public async Task TenK_WithTimerWheel()
        {
            TimerWheel  wheel  = TimerWheel.CreateTimerWheel(TimerWheelBenchmark.resolution, 20);
            List <Task> timers = new List <Task>(this.timeouts.Count);

            for (int i = 0; i < this.timeouts.Count; i++)
            {
                SimpleTimerWheel.TimerWheelTimer timer = wheel.CreateTimer(TimeSpan.FromMilliseconds(this.timeouts[i]));
                timers.Add(timer.StartTimerAsync());
            }

            await Task.WhenAll(timers);

            wheel.Dispose();
        }
示例#2
0
        public override void SubscribeForTimeouts(TimerWheelTimer timer)
        {
            this.ThrowIfDisposed();
            long timerTimeoutInTicks = timer.Timeout.Ticks;
            int  bucket = (int)timerTimeoutInTicks / this.resolutionInTicks;

            lock (this.subscriptionLock)
            {
                int index = this.GetIndexForTimeout(bucket);
                ConcurrentQueue <TimerWheelTimer> timerQueue = this.timers.GetOrAdd(index,
                                                                                    _ =>
                {
                    return(new ConcurrentQueue <TimerWheelTimer>());
                });
                timerQueue.Enqueue(timer);
            }
        }
示例#3
0
 public abstract void SubscribeForTimeouts(TimerWheelTimer timer);