public static LongHistogram GetNewHistogram()
        {
            LongHistogram histo = new LongHistogram(1, 2, NUMBER_SIGNIFICANT_DIGITS);

            histo.Reset();
            return(histo);
        }
Esempio n. 2
0
        public void TestReset()
        {
            var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);

            longHistogram.RecordValue(TestValueLevel);
            longHistogram.Reset();
            Assert.AreEqual(0L, longHistogram.GetCountAtValue(TestValueLevel));
            Assert.AreEqual(0L, longHistogram.TotalCount);
        }
Esempio n. 3
0
        public void Run(Program.Options options)
        {
            _runCount = options.RunCount ?? 3;

            Console.WriteLine($"Latency Test to run => {_perfTestType.FullName}, Runs => {_runCount}");

            _test = (ILatencyTest)Activator.CreateInstance(_perfTestType);
            CheckProcessorsRequirements(_test);

            Console.WriteLine("Starting");
            var stopwatch = new Stopwatch();
            var histogram = new LongHistogram(10000000000L, 4);

            for (var i = 0; i < _runCount; i++)
            {
                stopwatch.Reset();
                histogram.Reset();
                GC.Collect();
                GC.WaitForPendingFinalizers();

                var beforeGen0Count = GC.CollectionCount(0);
                var beforeGen1Count = GC.CollectionCount(1);
                var beforeGen2Count = GC.CollectionCount(2);

                Exception exception             = null;
                LatencyTestSessionResult result = null;
                try
                {
                    _test.Run(stopwatch, histogram);
                }
                catch (Exception ex)
                {
                    exception = ex;
                }

                if (exception != null)
                {
                    result = new LatencyTestSessionResult(exception);
                }
                else
                {
                    var gen0Count = GC.CollectionCount(0) - beforeGen0Count;
                    var gen1Count = GC.CollectionCount(1) - beforeGen1Count;
                    var gen2Count = GC.CollectionCount(2) - beforeGen2Count;

                    result = new LatencyTestSessionResult(histogram, stopwatch.Elapsed, gen0Count, gen1Count, gen2Count);
                }

                Console.WriteLine(result);
                _results.Add(result);
            }
        }
Esempio n. 4
0
        private static void RunClient(IFeedClient client)
        {
            var histogram            = new LongHistogram(TimeSpan.FromSeconds(10).Ticks, 2);
            var receivedMessageCount = 0;

            void OnMessageReceived(ReadOnlySpan <byte> message)
            {
                var now   = Stopwatch.GetTimestamp();
                var start = Unsafe.ReadUnaligned <long>(ref MemoryMarshal.GetReference(message));
                var rrt   = now - start;

                var latencyInMicroseconds = unchecked (rrt * 1_000_000 / (double)Stopwatch.Frequency);

                receivedMessageCount++;

                histogram.RecordValue((long)latencyInMicroseconds);
            }

            using (client)
            {
                var connectedSignal = new AutoResetEvent(false);
                client.Connected       += () => Console.WriteLine($"Connected {connectedSignal.Set()}");
                client.MessageReceived += OnMessageReceived;
                client.Start("client " + Guid.NewGuid());
                connectedSignal.WaitOne();

                do
                {
                    Console.WriteLine("Bench? (<message count> <message size> <delay in micro> <burst>, eg.: 100000 128 10 1)");

                    var benchArgs = Console.ReadLine();

                    if (!TryParseBenchArgs(benchArgs, out var args))
                    {
                        break;
                    }

                    histogram.Reset();

                    RunBench(client, args, ref receivedMessageCount);

                    histogram.OutputPercentileDistribution(Console.Out, 1);

                    Console.WriteLine("FailSends : " + Counters.FailedReceivingNextCount);
                    Console.WriteLine("FailReceives : " + Counters.FailedReceivingNextCount);

                    Counters.Reset();
                } while (true);

                client.Stop();
            }
        }
Esempio n. 5
0
        public static void Main()
        {
            var ctx = new Aeron.Context()
                      .AvailableImageHandler(AvailablePongImageHandler);

            var fragmentAssembler = new FragmentAssembler(HandlerHelper.ToFragmentHandler(PongHandler));

            Console.WriteLine("Publishing Ping at " + PingChannel + " on stream Id " + PingStreamID);
            Console.WriteLine("Subscribing Pong at " + PongChannel + " on stream Id " + PongStreamID);
            Console.WriteLine("Message length of " + MessageLength + " bytes");

            using (var aeron = Aeron.Connect(ctx))
            {
                Console.WriteLine("Warming up... " + WarmupNumberOfIterations + " iterations of " + WarmupNumberOfMessages + " messages");

                using (var publication = aeron.AddPublication(PingChannel, PingStreamID))
                    using (var subscription = aeron.AddSubscription(PongChannel, PongStreamID))
                        using (var byteBuffer = BufferUtil.AllocateDirectAligned(MessageLength, BitUtil.CACHE_LINE_LENGTH))
                            using (var atomicBuffer = new UnsafeBuffer(byteBuffer))
                            {
                                Latch.Wait();

                                for (var i = 0; i < WarmupNumberOfIterations; i++)
                                {
                                    RoundTripMessages(atomicBuffer, fragmentAssembler, publication, subscription, WarmupNumberOfMessages);
                                }

                                Thread.Sleep(100);

                                do
                                {
                                    Histogram.Reset();
                                    Console.WriteLine("Pinging " + NumberOfMessages + " messages");

                                    RoundTripMessages(atomicBuffer, fragmentAssembler, publication, subscription, NumberOfMessages);
                                    Console.WriteLine("Histogram of RTT latencies in microseconds.");

                                    Histogram.OutputPercentileDistribution(Console.Out, outputValueUnitScalingRatio: 1000);
                                } while (Console.Read() == 'y');
                            }
            }
        }
Esempio n. 6
0
 public void TestReset()
 {
     var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
     longHistogram.RecordValue(TestValueLevel);
     longHistogram.Reset();
     Assert.AreEqual(0L, longHistogram.GetCountAtValue(TestValueLevel));
     Assert.AreEqual(0L, longHistogram.TotalCount);
 }
Esempio n. 7
0
        private void StartLoop(int messageSize, int delayMicros, int burst)
        {
            _cts = new CancellationTokenSource();
            var histogram = new LongHistogram(TimeSpan.FromSeconds(10).Ticks, 2);

            void FeedClientOnMessageReceived(ReadOnlySpan <byte> bytes)
            {
                var now = Stopwatch.GetTimestamp();

                var count = Interlocked.Increment(ref _messageCounter);

                if (count <= _warmupSkipCount)
                {
                    return;
                }

                var start  = Unsafe.ReadUnaligned <long>(ref MemoryMarshal.GetReference(bytes));
                var rrt    = now - start;
                var micros = (long)(rrt * 1_000_000.0 / Stopwatch.Frequency);

                if (!_cts.IsCancellationRequested)
                {
                    histogram.RecordValue(micros);
                }
            }

            _feedClientManual.MessageReceived += FeedClientOnMessageReceived;

            histogram.Reset();
            _messageCounter = 0;

            var buffer = new byte[messageSize];

            for (var i = 0; i < buffer.Length; i++)
            {
                buffer[i] = 42;
            }

            var rateReporter = Task.Run(async() =>
            {
                var previousCount = 0L;

                while (!_cts.IsCancellationRequested)
                {
                    var count       = Volatile.Read(ref _messageCounter);
                    var countPerSec = count - previousCount;
                    previousCount   = count;

                    Console.WriteLine($"Processed messages: {countPerSec:N0}, total: {count:N0} [GC 0:{GC.CollectionCount(0)} 1:{GC.CollectionCount(1)}]");
                    await Task.Delay(1000);
                }
            });

            while (!_cts.IsCancellationRequested)
            {
                _sw.Restart();

                for (int i = 0; i < burst; i++)
                {
                    Unsafe.WriteUnaligned(ref buffer[0], Stopwatch.GetTimestamp());
                    _feedClientManual.Send(buffer);
                }

                NOP(delayMicros / 1000_000.0);
            }

            _feedClientManual.MessageReceived -= FeedClientOnMessageReceived;

            rateReporter.Wait();
            histogram.OutputPercentileDistribution(Console.Out, 1);
            using var writer = new StreamWriter(Path.Combine(_outFolder, $"Latency_{messageSize}_{delayMicros}.hgrm"));
            histogram.OutputPercentileDistribution(writer);
        }