예제 #1
0
        public void CanReadv1Logs_Skip_PreStart(string logPath, int skip, int take,
                                                int expectedHistogramCount, int expectedCombinedValueCount,
                                                int expectedCombined999, long expectedCombinedMaxLength,
                                                double expectedStartTime)
        {
            var  readerStream   = GetEmbeddedFileStream(logPath);
            var  reader         = new HistogramLogReader(readerStream);
            int  histogramCount = 0;
            long totalCount     = 0;

            HistogramBase accumulatedHistogram = new LongHistogram(3600L * 1000 * 1000 * 1000, 3);
            var           histograms           = reader.ReadHistograms()
                                                 .Where(h => h.StartTimeStamp >= reader.GetStartTime().MillisecondsSinceUnixEpoch())
                                                 .Skip(skip)
                                                 .Take(take);

            foreach (var histogram in histograms)
            {
                histogramCount++;
                totalCount += histogram.TotalCount;
                accumulatedHistogram.Add(histogram);
            }

            Assert.AreEqual(expectedHistogramCount, histogramCount);
            Assert.AreEqual(expectedCombinedValueCount, totalCount);
            Assert.AreEqual(expectedCombined999, accumulatedHistogram.GetValueAtPercentile(99.9));
            Assert.AreEqual(expectedCombinedMaxLength, accumulatedHistogram.GetMaxValue());
            Assert.AreEqual(expectedStartTime, reader.GetStartTime().SecondsSinceUnixEpoch());
        }
예제 #2
0
        [Fact] //BUG https://github.com/HdrHistogram/HdrHistogram.NET/issues/39
        public void OnlySingleValueFlaggedAsLastValue()
        {
            var expected = GetEmbeddedFileText("IsLastValueBug.hgrm");

            var histogram = new LongHistogram(highestTrackableValue: 36000000000, numberOfSignificantValueDigits: 3);

            histogram.RecordValueWithCount(1L, 7604459);
            histogram.RecordValueWithCount(383, 2395524);
            histogram.RecordValueWithCount(453, 2);
            histogram.RecordValueWithCount(511, 2);
            histogram.RecordValueWithCount(537, 3);
            histogram.RecordValueWithCount(672, 1);
            histogram.RecordValueWithCount(777, 1);
            histogram.RecordValueWithCount(18143, 1);
            histogram.RecordValueWithCount(208127, 1);
            histogram.RecordValueWithCount(224639, 1);
            histogram.RecordValueWithCount(229759, 1);
            histogram.RecordValueWithCount(230271, 1);
            histogram.RecordValueWithCount(258943, 1);
            histogram.RecordValueWithCount(275711, 1);
            histogram.RecordValueWithCount(282111, 1);

            var writer = new StringWriter();

            histogram.OutputPercentileDistribution(writer);
            var actual = writer.ToString();

            Assert.Equal(expected, actual);
        }
 private static LongHistogram CompressedEncodeDecode(LongHistogram source)
 {
     var targetBuffer = ByteBuffer.Allocate(source.GetNeededByteBufferCapacity());
     source.EncodeIntoCompressedByteBuffer(targetBuffer);
     targetBuffer.Position = 0;
     return (LongHistogram)HistogramEncoding.DecodeFromCompressedByteBuffer(targetBuffer, 0);
 }
        static HistogramDataAccessTest()
        {
            LongHistogram   = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
            ScaledHistogram = new LongHistogram(1000, HighestTrackableValue * 512, NumberOfSignificantValueDigits);
            RawHistogram    = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
            var scaledRawHistogram = new LongHistogram(1000, HighestTrackableValue * 512, NumberOfSignificantValueDigits);

            // Log hypothetical scenario: 100 seconds of "perfect" 1msec results, sampled
            // 100 times per second (10,000 results), followed by a 100 second pause with
            // a single (100 second) recorded result. Recording is done indicating an expected
            // interval between samples of 10 msec:
            for (var i = 0; i < 10000; i++)
            {
                LongHistogram.RecordValueWithExpectedInterval(1000 /* 1 msec */, 10000 /* 10 msec expected interval */);
                ScaledHistogram.RecordValueWithExpectedInterval(1000 * 512 /* 1 msec */, 10000 * 512 /* 10 msec expected interval */);
                RawHistogram.RecordValue(1000 /* 1 msec */);
                scaledRawHistogram.RecordValue(1000 * 512 /* 1 msec */);
            }
            LongHistogram.RecordValueWithExpectedInterval(100000000L /* 100 sec */, 10000 /* 10 msec expected interval */);
            ScaledHistogram.RecordValueWithExpectedInterval(100000000L * 512 /* 100 sec */, 10000 * 512 /* 10 msec expected interval */);
            RawHistogram.RecordValue(100000000L /* 100 sec */);
            scaledRawHistogram.RecordValue(100000000L * 512 /* 100 sec */);

            PostCorrectedHistogram       = RawHistogram.CopyCorrectedForCoordinatedOmission(10000 /* 10 msec expected interval */);
            PostCorrectedScaledHistogram = scaledRawHistogram.CopyCorrectedForCoordinatedOmission(10000 * 512 /* 10 msec expected interval */);
        }
예제 #5
0
        public static LongHistogram GetNewHistogram()
        {
            LongHistogram histo = new LongHistogram(1, 2, NUMBER_SIGNIFICANT_DIGITS);

            histo.Reset();
            return(histo);
        }
예제 #6
0
        public void TestAdd()
        {
            var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
            var other         = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);

            longHistogram.RecordValue(TestValueLevel);
            longHistogram.RecordValue(TestValueLevel * 1000);
            other.RecordValue(TestValueLevel);
            other.RecordValue(TestValueLevel * 1000);
            longHistogram.Add(other);
            Assert.AreEqual(2L, longHistogram.GetCountAtValue(TestValueLevel));
            Assert.AreEqual(2L, longHistogram.GetCountAtValue(TestValueLevel * 1000));
            Assert.AreEqual(4L, longHistogram.TotalCount);

            var biggerOther = new LongHistogram(HighestTrackableValue * 2, NumberOfSignificantValueDigits);

            biggerOther.RecordValue(TestValueLevel);
            biggerOther.RecordValue(TestValueLevel * 1000);

            // Adding the smaller histogram to the bigger one should work:
            biggerOther.Add(longHistogram);
            Assert.AreEqual(3L, biggerOther.GetCountAtValue(TestValueLevel));
            Assert.AreEqual(3L, biggerOther.GetCountAtValue(TestValueLevel * 1000));
            Assert.AreEqual(6L, biggerOther.TotalCount);

            // But trying to add a larger histogram into a smaller one should throw an AIOOB:
            Assert.Throws <ArgumentOutOfRangeException>(() => { longHistogram.Add(biggerOther); });
        }
예제 #7
0
        private static void ProcessHistogrmaResults(LongHistogram histogram)
        {
            Console.WriteLine();
            var percentiles = new[] { 50.0, 90.0, 95.0, 99.9, 99.99, 99.999, 99.9999, 99.99999, 99.999999, 100.0 };

            foreach (var percentile in percentiles)
            {
                var value = histogram.GetValueAtPercentile(percentile) / OutputScalingFactor.TimeStampToMilliseconds;
                Console.WriteLine($"{percentile,10:##.######}th Percentile : {value,9:N4} ms");
            }
            Console.WriteLine(
                $"                    Max : {histogram.GetMaxValue() / OutputScalingFactor.TimeStampToMilliseconds,9:N4} ms");


            var fileName = "HistogramResults.hgrm";

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            using (var writer = new StreamWriter(fileName))
            {
                histogram.OutputPercentileDistribution(writer, outputValueUnitScalingRatio: OutputScalingFactor.TimeStampToMilliseconds);
            }
        }
예제 #8
0
        public void TestScaledLowestEquivalentValue()
        {
            var longHistogram = new LongHistogram(1024, HighestTrackableValue, NumberOfSignificantValueDigits);

            Assert.AreEqual(10000 * 1024, longHistogram.LowestEquivalentValue(10007 * 1024), "The lowest equivalent value to 10007 * 1024 is 10000 * 1024");
            Assert.AreEqual(10008 * 1024, longHistogram.LowestEquivalentValue(10009 * 1024), "The lowest equivalent value to 10009 * 1024 is 10008 * 1024");
        }
예제 #9
0
        private void WriteToDisk(Recorder recorder)
        {
            //Sample every second until flagged as completed.
            var accumulatingHistogram = new LongHistogram(TimeStamp.Hours(1), 3);

            while (_isCompleted == 0)
            {
                Thread.Sleep(1000);

                var histogram = recorder.GetIntervalHistogram();
                accumulatingHistogram.Add(histogram);
                _logWriter.Append(histogram);
                Console.WriteLine($"{DateTime.Now:o} Interval.TotalCount = {histogram.TotalCount,10:G}. Accumulated.TotalCount = {accumulatingHistogram.TotalCount,10:G}.");
            }
            _logWriter.Dispose();
            _outputStream.Dispose();


            Console.WriteLine("Log contents");
            Console.WriteLine(File.ReadAllText(LogPath));
            Console.WriteLine();
            Console.WriteLine("Percentile distribution (values reported in milliseconds)");
            accumulatingHistogram.OutputPercentileDistribution(Console.Out, outputValueUnitScalingRatio: OutputScalingFactor.TimeStampToMilliseconds);

            Console.WriteLine("Output thread finishing.");
        }
예제 #10
0
        public void TestLowestEquivalentValue()
        {
            var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);

            Assert.AreEqual(10000, longHistogram.LowestEquivalentValue(10007), "The lowest equivalent value to 10007 is 10000");
            Assert.AreEqual(10008, longHistogram.LowestEquivalentValue(10009), "The lowest equivalent value to 10009 is 10008");
        }
예제 #11
0
 public void TestRecordValue()
 {
     var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
     longHistogram.RecordValue(TestValueLevel);
     Assert.AreEqual(1L, longHistogram.GetCountAtValue(TestValueLevel));
     Assert.AreEqual(1L, longHistogram.TotalCount);
 }
예제 #12
0
        public void TestNextNonEquivalentValue()
        {
            //HACK: WTF does this prove? -LC
            var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);

            Assert.IsNotNull(longHistogram);
        }
        static HistogramDataAccessTest()
        {
            LongHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
            ScaledHistogram = new LongHistogram(1000, HighestTrackableValue * 512, NumberOfSignificantValueDigits);
            RawHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
            var scaledRawHistogram = new LongHistogram(1000, HighestTrackableValue * 512, NumberOfSignificantValueDigits);
            // Log hypothetical scenario: 100 seconds of "perfect" 1msec results, sampled
            // 100 times per second (10,000 results), followed by a 100 second pause with
            // a single (100 second) recorded result. Recording is done indicating an expected
            // interval between samples of 10 msec:
            for (var i = 0; i < 10000; i++)
            {
                LongHistogram.RecordValueWithExpectedInterval(1000 /* 1 msec */, 10000 /* 10 msec expected interval */);
                ScaledHistogram.RecordValueWithExpectedInterval(1000 * 512 /* 1 msec */, 10000 * 512 /* 10 msec expected interval */);
                RawHistogram.RecordValue(1000 /* 1 msec */);
                scaledRawHistogram.RecordValue(1000 * 512/* 1 msec */);
            }
            LongHistogram.RecordValueWithExpectedInterval(100000000L /* 100 sec */, 10000 /* 10 msec expected interval */);
            ScaledHistogram.RecordValueWithExpectedInterval(100000000L * 512 /* 100 sec */, 10000 * 512 /* 10 msec expected interval */);
            RawHistogram.RecordValue(100000000L /* 100 sec */);
            scaledRawHistogram.RecordValue(100000000L * 512 /* 100 sec */);

            PostCorrectedHistogram = RawHistogram.CopyCorrectedForCoordinatedOmission(10000 /* 10 msec expected interval */);
            PostCorrectedScaledHistogram = scaledRawHistogram.CopyCorrectedForCoordinatedOmission(10000 * 512 /* 10 msec expected interval */);
        }
        private void WriteToDisk(Recorder recorder)
        {
            //Sample every second until flagged as completed.
            var accumulatingHistogram = new LongHistogram(TimeStamp.Hours(1), 3);
            while (_isCompleted == 0)
            {
                Thread.Sleep(1000);

                var histogram = recorder.GetIntervalHistogram();
                accumulatingHistogram.Add(histogram);
                _logWriter.Append(histogram);
                Console.WriteLine($"{DateTime.Now:o} Interval.TotalCount = {histogram.TotalCount,10:G}. Accumulated.TotalCount = {accumulatingHistogram.TotalCount,10:G}.");
            }
            _logWriter.Dispose();
            _outputStream.Dispose();


            Console.WriteLine("Log contents");
            Console.WriteLine(File.ReadAllText(LogPath));
            Console.WriteLine();
            Console.WriteLine("Percentile distribution (values reported in milliseconds)");
            accumulatingHistogram.OutputPercentileDistribution(Console.Out, outputValueUnitScalingRatio: OutputScalingFactor.TimeStampToMilliseconds);

            Console.WriteLine("Output thread finishing.");
        }
 private static void Load(LongHistogram source)
 {
     for (long i = 0L; i < 10000L; i++)
     {
         source.RecordValue(1000L * i);
     }
 }
예제 #16
0
        public void TestRecordValue()
        {
            var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);

            longHistogram.RecordValue(TestValueLevel);
            Assert.AreEqual(1L, longHistogram.GetCountAtValue(TestValueLevel));
            Assert.AreEqual(1L, longHistogram.TotalCount);
        }
예제 #17
0
 public LatencyTestSessionResult(LongHistogram histogram, TimeSpan duration, int gen0, int gen1, int gen2)
 {
     Histogram = histogram;
     Duration  = duration;
     Gen0      = gen0;
     Gen1      = gen1;
     Gen2      = gen2;
 }
 private static LongHistogram CreatePopulatedHistogram(long multiplier)
 {
     var histogram = new LongHistogram(3600L * 1000 * 1000, 3);
     for (int i = 0; i < 10000; i++)
     {
         histogram.RecordValue(i * multiplier);
     }
     return histogram;
 }
예제 #19
0
        private BenchmarkResult RunTest(int messageSize, int delayMicros, int burst, int tgtMsgCount, int warmUpMessageCount, int secondsPerTest)
        {
            var result = new BenchmarkResult(_feedClients.Count);

            if (_hostCount == 1 && _serversPerHost == 1 && _clientsPerServer == 1)
            {
                result.Transport = _transportId;
            }
            else
            {
                result.Transport = $"{_transportId}_H{_hostCount}_S{_serversPerHost}_C{_clientsPerServer}";
            }

            result.MsgSize     = messageSize;
            result.Delay       = delayMicros;
            result.Burst       = burst;
            result.TgtMsgCount = tgtMsgCount * _feedClients.Count;

            Thread.Sleep(1000);
            GC.Collect(2, GCCollectionMode.Forced, true);
            GC.WaitForPendingFinalizers();
            GC.Collect(2, GCCollectionMode.Forced, true);
            GC.WaitForPendingFinalizers();

            LoopAll(warmUpMessageCount, true);

            GC.Collect(2, GCCollectionMode.Forced, true);

            Thread.Sleep(500);

            result.Started = DateTime.UtcNow;

            var(counter, histogramAll) = LoopAll(tgtMsgCount, false);

            result.ActMsgCount = counter;

            result.Ended = DateTime.UtcNow;

            result.SetStats(histogramAll);

            var name = $"Latency_{_transportId}_{messageSize}_{delayMicros}_{burst}";

            histogramAll.OutputPercentileDistribution(Console.Out, 1);
            using var writer = new StreamWriter(Path.Combine(_outFolder, $"Latency_{_transportId}_{messageSize}_{delayMicros}_{burst}.hgrm"));
            histogramAll.OutputPercentileDistribution(writer);
            Console.WriteLine(name);
            Console.WriteLine($"TgtMsgSec: {result.TgtMsgSec:N0}, ActMsgSec: {result.ActMsgSec:N0}, TgtBw: {result.TgtBwMb:N0} Mb, ActBw: {result.ActBwMb:N0} Mb");
            Console.WriteLine("------------------------------");
            return(result);

            (int, LongHistogram) LoopAll(int msgCount, bool warmup)
            {
                _isRunning = true;
                var histogram = new LongHistogram(TimeSpan.FromSeconds(10).Ticks, 2);

                Task[] threads = new Task[_feedClients.Count];
                (MessageCounter, LongHistogram)[] results = new (MessageCounter, LongHistogram)[_feedClients.Count];
예제 #20
0
 public void TestConstructionArgumentGets()
 {
     var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
     Assert.AreEqual(1, longHistogram.LowestTrackableValue);
     Assert.AreEqual(HighestTrackableValue, longHistogram.HighestTrackableValue);
     Assert.AreEqual(NumberOfSignificantValueDigits, longHistogram.NumberOfSignificantValueDigits);
     var histogram2 = new LongHistogram(1000, HighestTrackableValue, NumberOfSignificantValueDigits);
     Assert.AreEqual(1000, histogram2.LowestTrackableValue);
 }
        public void TestGetValueAtPercentileForLargeHistogram()
        {
            const long largestValue = 1000000000000L;
            var        h            = new LongHistogram(largestValue, 5);

            h.RecordValue(largestValue);

            Assert.That(h.GetValueAtPercentile(100.0) > 0);
        }
예제 #22
0
        public void TestScaledSizeOfEquivalentValueRange()
        {
            var longHistogram = new LongHistogram(1024, HighestTrackableValue, NumberOfSignificantValueDigits);

            Assert.AreEqual(1 * 1024, longHistogram.SizeOfEquivalentValueRange(1 * 1024), "Size of equivalent range for value 1 * 1024 is 1 * 1024");
            Assert.AreEqual(2 * 1024, longHistogram.SizeOfEquivalentValueRange(2500 * 1024), "Size of equivalent range for value 2500 * 1024 is 2 * 1024");
            Assert.AreEqual(4 * 1024, longHistogram.SizeOfEquivalentValueRange(8191 * 1024), "Size of equivalent range for value 8191 * 1024 is 4 * 1024");
            Assert.AreEqual(8 * 1024, longHistogram.SizeOfEquivalentValueRange(8192 * 1024), "Size of equivalent range for value 8192 * 1024 is 8 * 1024");
            Assert.AreEqual(8 * 1024, longHistogram.SizeOfEquivalentValueRange(10000 * 1024), "Size of equivalent range for value 10000 * 1024 is 8 * 1024");
        }
예제 #23
0
        public void TestScaledMedianEquivalentValue()
        {
            var longHistogram = new LongHistogram(1024, HighestTrackableValue, NumberOfSignificantValueDigits);

            Assert.AreEqual(4 * 1024 + 512, longHistogram.MedianEquivalentValue(4 * 1024), "The median equivalent value to 4 * 1024 is 4 * 1024 + 512");
            Assert.AreEqual(5 * 1024 + 512, longHistogram.MedianEquivalentValue(5 * 1024), "The median equivalent value to 5 * 1024 is 5 * 1024 + 512");
            Assert.AreEqual(4001 * 1024, longHistogram.MedianEquivalentValue(4000 * 1024), "The median equivalent value to 4000 * 1024 is 4001 * 1024");
            Assert.AreEqual(8002 * 1024, longHistogram.MedianEquivalentValue(8000 * 1024), "The median equivalent value to 8000 * 1024 is 8002 * 1024");
            Assert.AreEqual(10004 * 1024, longHistogram.MedianEquivalentValue(10007 * 1024), "The median equivalent value to 10007 * 1024 is 10004 * 1024");
        }
예제 #24
0
        public void TestSizeOfEquivalentValueRange()
        {
            var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);

            Assert.AreEqual(1, longHistogram.SizeOfEquivalentValueRange(1), "Size of equivalent range for value 1 is 1");
            Assert.AreEqual(2, longHistogram.SizeOfEquivalentValueRange(2500), "Size of equivalent range for value 2500 is 2");
            Assert.AreEqual(4, longHistogram.SizeOfEquivalentValueRange(8191), "Size of equivalent range for value 8191 is 4");
            Assert.AreEqual(8, longHistogram.SizeOfEquivalentValueRange(8192), "Size of equivalent range for value 8192 is 8");
            Assert.AreEqual(8, longHistogram.SizeOfEquivalentValueRange(10000), "Size of equivalent range for value 10000 is 8");
        }
예제 #25
0
        public void TestMedianEquivalentValue()
        {
            var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);

            Assert.AreEqual(4, longHistogram.MedianEquivalentValue(4), "The median equivalent value to 4 is 4");
            Assert.AreEqual(5, longHistogram.MedianEquivalentValue(5), "The median equivalent value to 5 is 5");
            Assert.AreEqual(4001, longHistogram.MedianEquivalentValue(4000), "The median equivalent value to 4000 is 4001");
            Assert.AreEqual(8002, longHistogram.MedianEquivalentValue(8000), "The median equivalent value to 8000 is 8002");
            Assert.AreEqual(10004, longHistogram.MedianEquivalentValue(10007), "The median equivalent value to 10007 is 10004");
        }
예제 #26
0
 private static byte[] WriteLog(DateTime startTimeWritten, LongHistogram histogram)
 {
     byte[] data;
     using (var writerStream = new MemoryStream())
     {
         Histogram.Write(writerStream, startTimeWritten, histogram);
         data = writerStream.ToArray();
     }
     return(data);
 }
예제 #27
0
        private static LongHistogram CreatePopulatedHistogram(long multiplier)
        {
            var histogram = new LongHistogram(3600L * 1000 * 1000, 3);

            for (int i = 0; i < 10000; i++)
            {
                histogram.RecordValue(i * multiplier);
            }
            return(histogram);
        }
 private static byte[] WriteLog(DateTime startTimeWritten, LongHistogram histogram)
 {
     byte[] data;
     using (var writerStream = new MemoryStream())
     {
         Histogram.Write(writerStream, startTimeWritten, histogram);
         data = writerStream.ToArray();
     }
     return data;
 }
예제 #29
0
        public static LongHistogram Bench(Action action, int count)
        {
            var histogram = new LongHistogram(TimeStamp.Minutes(1), 5);

            for (var i = 0; i < count; i++)
            {
                histogram.Record(() => action());
            }

            return(histogram);
        }
        public async void AmazonIotStreamer([FromQuery] int messageToSend = 10, [FromQuery] int delayBtwMessageInMs = 50)
        {
            var rd = new Random(100);

            var histogram = new LongHistogram(TimeStamp.Hours(1), 3);

            var writer = new StringWriter();

            var messages = messageToSend;

            string[] currencyPairs = new string[] { "EUR/USD", "EUR/JPY", "EUR/GBP", "USD/JPY", "USD/GBP" };
            for (int currIndex = 0; currIndex < currencyPairs.Length; currIndex++)
            {
                var pair = currencyPairs[currIndex];

                Task.Run(async() =>
                {
                    var publisher = new AmazonIotDataClient(IotEndpoint, new BasicAWSCredentials(IotAccessKey, IotSecret));
                    for (var i = 1; i <= messages; i++)
                    {
                        long startTimestamp = Stopwatch.GetTimestamp();
                        long timestamp      = DateTimeOffset.Now.ToUnixTimeMilliseconds();

                        var currency = new Currency()
                        {
                            Id           = i,
                            CurrencyType = pair,
                            Price        = rd.NextDouble(),
                            Timestamp    = DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString(),
                            Ladders      = new LadderFactory().Build(10)
                        };

                        var cur = JsonConvert.SerializeObject(currency);

                        publisher.PublishAsync(new Amazon.IotData.Model.PublishRequest()
                        {
                            Topic   = pair,
                            Payload = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(cur)),
                            Qos     = 0
                        });

                        long elapsed = Stopwatch.GetTimestamp() - startTimestamp;
                        histogram.RecordValue(elapsed);
                        await Task.Delay(delayBtwMessageInMs).ConfigureAwait(false);
                    }

                    var scalingRatio = OutputScalingFactor.TimeStampToMilliseconds;
                    histogram.OutputPercentileDistribution(
                        writer,
                        outputValueUnitScalingRatio: scalingRatio);
                    System.IO.File.WriteAllText(@"d:\cloud\appsync.txt", writer.ToString());
                });
            }
        }
        public void Can_add_LongHistogram_with_values_in_range()
        {
            var longHistogram = new LongHistogram(short.MaxValue-1, 3);
            longHistogram.RecordValueWithCount(1, 100);
            longHistogram.RecordValueWithCount(short.MaxValue-1, 1000);

            var shortHistogram = new ShortHistogram(short.MaxValue-1, 3);
            shortHistogram.Add(longHistogram);

            HistogramAssert.AreValueEqual(longHistogram, shortHistogram);
        }
예제 #32
0
        public void TestHighestEquivalentValue()
        {
            var longHistogram = new LongHistogram(1024, HighestTrackableValue, NumberOfSignificantValueDigits);

            Assert.AreEqual(8183 * 1024 + 1023, longHistogram.HighestEquivalentValue(8180 * 1024), "The highest equivalent value to 8180 * 1024 is 8183 * 1024 + 1023");
            Assert.AreEqual(8191 * 1024 + 1023, longHistogram.HighestEquivalentValue(8191 * 1024), "The highest equivalent value to 8187 * 1024 is 8191 * 1024 + 1023");
            Assert.AreEqual(8199 * 1024 + 1023, longHistogram.HighestEquivalentValue(8193 * 1024), "The highest equivalent value to 8193 * 1024 is 8199 * 1024 + 1023");
            Assert.AreEqual(9999 * 1024 + 1023, longHistogram.HighestEquivalentValue(9995 * 1024), "The highest equivalent value to 9995 * 1024 is 9999 * 1024 + 1023");
            Assert.AreEqual(10007 * 1024 + 1023, longHistogram.HighestEquivalentValue(10007 * 1024), "The highest equivalent value to 10007 * 1024 is 10007 * 1024 + 1023");
            Assert.AreEqual(10015 * 1024 + 1023, longHistogram.HighestEquivalentValue(10008 * 1024), "The highest equivalent value to 10008 * 1024 is 10015 * 1024 + 1023");
        }
예제 #33
0
        public void TestScaledHighestEquivalentValue()
        {
            var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);

            Assert.AreEqual(8183, longHistogram.HighestEquivalentValue(8180), "The highest equivalent value to 8180 is 8183");
            Assert.AreEqual(8191, longHistogram.HighestEquivalentValue(8191), "The highest equivalent value to 8187 is 8191");
            Assert.AreEqual(8199, longHistogram.HighestEquivalentValue(8193), "The highest equivalent value to 8193 is 8199");
            Assert.AreEqual(9999, longHistogram.HighestEquivalentValue(9995), "The highest equivalent value to 9995 is 9999");
            Assert.AreEqual(10007, longHistogram.HighestEquivalentValue(10007), "The highest equivalent value to 10007 is 10007");
            Assert.AreEqual(10015, longHistogram.HighestEquivalentValue(10008), "The highest equivalent value to 10008 is 10015");
        }
예제 #34
0
        static void DocumentResults(LongHistogram accumulatingHistogram, Recorder recorder)
        {
            recorder?.RecordValue(GC.GetTotalMemory(false));
            var histogram = recorder?.GetIntervalHistogram();

            accumulatingHistogram?.Add(histogram);
            _logWriter?.Append(histogram);
            RILogManager.Default?.SendDebug($"Accumulated.TotalCount = {accumulatingHistogram.TotalCount,10:G}.");
            RILogManager.Default?.SendDebug("Mean: " + BytesToString(accumulatingHistogram.GetMean()) + ", StdDev: " +
                                            BytesToString(accumulatingHistogram.GetStdDeviation()));
        }
예제 #35
0
        public void TestConstructionArgumentGets()
        {
            var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);

            Assert.AreEqual(1, longHistogram.LowestTrackableValue);
            Assert.AreEqual(HighestTrackableValue, longHistogram.HighestTrackableValue);
            Assert.AreEqual(NumberOfSignificantValueDigits, longHistogram.NumberOfSignificantValueDigits);
            var histogram2 = new LongHistogram(1000, HighestTrackableValue, NumberOfSignificantValueDigits);

            Assert.AreEqual(1000, histogram2.LowestTrackableValue);
        }
예제 #36
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);
            }
        }
예제 #37
0
파일: Program.cs 프로젝트: buybackoff/Zerio
        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();
            }
        }
예제 #38
0
        static void Report(string name, LongHistogram histogram, TimeSpan?maximumMean)
        {
            Console.Out.WriteLine($"Histogram for {name}:");
            histogram.OutputPercentileDistribution(Console.Out, outputValueUnitScalingRatio: OutputScalingFactor.TimeStampToMilliseconds, percentileTicksPerHalfDistance: 1);
            Console.Out.WriteLine();

            if (maximumMean != null)
            {
                var max        = maximumMean.Value;
                var actualMean = TimeSpan.FromMilliseconds(histogram.GetValueAtPercentile(50) / OutputScalingFactor.TimeStampToMilliseconds);

                Assert.LessOrEqual(actualMean, max, $"The actual mean for {name} was '{actualMean}' and was bigger than maximum allowed mean '{max}'.");
            }
        }
예제 #39
0
        public void TestGetEstimatedFootprintInBytes2()
        {
            var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
            var largestValueWithSingleUnitResolution = 2 * (long)Math.Pow(10, NumberOfSignificantValueDigits);
            var subBucketCountMagnitude = (int)Math.Ceiling(Math.Log(largestValueWithSingleUnitResolution) / Math.Log(2));
            var subBucketSize = (int)Math.Pow(2, (subBucketCountMagnitude));
            var bucketCount = GetBucketsNeededToCoverValue(subBucketSize, HighestTrackableValue);

            var header = 512;
            var width = sizeof (long);
            var length = (bucketCount + 1) * (subBucketSize / 2);
            var expectedSize = header + (width * length);

            Assert.AreEqual(expectedSize, longHistogram.GetEstimatedFootprintInBytes());
        }
예제 #40
0
        public void TestGetEstimatedFootprintInBytes2()
        {
            var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
            var largestValueWithSingleUnitResolution = 2 * (long)Math.Pow(10, NumberOfSignificantValueDigits);
            var subBucketCountMagnitude = (int)Math.Ceiling(Math.Log(largestValueWithSingleUnitResolution) / Math.Log(2));
            var subBucketSize           = (int)Math.Pow(2, (subBucketCountMagnitude));
            var bucketCount             = GetBucketsNeededToCoverValue(subBucketSize, HighestTrackableValue);

            var header       = 512;
            var width        = sizeof(long);
            var length       = (bucketCount + 1) * (subBucketSize / 2);
            var expectedSize = header + (width * length);

            Assert.AreEqual(expectedSize, longHistogram.GetEstimatedFootprintInBytes());
        }
        public void PercentileDistrubution_csv_output_is_in_correct_format(
            [Values(36000000000)]long highestTrackableValue,
            [Values(1, 2, 3, 4, 5)]int signigicantDigits,
            [Values(10000.0)]double scaling,
            [Values(5, 10, 20)]int percentileTicksPerHalfDistance)
        {
            var fileName = $"Sample_10kBy1k_{signigicantDigits}sf_TicksPerHour_asMs_{percentileTicksPerHalfDistance}percPerHalfDistance.csv";
            var expected = GetEmbeddedFileText(fileName);

            var histogram = new LongHistogram(highestTrackableValue, signigicantDigits);
            LoadHistogram(histogram);

            var writer = new StringWriter();
            histogram.OutputPercentileDistribution(writer, percentileTicksPerHalfDistance, scaling, true);
            var actual = writer.ToString();

            Assert.AreEqual(expected, actual);
        }
예제 #42
0
 public void TestRecordValueWithExpectedInterval()
 {
     var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
     longHistogram.RecordValueWithExpectedInterval(TestValueLevel, TestValueLevel / 4);
     var rawHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
     rawHistogram.RecordValue(TestValueLevel);
     // The data will include corrected samples:
     Assert.AreEqual(1L, longHistogram.GetCountAtValue((TestValueLevel * 1) / 4));
     Assert.AreEqual(1L, longHistogram.GetCountAtValue((TestValueLevel * 2) / 4));
     Assert.AreEqual(1L, longHistogram.GetCountAtValue((TestValueLevel * 3) / 4));
     Assert.AreEqual(1L, longHistogram.GetCountAtValue((TestValueLevel * 4) / 4));
     Assert.AreEqual(4L, longHistogram.TotalCount);
     // But the raw data will not:
     Assert.AreEqual(0L, rawHistogram.GetCountAtValue((TestValueLevel * 1) / 4));
     Assert.AreEqual(0L, rawHistogram.GetCountAtValue((TestValueLevel * 2) / 4));
     Assert.AreEqual(0L, rawHistogram.GetCountAtValue((TestValueLevel * 3) / 4));
     Assert.AreEqual(1L, rawHistogram.GetCountAtValue((TestValueLevel * 4) / 4));
     Assert.AreEqual(1L, rawHistogram.TotalCount);
 }
        public Recording32BitBenchmark()
        {
            const int lowestTrackableValue = 1;
            var highestTrackableValue = TimeStamp.Minutes(10);
            const int numberOfSignificantValueDigits = 3;

            _testValues = TestValues(highestTrackableValue);
            
            _longHistogram = new LongHistogram(highestTrackableValue, numberOfSignificantValueDigits);
            _intHistogram = new IntHistogram(highestTrackableValue, numberOfSignificantValueDigits);
            _shortHistogram = new ShortHistogram(highestTrackableValue, numberOfSignificantValueDigits);

            _longConcurrentHistogram = new LongConcurrentHistogram(lowestTrackableValue, highestTrackableValue, numberOfSignificantValueDigits);
            _intConcurrentHistogram = new IntConcurrentHistogram(lowestTrackableValue, highestTrackableValue, numberOfSignificantValueDigits);

            _longRecorder = new Recorder(lowestTrackableValue, highestTrackableValue, numberOfSignificantValueDigits, (id, low, hi, sf) => new LongHistogram(id, low, hi, sf));
            _longConcurrentRecorder = new Recorder(lowestTrackableValue, highestTrackableValue, numberOfSignificantValueDigits, (id, low, hi, sf) => new LongConcurrentHistogram(id, low, hi, sf));
            _intRecorder = new Recorder(lowestTrackableValue, highestTrackableValue, numberOfSignificantValueDigits, (id, low, hi, sf) => new IntHistogram(id, low, hi, sf));
            _intConcurrentRecorder = new Recorder(lowestTrackableValue, highestTrackableValue, numberOfSignificantValueDigits, (id, low, hi, sf) => new IntConcurrentHistogram(id, low, hi, sf));
            _shortRecorder = new Recorder(lowestTrackableValue, highestTrackableValue, numberOfSignificantValueDigits, (id, low, hi, sf) => new ShortHistogram(id, low, hi, sf));
        }
        public void CanReadv2Logs(string logPath)
        {
            var readerStream = GetEmbeddedFileStream(logPath);
            var reader = new HistogramLogReader(readerStream);
            int histogramCount = 0;
            long totalCount = 0;
            var accumulatedHistogram = new LongHistogram(85899345920838, 3);
            foreach (var histogram in reader.ReadHistograms())
            {
                histogramCount++;
                Assert.IsInstanceOf<HistogramBase>(histogram, "Expected integer value histograms in log file");

                totalCount += histogram.TotalCount;
                accumulatedHistogram.Add(histogram);
            }

            Assert.AreEqual(62, histogramCount);
            Assert.AreEqual(48761, totalCount);
            Assert.AreEqual(1745879039, accumulatedHistogram.GetValueAtPercentile(99.9));
            Assert.AreEqual(1796210687, accumulatedHistogram.GetMaxValue());
            Assert.AreEqual(1441812279.474, reader.GetStartTime().SecondsSinceUnixEpoch());
        }
예제 #45
0
 public void testRecordValue_Overflow_ShouldThrowException()
 {
     var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
     Assert.Catch<IndexOutOfRangeException>(()=>longHistogram.RecordValue(HighestTrackableValue * 3));
 }
예제 #46
0
        public void TestAdd()
        {
            var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
            var other = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
            longHistogram.RecordValue(TestValueLevel);
            longHistogram.RecordValue(TestValueLevel * 1000);
            other.RecordValue(TestValueLevel);
            other.RecordValue(TestValueLevel * 1000);
            longHistogram.Add(other);
            Assert.AreEqual(2L, longHistogram.GetCountAtValue(TestValueLevel));
            Assert.AreEqual(2L, longHistogram.GetCountAtValue(TestValueLevel * 1000));
            Assert.AreEqual(4L, longHistogram.TotalCount);

            var biggerOther = new LongHistogram(HighestTrackableValue * 2, NumberOfSignificantValueDigits);
            biggerOther.RecordValue(TestValueLevel);
            biggerOther.RecordValue(TestValueLevel * 1000);

            // Adding the smaller histogram to the bigger one should work:
            biggerOther.Add(longHistogram);
            Assert.AreEqual(3L, biggerOther.GetCountAtValue(TestValueLevel));
            Assert.AreEqual(3L, biggerOther.GetCountAtValue(TestValueLevel * 1000));
            Assert.AreEqual(6L, biggerOther.TotalCount);

            // But trying to add a larger histogram into a smaller one should throw an AIOOB:
            Assert.Throws<ArgumentOutOfRangeException>(() => { longHistogram.Add(biggerOther); });
        }
예제 #47
0
 public void TestSizeOfEquivalentValueRange()
 {
     var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
     Assert.AreEqual(1, longHistogram.SizeOfEquivalentValueRange(1), "Size of equivalent range for value 1 is 1");
     Assert.AreEqual(2, longHistogram.SizeOfEquivalentValueRange(2500), "Size of equivalent range for value 2500 is 2");
     Assert.AreEqual(4, longHistogram.SizeOfEquivalentValueRange(8191), "Size of equivalent range for value 8191 is 4");
     Assert.AreEqual(8, longHistogram.SizeOfEquivalentValueRange(8192), "Size of equivalent range for value 8192 is 8");
     Assert.AreEqual(8, longHistogram.SizeOfEquivalentValueRange(10000), "Size of equivalent range for value 10000 is 8");
 }
예제 #48
0
        public void TestScaledCopyInto()
        {
            var longHistogram = new LongHistogram(1000, HighestTrackableValue, NumberOfSignificantValueDigits);
            var targetLongHistogram = new LongHistogram(1000, HighestTrackableValue, NumberOfSignificantValueDigits);
            longHistogram.RecordValue(TestValueLevel);
            longHistogram.RecordValue(TestValueLevel * 10);
            longHistogram.RecordValueWithExpectedInterval(longHistogram.HighestTrackableValue - 1, 31000);

            Console.WriteLine("Testing copyInto for scaled Histogram:");
            longHistogram.CopyInto(targetLongHistogram);
            AssertEqual(longHistogram, targetLongHistogram);

            longHistogram.RecordValue(TestValueLevel * 20);

            longHistogram.CopyInto(targetLongHistogram);
            AssertEqual(longHistogram, targetLongHistogram);

            var intHistogram = new IntHistogram(1000, HighestTrackableValue, NumberOfSignificantValueDigits);
            var targetIntHistogram = new IntHistogram(1000, HighestTrackableValue, NumberOfSignificantValueDigits);
            intHistogram.RecordValue(TestValueLevel);
            intHistogram.RecordValue(TestValueLevel * 10);
            intHistogram.RecordValueWithExpectedInterval(intHistogram.HighestTrackableValue - 1, 31000);

            Console.WriteLine("Testing copyInto for scaled IntHistogram:");
            intHistogram.CopyInto(targetIntHistogram);
            AssertEqual(intHistogram, targetIntHistogram);

            intHistogram.RecordValue(TestValueLevel * 20);

            intHistogram.CopyInto(targetIntHistogram);
            AssertEqual(intHistogram, targetIntHistogram);

            var shortHistogram = new ShortHistogram(1000, HighestTrackableValue, NumberOfSignificantValueDigits);
            var targetShortHistogram = new ShortHistogram(1000, HighestTrackableValue, NumberOfSignificantValueDigits);
            shortHistogram.RecordValue(TestValueLevel);
            shortHistogram.RecordValue(TestValueLevel * 10);
            shortHistogram.RecordValueWithExpectedInterval(shortHistogram.HighestTrackableValue - 1, 31000);

            Console.WriteLine("Testing copyInto for scaled ShortHistogram:");
            shortHistogram.CopyInto(targetShortHistogram);
            AssertEqual(shortHistogram, targetShortHistogram);

            shortHistogram.RecordValue(TestValueLevel * 20);

            shortHistogram.CopyInto(targetShortHistogram);
            AssertEqual(shortHistogram, targetShortHistogram);

            var syncHistogram = new SynchronizedHistogram(1000, HighestTrackableValue, NumberOfSignificantValueDigits);
            var targetSyncHistogram = new SynchronizedHistogram(1000, HighestTrackableValue, NumberOfSignificantValueDigits);
            syncHistogram.RecordValue(TestValueLevel);
            syncHistogram.RecordValue(TestValueLevel * 10);
            syncHistogram.RecordValueWithExpectedInterval(syncHistogram.HighestTrackableValue - 1, 31000);

            Console.WriteLine("Testing copyInto for scaled SynchronizedHistogram:");
            syncHistogram.CopyInto(targetSyncHistogram);
            AssertEqual(syncHistogram, targetSyncHistogram);

            syncHistogram.RecordValue(TestValueLevel * 20);

            syncHistogram.CopyInto(targetSyncHistogram);
            AssertEqual(syncHistogram, targetSyncHistogram);
        }
예제 #49
0
 public void TestLowestEquivalentValue()
 {
     var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
     Assert.AreEqual(10000, longHistogram.LowestEquivalentValue(10007), "The lowest equivalent value to 10007 is 10000");
     Assert.AreEqual(10008, longHistogram.LowestEquivalentValue(10009), "The lowest equivalent value to 10009 is 10008");
 }
        public void Using_external_histogram_for_recycling_throws()
        {
            var externallyCreatedHistogram = new LongHistogram(HighestTrackableValue, 3);
            var recorder = new Recorder(1, HighestTrackableValue, NumberOfSignificantValueDigits, (id, lowest, highest, sf) => new LongHistogram(id, lowest, highest, sf));
            recorder.RecordValue(1000);

            Assert.Throws<InvalidOperationException>(() => recorder.GetIntervalHistogram(externallyCreatedHistogram));

            recorder.GetIntervalHistogramInto(externallyCreatedHistogram);
        }
예제 #51
0
        public void TestCopy()
        {
            var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
            longHistogram.RecordValue(TestValueLevel);
            longHistogram.RecordValue(TestValueLevel * 10);
            longHistogram.RecordValueWithExpectedInterval(longHistogram.HighestTrackableValue - 1, 31000);

            Console.WriteLine("Testing copy of Histogram:");
            AssertEqual(longHistogram, longHistogram.Copy());

            var intHistogram = new IntHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
            intHistogram.RecordValue(TestValueLevel);
            intHistogram.RecordValue(TestValueLevel * 10);
            intHistogram.RecordValueWithExpectedInterval(intHistogram.HighestTrackableValue - 1, 31000);

            Console.WriteLine("Testing copy of IntHistogram:");
            AssertEqual(intHistogram, intHistogram.Copy());

            var shortHistogram = new ShortHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
            shortHistogram.RecordValue(TestValueLevel);
            shortHistogram.RecordValue(TestValueLevel * 10);
            shortHistogram.RecordValueWithExpectedInterval(shortHistogram.HighestTrackableValue - 1, 31000);

            Console.WriteLine("Testing copy of ShortHistogram:");
            AssertEqual(shortHistogram, shortHistogram.Copy());

            var syncHistogram = new SynchronizedHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
            syncHistogram.RecordValue(TestValueLevel);
            syncHistogram.RecordValue(TestValueLevel * 10);
            syncHistogram.RecordValueWithExpectedInterval(syncHistogram.HighestTrackableValue - 1, 31000);

            Console.WriteLine("Testing copy of SynchronizedHistogram:");
            AssertEqual(syncHistogram, syncHistogram.Copy());
        }
예제 #52
0
 public void TestNextNonEquivalentValue()
 {
     //HACK: WTF does this prove? -LC
     var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
     Assert.IsNotNull(longHistogram);
 }
예제 #53
0
 public void TestScaledMedianEquivalentValue()
 {
     var longHistogram = new LongHistogram(1024, HighestTrackableValue, NumberOfSignificantValueDigits);
     Assert.AreEqual(4 * 1024 + 512, longHistogram.MedianEquivalentValue(4 * 1024), "The median equivalent value to 4 * 1024 is 4 * 1024 + 512");
     Assert.AreEqual(5 * 1024 + 512, longHistogram.MedianEquivalentValue(5 * 1024), "The median equivalent value to 5 * 1024 is 5 * 1024 + 512");
     Assert.AreEqual(4001 * 1024, longHistogram.MedianEquivalentValue(4000 * 1024), "The median equivalent value to 4000 * 1024 is 4001 * 1024");
     Assert.AreEqual(8002 * 1024, longHistogram.MedianEquivalentValue(8000 * 1024), "The median equivalent value to 8000 * 1024 is 8002 * 1024");
     Assert.AreEqual(10004 * 1024, longHistogram.MedianEquivalentValue(10007 * 1024), "The median equivalent value to 10007 * 1024 is 10004 * 1024");
 }
예제 #54
0
 public void TestMedianEquivalentValue()
 {
     var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
     Assert.AreEqual(4, longHistogram.MedianEquivalentValue(4), "The median equivalent value to 4 is 4");
     Assert.AreEqual(5, longHistogram.MedianEquivalentValue(5), "The median equivalent value to 5 is 5");
     Assert.AreEqual(4001, longHistogram.MedianEquivalentValue(4000), "The median equivalent value to 4000 is 4001");
     Assert.AreEqual(8002, longHistogram.MedianEquivalentValue(8000), "The median equivalent value to 8000 is 8002");
     Assert.AreEqual(10004, longHistogram.MedianEquivalentValue(10007), "The median equivalent value to 10007 is 10004");
 }
예제 #55
0
 public void TestScaledSizeOfEquivalentValueRange()
 {
     var longHistogram = new LongHistogram(1024, HighestTrackableValue, NumberOfSignificantValueDigits);
     Assert.AreEqual(1 * 1024, longHistogram.SizeOfEquivalentValueRange(1 * 1024), "Size of equivalent range for value 1 * 1024 is 1 * 1024");
     Assert.AreEqual(2 * 1024, longHistogram.SizeOfEquivalentValueRange(2500 * 1024), "Size of equivalent range for value 2500 * 1024 is 2 * 1024");
     Assert.AreEqual(4 * 1024, longHistogram.SizeOfEquivalentValueRange(8191 * 1024), "Size of equivalent range for value 8191 * 1024 is 4 * 1024");
     Assert.AreEqual(8 * 1024, longHistogram.SizeOfEquivalentValueRange(8192 * 1024), "Size of equivalent range for value 8192 * 1024 is 8 * 1024");
     Assert.AreEqual(8 * 1024, longHistogram.SizeOfEquivalentValueRange(10000 * 1024), "Size of equivalent range for value 10000 * 1024 is 8 * 1024");
 }
예제 #56
0
        public void TestCopyInto()
        {
            var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
            var targetLongHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
            longHistogram.RecordValue(TestValueLevel);
            longHistogram.RecordValue(TestValueLevel * 10);
            longHistogram.RecordValueWithExpectedInterval(longHistogram.HighestTrackableValue - 1, 31000);

            Console.WriteLine("Testing copyInto for Histogram:");
            longHistogram.CopyInto(targetLongHistogram);
            AssertEqual(longHistogram, targetLongHistogram);

            longHistogram.RecordValue(TestValueLevel * 20);

            longHistogram.CopyInto(targetLongHistogram);
            AssertEqual(longHistogram, targetLongHistogram);

            var intHistogram = new IntHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
            var targetIntHistogram = new IntHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
            intHistogram.RecordValue(TestValueLevel);
            intHistogram.RecordValue(TestValueLevel * 10);
            intHistogram.RecordValueWithExpectedInterval(intHistogram.HighestTrackableValue - 1, 31000);

            Console.WriteLine("Testing copyInto for IntHistogram:");
            intHistogram.CopyInto(targetIntHistogram);
            AssertEqual(intHistogram, targetIntHistogram);

            intHistogram.RecordValue(TestValueLevel * 20);

            intHistogram.CopyInto(targetIntHistogram);
            AssertEqual(intHistogram, targetIntHistogram);

            var shortHistogram = new ShortHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
            var targetShortHistogram = new ShortHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
            shortHistogram.RecordValue(TestValueLevel);
            shortHistogram.RecordValue(TestValueLevel * 10);
            shortHistogram.RecordValueWithExpectedInterval(shortHistogram.HighestTrackableValue - 1, 31000);

            Console.WriteLine("Testing copyInto for ShortHistogram:");
            shortHistogram.CopyInto(targetShortHistogram);
            AssertEqual(shortHistogram, targetShortHistogram);

            shortHistogram.RecordValue(TestValueLevel * 20);

            shortHistogram.CopyInto(targetShortHistogram);
            AssertEqual(shortHistogram, targetShortHistogram);

            Console.WriteLine("Testing copyInto for AtomicHistogram:");

            var syncHistogram = new SynchronizedHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
            var targetSyncHistogram = new SynchronizedHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
            syncHistogram.RecordValue(TestValueLevel);
            syncHistogram.RecordValue(TestValueLevel * 10);
            syncHistogram.RecordValueWithExpectedInterval(syncHistogram.HighestTrackableValue - 1, 31000); // Should this really be 31, if it is the test takes 1min!!!);

            Console.WriteLine("Testing copyInto for SynchronizedHistogram:");
            syncHistogram.CopyInto(targetSyncHistogram);
            AssertEqual(syncHistogram, targetSyncHistogram);

            syncHistogram.RecordValue(TestValueLevel * 20);

            syncHistogram.CopyInto(targetSyncHistogram);
            AssertEqual(syncHistogram, targetSyncHistogram);
        }
예제 #57
0
 public void TestHighestEquivalentValue()
 {
     var longHistogram = new LongHistogram(1024, HighestTrackableValue, NumberOfSignificantValueDigits);
     Assert.AreEqual(8183 * 1024 + 1023, longHistogram.HighestEquivalentValue(8180 * 1024), "The highest equivalent value to 8180 * 1024 is 8183 * 1024 + 1023");
     Assert.AreEqual(8191 * 1024 + 1023, longHistogram.HighestEquivalentValue(8191 * 1024), "The highest equivalent value to 8187 * 1024 is 8191 * 1024 + 1023");
     Assert.AreEqual(8199 * 1024 + 1023, longHistogram.HighestEquivalentValue(8193 * 1024), "The highest equivalent value to 8193 * 1024 is 8199 * 1024 + 1023");
     Assert.AreEqual(9999 * 1024 + 1023, longHistogram.HighestEquivalentValue(9995 * 1024), "The highest equivalent value to 9995 * 1024 is 9999 * 1024 + 1023");
     Assert.AreEqual(10007 * 1024 + 1023, longHistogram.HighestEquivalentValue(10007 * 1024), "The highest equivalent value to 10007 * 1024 is 10007 * 1024 + 1023");
     Assert.AreEqual(10015 * 1024 + 1023, longHistogram.HighestEquivalentValue(10008 * 1024), "The highest equivalent value to 10008 * 1024 is 10015 * 1024 + 1023");
 }
예제 #58
0
 public void TestScaledLowestEquivalentValue()
 {
     var longHistogram = new LongHistogram(1024, HighestTrackableValue, NumberOfSignificantValueDigits);
     Assert.AreEqual(10000 * 1024, longHistogram.LowestEquivalentValue(10007 * 1024), "The lowest equivalent value to 10007 * 1024 is 10000 * 1024");
     Assert.AreEqual(10008 * 1024, longHistogram.LowestEquivalentValue(10009 * 1024), "The lowest equivalent value to 10009 * 1024 is 10008 * 1024");
 }
        public void CanReadv1Logs_Skip_PreStart(string logPath, int skip, int take,
            int expectedHistogramCount, int expectedCombinedValueCount,
            int expectedCombined999, long expectedCombinedMaxLength,
            double expectedStartTime)
        {
            var readerStream = GetEmbeddedFileStream(logPath);
            var reader = new HistogramLogReader(readerStream);
            int histogramCount = 0;
            long totalCount = 0;

            HistogramBase accumulatedHistogram = new LongHistogram(3600L * 1000 * 1000 * 1000, 3);
            var histograms = reader.ReadHistograms()
                .Where(h => h.StartTimeStamp >= reader.GetStartTime().MillisecondsSinceUnixEpoch())
                .Skip(skip)
                .Take(take);
            foreach (var histogram in histograms)
            {
                histogramCount++;
                totalCount += histogram.TotalCount;
                accumulatedHistogram.Add(histogram);
            }

            Assert.AreEqual(expectedHistogramCount, histogramCount);
            Assert.AreEqual(expectedCombinedValueCount, totalCount);
            Assert.AreEqual(expectedCombined999, accumulatedHistogram.GetValueAtPercentile(99.9));
            Assert.AreEqual(expectedCombinedMaxLength, accumulatedHistogram.GetMaxValue());
            Assert.AreEqual(expectedStartTime, reader.GetStartTime().SecondsSinceUnixEpoch());
        }
예제 #60
0
 public void TestScaledHighestEquivalentValue()
 {
     var longHistogram = new LongHistogram(HighestTrackableValue, NumberOfSignificantValueDigits);
     Assert.AreEqual(8183, longHistogram.HighestEquivalentValue(8180), "The highest equivalent value to 8180 is 8183");
     Assert.AreEqual(8191, longHistogram.HighestEquivalentValue(8191), "The highest equivalent value to 8187 is 8191");
     Assert.AreEqual(8199, longHistogram.HighestEquivalentValue(8193), "The highest equivalent value to 8193 is 8199");
     Assert.AreEqual(9999, longHistogram.HighestEquivalentValue(9995), "The highest equivalent value to 9995 is 9999");
     Assert.AreEqual(10007, longHistogram.HighestEquivalentValue(10007), "The highest equivalent value to 10007 is 10007");
     Assert.AreEqual(10015, longHistogram.HighestEquivalentValue(10008), "The highest equivalent value to 10008 is 10015");
 }