public void Can_retrieve_decaying_rate_with_discrete_value() { var ewma = EWMA.OneMinuteEWMA(InitialTimestamp); ewma.Update(3); ewma.Tick(FiveSecondsTimestamp); // Assumes 5 seconds have passed var rate = ewma.Rate(TimeUnit.Seconds); Assert.AreEqual(0.6, rate, "the EWMA has a rate of 0.6 events/sec after the first tick"); var timestamp = FiveSecondsTimestamp; timestamp = ElapseMinute(timestamp, ewma); rate = ewma.Rate(TimeUnit.Seconds); AssertIsCloseTo(0.22072766, rate, 8, "the EWMA has a rate of 0.22072766 events/sec after 1 minute"); timestamp = ElapseMinute(timestamp, ewma); rate = ewma.Rate(TimeUnit.Seconds); AssertIsCloseTo(0.08120116, rate, 8, "the EWMA has a rate of 0.08120116 events/sec after 2 minutes"); timestamp = ElapseMinute(timestamp, ewma); rate = ewma.Rate(TimeUnit.Seconds); AssertIsCloseTo(0.02987224, rate, 8, "the EWMA has a rate of 0.02987224 events/sec after 3 minutes"); timestamp = ElapseMinute(timestamp, ewma); rate = ewma.Rate(TimeUnit.Seconds); AssertIsCloseTo(0.01098938, rate, 8, "the EWMA has a rate of 0.01098938 events/sec after 4 minutes"); timestamp = ElapseMinute(timestamp, ewma); rate = ewma.Rate(TimeUnit.Seconds); AssertIsCloseTo(0.00404276, rate, 8, "the EWMA has a rate of 0.00404276 events/sec after 5 minutes"); timestamp = ElapseMinute(timestamp, ewma); rate = ewma.Rate(TimeUnit.Seconds); AssertIsCloseTo(0.00148725, rate, 8, "the EWMA has a rate of 0.00148725 events/sec after 6 minutes"); timestamp = ElapseMinute(timestamp, ewma); rate = ewma.Rate(TimeUnit.Seconds); AssertIsCloseTo(0.00054712, rate, 8, "the EWMA has a rate of 0.00054712 events/sec after 7 minutes"); ElapseMinute(timestamp, ewma); rate = ewma.Rate(TimeUnit.Seconds); AssertIsCloseTo(0.00020127, rate, 8, "the EWMA has a rate of 0.00020127 events/sec after 8 minutes"); }
public MeterMetric(string eventType, TimeUnit rateUnit) { var timestamp = Timer.ElapsedNanoseconds; _m1Rate = EWMA.OneMinuteEWMA(timestamp); _m5Rate = EWMA.FiveMinuteEWMA(timestamp); _m15Rate = EWMA.FifteenMinuteEWMA(timestamp); EventType = eventType; RateUnit = rateUnit; Timer.Tick += Tick; }
static void Main(string[] args) { //FixedTimeBenchmark.Run<CounterMetric>(m => m.Increment()); //FixedTimeBenchmark.Run<MeterMetric>(m => m.Mark()); //FixedTimeBenchmark.Run<HistogramMetric>(m => m.Update(1)); FixedTimeBenchmark.Run(() => EWMA.OneMinuteEWMA(), m => m.Update(1), maxThreads: 32, seconds: 5, decrement: 4); //FixedTimeBenchmark.Run(() => new TimerMetric(new SlidingWindowReservoir()), m => { using (m.NewContext()) { } }, maxThreads: 32, seconds: 5, decrement: 4); //FixedTimeBenchmark.Run(() => new ExponentiallyDecayingReservoir(), r => r.Update(100), maxThreads: 32, seconds: 5, decrement: 4); //FixedTimeBenchmark.Run(() => new UniformReservoir(), r => r.Update(100), maxThreads: 32, seconds: 5, decrement: 4); //FixedIterationsBenchmark.Run<TimerMetric>(m => { using (m.NewContext()) { } }, 1000 * 1000); }
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); } Console.WriteLine("{0} | Duration {1} seconds | Start Threads {2} | Step {3}", target, targetOptions.Seconds, targetOptions.MaxThreads, targetOptions.Decrement); switch (target) { case "counter": Run(() => new CounterMetric(), c => c.Increment()); break; case "meter": Run(() => new MeterMetric(), m => m.Mark()); break; case "histogram": Run(() => new HistogramMetric(), h => h.Update(37)); break; case "timer": Run(() => new TimerMetric(SamplingType.FavourRecent), t => t.Record(10, TimeUnit.Milliseconds)); break; case "ewma": Run(() => EWMA.OneMinuteEWMA(), m => m.Update(1)); break; case "edr": Run(() => new ExponentiallyDecayingReservoir(), r => r.Update(100)); break; case "uniform": Run(() => new UniformReservoir(), r => r.Update(100)); break; case "sliding": Run(() => new SlidingWindowReservoir(), r => r.Update(100)); break; } }
public void Can_relative_decay_rates_for_discrete_values() { var one = EWMA.OneMinuteEWMA(InitialTimestamp); one.Update(100000); one.Tick(FiveSecondsTimestamp); var five = EWMA.FiveMinuteEWMA(InitialTimestamp); five.Update(100000); five.Tick(FiveSecondsTimestamp); var fifteen = EWMA.FifteenMinuteEWMA(InitialTimestamp); fifteen.Update(100000); fifteen.Tick(FiveSecondsTimestamp); var rateOne = one.Rate(TimeUnit.Seconds); var rateFive = five.Rate(TimeUnit.Seconds); var rateFifteen = fifteen.Rate(TimeUnit.Seconds); Assert.AreEqual(20000, rateOne); Assert.AreEqual(20000, rateFive); Assert.AreEqual(20000, rateFifteen); var timestamp = FiveSecondsTimestamp; ElapseMinute(timestamp, one); rateOne = one.Rate(TimeUnit.Seconds); ElapseMinute(timestamp, five); rateFive = five.Rate(TimeUnit.Seconds); ElapseMinute(timestamp, fifteen); rateFifteen = fifteen.Rate(TimeUnit.Seconds); Assert.AreEqual(7357.5888234288504d, rateOne); Assert.AreEqual(16374.615061559636d, rateFive); Assert.AreEqual(18710.13970063235d, rateFifteen); }
public void EWMA_aOneMinuteEWMAWithAValueOfThree() { var ewma = EWMA.OneMinuteEWMA(); ewma.Update(3L); ewma.Tick(); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.6, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.22072766, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.08120117, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.02987224, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.01098938, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.00404277, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.00148725, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.00054713, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.00020128, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.00007405, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.00002724, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.00001002, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.00000369, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.00000136, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.00000050, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.00000018, 0.000001); }
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; } }