Ejemplo n.º 1
0
        public void TestSummaryDecay()
        {
            var baseTime = new DateTime(2015, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            var sum = new Summary("test_summary", "helpless", new string[0], objectives: new List <QuantileEpsilonPair> {
                new QuantileEpsilonPair(0.1d, 0.001d)
            }, maxAge: TimeSpan.FromSeconds(100), ageBuckets: 10);
            var child = new Summary.Child();

            child.Init(sum, LabelValues.Empty, baseTime);

            Advanced.DataContracts.Summary m;
            var metric = new Metric();

            for (var i = 0; i < 1000; i++)
            {
                var now = baseTime.AddSeconds(i);
                child.Observe(i, now);

                if (i % 10 == 0)
                {
                    child.Populate(metric, now);
                    m = metric.summary;
                    var got  = m.quantile[0].value;
                    var want = Math.Max((double)i / 10, (double)i - 90);

                    Assert.IsTrue(Math.Abs(got - want) <= 1, $"{i}. got {got} want {want}");
                }
            }

            // Wait for MaxAge without observations and make sure quantiles are NaN.
            child.Populate(metric, baseTime.AddSeconds(1000).AddSeconds(100));
            m = metric.summary;

            Assert.IsTrue(double.IsNaN(m.quantile[0].value));
        }
Ejemplo n.º 2
0
        public void BenchmarkSummaryWrite(int w)
        {
            var stopwatch = new Stopwatch();

            var summary = new Summary("test_summary", "helpless", new string[0]);
            var child   = new Summary.Child();
            var now     = new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            child.Init(summary, LabelValues.Empty, now, true);

            const int N = 1000;

            for (var obsNum = 0; obsNum < 1000000; obsNum++)
            {
                child.Observe(obsNum, now);
            }

            stopwatch.Start();
            var tasks = new Task[w];

            for (var taskNum = 0; taskNum < w; taskNum++)
            {
                var metric = new Metric();

                tasks[taskNum] = Task.Factory.StartNew(() =>
                {
                    for (var i = 0; i < N; i++)
                    {
                        child.Populate(metric, now);
                    }
                });
            }

            Task.WaitAll(tasks);
            stopwatch.Stop();

            Trace.WriteLine($"{w} tasks doing {N} writes took {stopwatch.Elapsed.TotalMilliseconds} milliseconds");
        }
Ejemplo n.º 3
0
        public void BencharmSummaryWrite(int w)
        {
            var stopwatch = new Stopwatch();

            var summary = new Summary("test_summary", "helpless", new string[0]);
            var child = new Summary.Child();
            var now = new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            child.Init(summary, LabelValues.Empty, now);

            const int N = 1000;

            for (var obsNum = 0; obsNum < 1000000; obsNum++)
            {
                child.Observe(obsNum, now);
            }

            stopwatch.Start();
            var tasks = new Task[w];
            for (var taskNum = 0; taskNum < w; taskNum++)
            {
                var metric = new Metric();

                tasks[taskNum] = Task.Factory.StartNew(() =>
                {
                    for (var i = 0; i < N; i++)
                        child.Populate(metric, now);
                });
            }
            
            Task.WaitAll(tasks);
            stopwatch.Stop();

            TestContext.WriteLine($"{w} tasks doing {N} writes took {stopwatch.Elapsed.TotalMilliseconds} milliseconds");
        }
Ejemplo n.º 4
0
        public void TestSummaryDecay()
        {
            var baseTime = new DateTime(2015, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            
            var sum = new Summary("test_summary", "helpless", new string[0], objectives: new List<QuantileEpsilonPair> {new QuantileEpsilonPair(0.1d, 0.001d)}, maxAge: TimeSpan.FromSeconds(100), ageBuckets: 10);
            var child = new Summary.Child();
            child.Init(sum, LabelValues.Empty, baseTime);
            
            Advanced.DataContracts.Summary m;
            var metric = new Metric();
            
            for (var i = 0; i < 1000; i++)
            {
                var now = baseTime.AddSeconds(i);
                child.Observe(i, now);
                
                if (i%10 == 0)
                {
                    child.Populate(metric, now);
                    m = metric.summary;
                    var got = m.quantile[0].value;
                    var want = Math.Max((double) i/10, (double) i - 90);

                    Assert.That(Math.Abs(got-want), Is.LessThanOrEqualTo(1), $"{i}. got {got} want {want}");
                }
            }

            // Wait for MaxAge without observations and make sure quantiles are NaN.
            child.Populate(metric, baseTime.AddSeconds(1000).AddSeconds(100));
            m = metric.summary;

            Assert.That(m.quantile[0].value, Is.NaN);
        }