Esempio n. 1
0
        public void EDR_SpotLift()
        {
            var reservoir = new ExponentiallyDecayingReservoir(Constants.ReservoirSampling.DefaultSampleSize,
                                                               Constants.ReservoirSampling.DefaultExponentialDecayFactor,
                                                               _clock, _scheduler);

            var valuesRatePerMinute  = 10;
            var valuesIntervalMillis = (int)(TimeUnit.Minutes.ToMilliseconds(1) / valuesRatePerMinute);

            // mode 1: steady regime for 120 minutes
            for (var i = 0; i < 120 * valuesRatePerMinute; i++)
            {
                reservoir.Update(177);
                _clock.Advance(TimeUnit.Milliseconds, valuesIntervalMillis);
            }

            // switching to mode 2: 10 minutes more with the same rate, but larger value
            for (var i = 0; i < 10 * valuesRatePerMinute; i++)
            {
                reservoir.Update(9999);
                _clock.Advance(TimeUnit.Milliseconds, valuesIntervalMillis);
            }

            // expect that quantiles should be more about mode 2 after 10 minutes
            reservoir.GetSnapshot().Median.Should().Be(9999);
        }
Esempio n. 2
0
        public void EDR_SpotFall()
        {
            TestClock     clock     = new TestClock();
            TestScheduler scheduler = new TestScheduler(clock);
            ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir(1000, 0.015, clock, scheduler);

            int valuesRatePerMinute  = 10;
            int valuesIntervalMillis = (int)(TimeUnit.Minutes.ToMilliseconds(1) / valuesRatePerMinute);

            // mode 1: steady regime for 120 minutes
            for (int i = 0; i < 120 * valuesRatePerMinute; i++)
            {
                reservoir.Update(9998);
                clock.Advance(TimeUnit.Milliseconds, valuesIntervalMillis);
            }

            // switching to mode 2: 10 minutes more with the same rate, but smaller value
            for (int i = 0; i < 10 * valuesRatePerMinute; i++)
            {
                reservoir.Update(178);
                clock.Advance(TimeUnit.Milliseconds, valuesIntervalMillis);
            }

            // expect that quantiles should be more about mode 2 after 10 minutes
            reservoir.Snapshot.Percentile95.Should().Be(178);
        }
Esempio n. 3
0
        public void EDR_QuantiliesShouldBeBasedOnWeights()
        {
            TestClock     clock     = new TestClock();
            TestScheduler scheduler = new TestScheduler(clock);
            ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir(1000, 0.015, clock, scheduler);

            for (int i = 0; i < 40; i++)
            {
                reservoir.Update(177);
            }

            clock.Advance(TimeUnit.Seconds, 120);

            for (int i = 0; i < 10; i++)
            {
                reservoir.Update(9999);
            }

            reservoir.Snapshot.Size.Should().Be(50);

            // the first added 40 items (177) have weights 1
            // the next added 10 items (9999) have weights ~6
            // so, it's 40 vs 60 distribution, not 40 vs 10
            reservoir.Snapshot.Median.Should().Be(9999);
            reservoir.Snapshot.Percentile75.Should().Be(9999);
        }
Esempio n. 4
0
        public void EDR_QuantiliesShouldBeBasedOnWeights()
        {
            var reservoir = new ExponentiallyDecayingReservoir(Constants.ReservoirSampling.DefaultSampleSize,
                                                               Constants.ReservoirSampling.DefaultExponentialDecayFactor,
                                                               _clock, _scheduler);

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

            _clock.Advance(TimeUnit.Seconds, 120);

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

            reservoir.GetSnapshot().Size.Should().Be(50);

            // the first added 40 items (177) have weights 1
            // the next added 10 items (9999) have weights ~6
            // so, it's 40 vs 60 distribution, not 40 vs 10
            reservoir.GetSnapshot().Median.Should().Be(9999);
            reservoir.GetSnapshot().Percentile75.Should().Be(9999);
        }
        public void EDR_RecordsUserValue()
        {
            ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir(clock, scheduler);

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

            reservoir.GetSnapshot().MinUserValue.Should().Be("A");
            reservoir.GetSnapshot().MaxUserValue.Should().Be("B");
        }
Esempio n. 6
0
        public void EDR_RecordsUserValue()
        {
            TestClock     clock     = new TestClock();
            TestScheduler scheduler = new TestScheduler(clock);
            ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir(1000, 0.015, clock, scheduler);

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

            reservoir.Snapshot.MinUserValue.Should().Be("A");
            reservoir.Snapshot.MaxUserValue.Should().Be("B");
        }
Esempio n. 7
0
        public void EDR_RecordsUserValue()
        {
            var reservoir = new ExponentiallyDecayingReservoir(Constants.ReservoirSampling.DefaultSampleSize,
                                                               Constants.ReservoirSampling.DefaultExponentialDecayFactor,
                                                               _clock, _scheduler);

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

            reservoir.GetSnapshot().MinUserValue.Should().Be("A");
            reservoir.GetSnapshot().MaxUserValue.Should().Be("B");
        }
        public void EDR_HeavilyBiasedReservoirOf100OutOf1000Elements()
        {
            ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir(1000, 0.01);
            for (int i = 0; i < 100; i++)
            {
                reservoir.Update(i);
            }

            reservoir.Size.Should().Be(100);
            var snapshot = reservoir.GetSnapshot();
            snapshot.Size.Should().Be(100);
            snapshot.Values.Should().OnlyContain(v => 0 <= v && v < 100);
        }
        public void ExponentialDecayingResevoir()
        {
            var reservoir = new ExponentiallyDecayingReservoir(Constants.ReservoirSampling.DefaultSampleSize, Constants.ReservoirSampling.DefaultExponentialDecayFactor);

            foreach (var sample in _samples)
            {
                reservoir.Update(sample);
            }

            var snapshot = reservoir.GetSnapshot();

            //TODO: Assert snapshot
            //snapshot.AssertValues(_samples);
        }
Esempio n. 10
0
        public void EDR_HeavilyBiasedReservoirOf100OutOf1000Elements()
        {
            var reservoir = new ExponentiallyDecayingReservoir(1000, 0.01);

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

            reservoir.Size.Should().Be(100);
            var snapshot = reservoir.GetSnapshot();

            snapshot.Size.Should().Be(100);
            snapshot.Values.Should().OnlyContain(v => 0 <= v && v < 100);
        }
Esempio n. 11
0
        public void can_report_apdex()
        {
            var expected  = StringReporterSamples.Apdex.ExtractStringReporterSampleFromResourceFile();
            var clock     = new TestClock();
            var sr        = new StringReporter();
            var reservoir = new ExponentiallyDecayingReservoir(Constants.ReservoirSampling.DefaultSampleSize,
                                                               Constants.ReservoirSampling.DefaultExponentialDecayFactor, clock, new TestTaskScheduler(clock));
            var metric = new ApdexMetric(new ApdexProvider(reservoir, Constants.ReservoirSampling.DefaultApdexTSeconds), clock, true);

            metric.Track(1000);

            sr.ReportMetric("test", new ApdexValueSource("apdex_name", metric, MetricTags.None));

            AssertReportResult(sr.Result, expected);
        }
Esempio n. 12
0
        public void EDR_ReservoirOf100OutOf10Elements()
        {
            ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir(100, 0.99);

            for (int i = 0; i < 10; i++)
            {
                reservoir.Update(i);
            }

            reservoir.Size.Should().Be(10);
            var snapshot = reservoir.Snapshot;

            snapshot.Size.Should().Be(10);
            snapshot.Values.Should().OnlyContain(v => 0 <= v && v < 10);
        }
Esempio n. 13
0
        public void EDR_longPeriodsOfInactivityShouldNotCorruptSamplingState()
        {
            TestClock     clock     = new TestClock();
            TestScheduler scheduler = new TestScheduler(clock);

            ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir(10, 0.015, clock, scheduler);

            // add 1000 values at a rate of 10 values/second
            for (int i = 0; i < 1000; i++)
            {
                reservoir.Update(1000 + i);
                clock.Advance(TimeUnit.Milliseconds, 100);
            }

            reservoir.Snapshot.Size.Should().Be(10);
            reservoir.Snapshot.Values.Should().OnlyContain(v => 1000 <= v && v < 2000);

            // wait for 15 hours and add another value.
            // this should trigger a rescale. Note that the number of samples will be reduced to 2
            // because of the very small scaling factor that will make all existing priorities equal to
            // zero after rescale.
            clock.Advance(TimeUnit.Hours, 15);
            reservoir.Update(2000);
            var snapshot = reservoir.Snapshot;

            snapshot.Size.Should().Be(2);
            snapshot.Values.Should().OnlyContain(v => 1000 <= v && v < 3000);

            // add 1000 values at a rate of 10 values/second
            for (int i = 0; i < 1000; i++)
            {
                reservoir.Update(3000 + i);
                clock.Advance(TimeUnit.Milliseconds, 100);
            }

            var finalSnapshot = reservoir.Snapshot;

            finalSnapshot.Size.Should().Be(10);
            // TODO: double check the Skip first value - sometimes first value is 2000 - which might or not be correct
            finalSnapshot.Values.Skip(1).Should().OnlyContain(v => 3000 <= v && v < 4000);
        }
Esempio n. 14
0
        public void EDR_longPeriodsOfInactivityShouldNotCorruptSamplingState()
        {
            var reservoir = new ExponentiallyDecayingReservoir(10, 0.015, _clock, _scheduler);

            // add 1000 values at a rate of 10 values/second
            for (var i = 0; i < 1000; i++)
            {
                reservoir.Update(1000 + i);
                _clock.Advance(TimeUnit.Milliseconds, 100);
            }

            reservoir.GetSnapshot().Size.Should().Be(10);
            reservoir.GetSnapshot().Values.Should().OnlyContain(v => 1000 <= v && v < 2000);

            // wait for 15 hours and add another value.
            // this should trigger a rescale. Note that the number of samples will be reduced to 2
            // because of the very small scaling factor that will make all existing priorities equal to
            // zero after rescale.
            _clock.Advance(TimeUnit.Hours, 15);
            reservoir.Update(2000);
            var snapshot = reservoir.GetSnapshot();

            snapshot.Size.Should().Be(2);
            snapshot.Values.Should().OnlyContain(v => 1000 <= v && v < 3000);

            // add 1000 values at a rate of 10 values/second
            for (var i = 0; i < 1000; i++)
            {
                reservoir.Update(3000 + i);
                _clock.Advance(TimeUnit.Milliseconds, 100);
            }

            var finalSnapshot = reservoir.GetSnapshot();

            finalSnapshot.Size.Should().Be(10);
            finalSnapshot.Values.Skip(1).Should().OnlyContain(v => 3000 <= v && v < 4000);
        }
        public void EDR_longPeriodsOfInactivityShouldNotCorruptSamplingState()
        {
            ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir(10, 0.015, clock, scheduler);

            // add 1000 values at a rate of 10 values/second
            for (int i = 0; i < 1000; i++)
            {
                reservoir.Update(1000 + i);
                clock.Advance(TimeUnit.Milliseconds, 100);
            }

            reservoir.GetSnapshot().Size.Should().Be(10);
            reservoir.GetSnapshot().Values.Should().OnlyContain(v => 1000 <= v && v < 2000);

            // wait for 15 hours and add another value.
            // this should trigger a rescale. Note that the number of samples will be reduced to 2
            // because of the very small scaling factor that will make all existing priorities equal to
            // zero after rescale.
            clock.Advance(TimeUnit.Hours, 15);
            reservoir.Update(2000);
            var snapshot = reservoir.GetSnapshot();
            snapshot.Size.Should().Be(2);
            snapshot.Values.Should().OnlyContain(v => 1000 <= v && v < 3000);

            // add 1000 values at a rate of 10 values/second
            for (int i = 0; i < 1000; i++)
            {
                reservoir.Update(3000 + i);
                clock.Advance(TimeUnit.Milliseconds, 100);
            }

            var finalSnapshot = reservoir.GetSnapshot();

            finalSnapshot.Size.Should().Be(10);
            // TODO: double check the Skip first value - sometimes first value is 2000 - which might or not be correct
            finalSnapshot.Values.Skip(1).Should().OnlyContain(v => 3000 <= v && v < 4000);
        }
        public void EDR_QuantiliesShouldBeBasedOnWeights()
        {
            ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir(clock, scheduler);

            for (int i = 0; i < 40; i++)
            {
                reservoir.Update(177);
            }

            clock.Advance(TimeUnit.Seconds, 120);

            for (int i = 0; i < 10; i++)
            {
                reservoir.Update(9999);
            }

            reservoir.GetSnapshot().Size.Should().Be(50);

            // the first added 40 items (177) have weights 1 
            // the next added 10 items (9999) have weights ~6 
            // so, it's 40 vs 60 distribution, not 40 vs 10
            reservoir.GetSnapshot().Median.Should().Be(9999);
            reservoir.GetSnapshot().Percentile75.Should().Be(9999);
        }
        public void EDR_RecordsUserValue()
        {
            ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir(clock, scheduler);

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

            reservoir.GetSnapshot().MinUserValue.Should().Be("A");
            reservoir.GetSnapshot().MaxUserValue.Should().Be("B");
        }
        public void EDR_SpotFall()
        {
            ExponentiallyDecayingReservoir reservoir = new ExponentiallyDecayingReservoir(clock, scheduler);

            int valuesRatePerMinute = 10;
            int valuesIntervalMillis = (int)(TimeUnit.Minutes.ToMilliseconds(1) / valuesRatePerMinute);
            // mode 1: steady regime for 120 minutes
            for (int i = 0; i < 120 * valuesRatePerMinute; i++)
            {
                reservoir.Update(9998);
                clock.Advance(TimeUnit.Milliseconds, valuesIntervalMillis);
            }

            // switching to mode 2: 10 minutes more with the same rate, but smaller value
            for (int i = 0; i < 10 * valuesRatePerMinute; i++)
            {
                reservoir.Update(178);
                clock.Advance(TimeUnit.Milliseconds, valuesIntervalMillis);
            }

            // expect that quantiles should be more about mode 2 after 10 minutes
            reservoir.GetSnapshot().Percentile95.Should().Be(178);
        }
Esempio n. 19
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 ExponentiallyDecayingReservoir()
        {
            var reservoir = new ExponentiallyDecayingReservoir(SampleSize, ExponentialDecayFactor);

            Run(reservoir);
        }