public LeakyBucketLimitingService(int maxQPS, int limitSize)
 {
     LimitSize         = limitSize;
     MaxQPS            = maxQPS;
     limitedQueue      = new LimitedQueue <RequestObject>(limitSize);
     cancellationToken = new CancellationTokenSource();
     task = Task.Factory.StartNew(TokenProcess, cancellationToken.Token);
 }
Esempio n. 2
0
        private readonly object lockObject = new object();//用于加锁
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="maxQPS">最大QPS</param>
        /// <param name="limitSize">最大限制同时并发数</param>
        public TokenBucketLimitingService(int maxQPS, int limitSize)
        {
            MaxQPS    = maxQPS;
            LimitSize = limitSize;

            limitedQueue = new LimitedQueue <object>(limitSize);
            for (int i = 0; i < limitSize; i++)//先放满令牌
            {
                limitedQueue.Enqueue(new object());
            }
            cancellationToken = new CancellationTokenSource();
            task = Task.Factory.StartNew(new Action(TokenProcess), cancellationToken.Token);
        }