public void Should_RefreshEntireHistogramAfterRefreshInterval()
        {
            var target = new HdrHistogramReservoir(1, 30000, 3, 1000);

            Parallel.ForEach(Enumerable.Range(1, 100), i => target.Update(i));

            AssertEmptySnapshot(target.GetSnapshot(false));
            AssertEmptySnapshot(target.GetSnapshot(false));

            TestHelper.RetryAssert(
                () =>
            {
                AssertFirstSnapshot(target.GetSnapshot(false));
            },
                200,
                15);

            Parallel.ForEach(Enumerable.Range(201, 100), i => target.Update(i));

            AssertFirstSnapshot(target.GetSnapshot(false));
            AssertFirstSnapshot(target.GetSnapshot(false));

            TestHelper.RetryAssert(
                () =>
            {
                AssertSecondSnapshot(target.GetSnapshot(false));
            },
                200,
                15);

            AssertSecondSnapshot(target.GetSnapshot(false));
            AssertSecondSnapshot(target.GetSnapshot(false));
        }
        public async Task Should_ReturnEmptyHistogram_When_ResetIsCalled()
        {
            var target = new HdrHistogramReservoir(1, 1000000000000, 3, 2000);

            var tcs = new CancellationTokenSource();

            AssertEmptySnapshot(target.GetSnapshot(false));

            Parallel.ForEach(Enumerable.Range(1, 100), i => target.Update(i));

            AssertEmptySnapshot(target.GetSnapshot(false));
            await Task.Yield();

            AssertEmptySnapshot(target.GetSnapshot(false));

            TestHelper.RetryAssert(
                () =>
            {
                AssertFirstSnapshot(target.GetSnapshot(false));
            },
                200,
                20);

            var tasks = Enumerable.Range(0, 4).Select(i => Task.Run(async() =>
            {
                var current = i * 100000;
                while (!tcs.IsCancellationRequested)
                {
                    if (current == int.MaxValue)
                    {
                        current = 0;
                    }

                    target.Update(++current);
                    await Task.Yield();
                }
            })).ToList();

            try
            {
                AssertFirstSnapshot(target.GetSnapshot(false));
                await Task.Yield();

                AssertFirstSnapshot(target.GetSnapshot(false));

                // reset
                AssertFirstSnapshot(target.GetSnapshot(true));

                AssertEmptySnapshot(target.GetSnapshot(false));
                await Task.Yield();

                AssertEmptySnapshot(target.GetSnapshot(false));
            }
            finally
            {
                tcs.Cancel();
                await Task.WhenAll(tasks).ConfigureAwait(false);
            }
        }
        public void Should_EmptySnapshotBeThreadSafe()
        {
            var target = new HdrHistogramReservoir(1, 1000, 3, 10000);

            Parallel.ForEach(Enumerable.Range(1, 100000), i => AssertEmptySnapshot(target.GetSnapshot(false)));
            target.Reset();
            Parallel.ForEach(Enumerable.Range(1, 100000), i => AssertEmptySnapshot(target.GetSnapshot(false)));
            Parallel.ForEach(Enumerable.Range(1, 1000), i => AssertEmptySnapshot(target.GetSnapshot(true)));
        }
Exemple #4
0
        public void can_records_user_value()
        {
            var reservoir = new HdrHistogramReservoir(new Recorder(2));

            reservoir.Update(2L, "B");
            reservoir.Update(1L, "A");

            var snapshot = reservoir.GetSnapshot();

            snapshot.MinUserValue.Should().Be("A");
            snapshot.Min.Should().Be(1L);
            snapshot.MaxUserValue.Should().Be("B");
            snapshot.Max.Should().Be(2L);
        }
Exemple #5
0
        public void snap_shot_reflects_what_was_recorded()
        {
            var reservoir = new HdrHistogramReservoir(new Recorder(2));

            for (var i = 0; i < 1000; i++)
            {
                reservoir.Update(i);
            }

            var snapshot = reservoir.GetSnapshot();

            snapshot.Count.Should().Be(1000);
            snapshot.Median.Should().Be(499);
            snapshot.Mean.Should().BeApproximately(499, 1);
            snapshot.Min.Should().Be(0);
            snapshot.Max.Should().Be(999);
            snapshot.Size.Should().Be(4608);
            snapshot.Percentile75.Should().Be(751);
            snapshot.Percentile95.Should().Be(951);
            snapshot.Percentile98.Should().Be(979);
            snapshot.Percentile99.Should().Be(991);
            snapshot.Percentile999.Should().Be(999);
        }
Exemple #6
0
        static void Main(string[] args)
        {
            var options = new Options();

            if (!Parser.Default.ParseArguments(args, options, (t, o) => { target = t; targetOptions = o as CommonOptions; }))
            {
                Console.WriteLine(new CommonOptions().GetUsage());
                Environment.Exit(CommandLine.Parser.DefaultExitCodeFail);
            }

            BenchmarkRunner.DefaultTotalSeconds = targetOptions.Seconds;
            BenchmarkRunner.DefaultMaxThreads   = targetOptions.MaxThreads;

            //Metric.Config.WithHttpEndpoint("http://localhost:1234/");

            switch (target)
            {
            case "noop":
                BenchmarkRunner.Run("Noop", () => { });
                break;

            case "counter":
                var counter = new CounterMetric();
                BenchmarkRunner.Run("Counter", () => counter.Increment());
                break;

            case "meter":
                var meter = new MeterMetric();
                BenchmarkRunner.Run("Meter", () => meter.Mark());
                break;

            case "histogram":
                var histogram = new HistogramMetric();
                BenchmarkRunner.Run("Histogram", () => histogram.Update(137));
                break;

            case "timer":
                var timer = new TimerMetric();
                BenchmarkRunner.Run("Timer", () => timer.Record(1, TimeUnit.Milliseconds));
                break;

            case "hdrtimer":
                var hdrTimer = new TimerMetric(new HdrHistogramReservoir());
                BenchmarkRunner.Run("HDR Timer", () => hdrTimer.Record(1, TimeUnit.Milliseconds));
                break;

            case "ewma":
                var ewma = EWMA.OneMinuteEWMA();
                BenchmarkRunner.Run("EWMA", () => ewma.Update(1));
                break;

            case "edr":
                var edr = new ExponentiallyDecayingReservoir();
                BenchmarkRunner.Run("EDR", () => edr.Update(1));
                break;

            case "hdr":
                var hdrReservoir = new HdrHistogramReservoir();
                BenchmarkRunner.Run("HDR Recorder", () => hdrReservoir.Update(1));
                break;

            case "uniform":
                var uniform = new UniformReservoir();
                BenchmarkRunner.Run("Uniform", () => uniform.Update(1));
                break;

            case "sliding":
                var sliding = new SlidingWindowReservoir();
                BenchmarkRunner.Run("Sliding", () => sliding.Update(1));
                break;

            case "timerimpact":
                var load = new WorkLoad();
                BenchmarkRunner.Run("WorkWithoutTimer", () => load.DoSomeWork(), iterationsChunk: 10);
                BenchmarkRunner.Run("WorkWithTimer", () => load.DoSomeWorkWithATimer(), iterationsChunk: 10);
                break;
            }
        }
        public void HdrHistogramReservoir()
        {
            var reservoir = new HdrHistogramReservoir();

            Run(reservoir);
        }