예제 #1
0
        public void Time(Action action, string userValue = null)
        {
            var start = this.clock.Nanoseconds;

            try
            {
                counter.Increment();
                action();
            }
            finally
            {
                counter.Decrement();
                Record(this.clock.Nanoseconds - start, TimeUnit.Nanoseconds, userValue);
            }
        }
예제 #2
0
        private void Update(long value, long timestamp)
        {
            [email protected]();
            try
            {
                long   age      = timestamp - startTime.Value;
                double weighted = Math.Exp(alpha * age);
                double priority = weighted / ThreadLocalRandom.NextDouble();

                long newCount = count.Increment();
                if (newCount <= size)
                {
                    values.AddOrUpdate(priority, value, (k, v) => value);
                }
                else
                {
                    var first = values.First().Key;
                    if (first < priority)
                    {
                        this.values.AddOrUpdate(priority, value, (k, v) => v);

                        long removed;
                        // ensure we always remove an item
                        while (!values.TryRemove(first, out removed))
                        {
                            first = values.First().Key;
                        }
                    }
                }
            }
            finally
            {
                [email protected]();
            }
        }