Search in sources :

Example 31 with Histogram

use of org.HdrHistogram.Histogram in project fast-cast by RuedigerMoeller.

the class AsyncLatPublisher method initFastCast.

public void initFastCast() throws Exception {
    fastCast = FastCast.getFastCast();
    fastCast.setNodeId("PUB");
    fastCast.loadConfig(CFG_FILE_PATH);
    pub = new ObjectPublisher(fastCast.onTransport("default").publish("stream"), AsyncLatMessage.class);
    fastCast.onTransport("back").subscribe("back", new ObjectSubscriber(false, AsyncLatMessage.class) {

        @Override
        protected void objectReceived(String s, long l, Object o) {
            if ("END".equals(o)) {
                final Histogram oldHi = hi;
                hi = new Histogram(TimeUnit.SECONDS.toNanos(2), 3);
                // no lambdas to stay 1.7 compatible
                // move printing out of the receiving thread
                dumper.execute(new Runnable() {

                    @Override
                    public void run() {
                        oldHi.outputPercentileDistribution(System.out, 1000.0);
                    }
                });
                //                        hi.reset();
                return;
            }
            final long value = System.nanoTime() - ((AsyncLatMessage) o).getSendTimeStampNanos();
            if (value < 1_000_000_000)
                hi.recordValue(value);
        }

        @Override
        public boolean dropped() {
            System.exit(-2);
            return false;
        }
    });
}
Also used : Histogram(org.HdrHistogram.Histogram) ObjectPublisher(org.nustaq.fastcast.api.util.ObjectPublisher) ObjectSubscriber(org.nustaq.fastcast.api.util.ObjectSubscriber)

Example 32 with Histogram

use of org.HdrHistogram.Histogram in project fast-cast by RuedigerMoeller.

the class AsyncPubStruct method initFastCast.

public void initFastCast() throws Exception {
    fastCast = FastCast.getFastCast();
    fastCast.setNodeId("PUB");
    fastCast.loadConfig(CFG_FILE_PATH);
    pub = fastCast.onTransport("default").publish("stream");
    // pointer to message
    final FSTStruct msg = FSTStructFactory.getInstance().createEmptyStructPointer(FSTStruct.class);
    fastCast.onTransport("back").subscribe("back", new FCSubscriber() {

        @Override
        public void messageReceived(String sender, long sequence, Bytez b, long off, int len) {
            // as structs decode literally in zero time, we can decode inside receiver thread
            msg.baseOn(b, (int) off);
            Class type = msg.getPointedClass();
            if (type == StructString.class) {
                // sequence end, print histogram
                final Histogram oldHi = hi;
                hi = new Histogram(TimeUnit.SECONDS.toNanos(2), 3);
                // no lambdas to stay 1.7 compatible
                // move printing out of the receiving thread
                dumper.execute(new Runnable() {

                    @Override
                    public void run() {
                        oldHi.outputPercentileDistribution(System.out, 1000.0);
                    }
                });
            } else {
                // a regular message, record latency
                AsyncLatMessageStruct mdata = msg.cast();
                long value = System.nanoTime() - mdata.getSendTimeStampNanos();
                if (value < 1_000_000_000) {
                    // avoid AIOB during init + JITTING
                    hi.recordValue(value);
                }
            // a real app would need to copy the message (recycle byte arrays/objects !) and
            // run msg processing in an executor to get out of the receiving thread.
            // mdata gets invalid on finish of this method
            }
        }

        @Override
        public boolean dropped() {
            System.out.println("DROPPED");
            System.exit(-1);
            return false;
        }

        @Override
        public void senderTerminated(String senderNodeId) {
        }

        @Override
        public void senderBootstrapped(String receivesFrom, long seqNo) {
        }
    });
}
Also used : StructString(org.nustaq.offheap.structs.structtypes.StructString) FSTStruct(org.nustaq.offheap.structs.FSTStruct) Histogram(org.HdrHistogram.Histogram) HeapBytez(org.nustaq.offheap.bytez.onheap.HeapBytez) Bytez(org.nustaq.offheap.bytez.Bytez) StructString(org.nustaq.offheap.structs.structtypes.StructString) FCSubscriber(org.nustaq.fastcast.api.FCSubscriber)

Aggregations

Histogram (org.HdrHistogram.Histogram)32 Utils.saveHistogram (io.grpc.benchmarks.Utils.saveHistogram)6 ByteBuffer (java.nio.ByteBuffer)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 InetSocketAddress (java.net.InetSocketAddress)4 DatagramChannel (java.nio.channels.DatagramChannel)4 ManagedChannel (io.grpc.ManagedChannel)3 SimpleRequest (io.grpc.benchmarks.proto.Messages.SimpleRequest)3 ArrayList (java.util.ArrayList)3 AtomicHistogram (org.HdrHistogram.AtomicHistogram)3 FCSubscriber (org.nustaq.fastcast.api.FCSubscriber)3 Bytez (org.nustaq.offheap.bytez.Bytez)3 ParameterException (com.beust.jcommander.ParameterException)2 RateLimiter (com.google.common.util.concurrent.RateLimiter)2 IntHashSet (com.hazelcast.util.collection.IntHashSet)2 BenchmarkServiceStub (io.grpc.benchmarks.proto.BenchmarkServiceGrpc.BenchmarkServiceStub)2 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 PrintStream (java.io.PrintStream)2