Inheritance: IRateLimiter
Ejemplo n.º 1
0
        private short roundsChoked, roundsUnchoked;     // for stats measurement

        private void InitializeTyrant()
        {
            this.haveMessagesReceived = 0;
            this.startTime            = Stopwatch.GetTimestamp();

            this.rateLimiter              = new RateLimiter();
            this.uploadRateForRecip       = MARKET_RATE;
            this.lastRateReductionTime    = DateTime.Now;
            this.lastMeasuredDownloadRate = 0;

            this.maxObservedDownloadSpeed = 0;
            this.roundsChoked             = 0;
            this.roundsUnchoked           = 0;
        }
Ejemplo n.º 2
0
        void CreateRateLimiters()
        {
            RateLimiter downloader = new RateLimiter();

            _downloadLimiter = new RateLimiterGroup();
            _downloadLimiter.Add(new PauseLimiter(this));
            _downloadLimiter.Add(downloader);

            RateLimiter uploader = new RateLimiter();

            _uploadLimiter = new RateLimiterGroup();
            _uploadLimiter.Add(new PauseLimiter(this));
            _uploadLimiter.Add(uploader);
        }
Ejemplo n.º 3
0
        private void CreateRateLimiters()
        {
            var downloader = new RateLimiter();

            downloadLimiter = new RateLimiterGroup();
            downloadLimiter.Add(new DiskWriterLimiter(DiskManager));
            downloadLimiter.Add(downloader);

            var uploader = new RateLimiter();

            uploadLimiter = new RateLimiterGroup();
            downloadLimiter.Add(new DiskWriterLimiter(DiskManager));
            uploadLimiter.Add(uploader);

            MainLoop.QueueTimeout(TimeSpan.FromSeconds(1), () =>
            {
                downloader.UpdateChunks(
                    Settings.GlobalMaxDownloadSpeed,
                    TotalDownloadSpeed);
                uploader.UpdateChunks(Settings.GlobalMaxUploadSpeed,
                                      TotalUploadSpeed);
                return(!disposed);
            });
        }
Ejemplo n.º 4
0
        internal DiskManager(ClientEngine engine, PieceWriter writer)
        {
            _bufferedReads  = new Queue <BufferedIO>();
            _bufferedWrites = new Queue <BufferedIO>();
            _cache          = new Cache <BufferedIO>(true).Synchronize();
            _engine         = engine;
            ReadLimiter     = new RateLimiter();
            _readMonitor    = new SpeedMonitor();
            _writeMonitor   = new SpeedMonitor();
            WriteLimiter    = new RateLimiter();
            _writer         = writer;

            _loopTask = delegate {
                if (_disposed)
                {
                    return;
                }

                while (_bufferedWrites.Count > 0 && WriteLimiter.TryProcess(_bufferedWrites.Peek().buffer.Length / 2048))
                {
                    BufferedIO write;
                    lock (_bufferLock)
                        write = _bufferedWrites.Dequeue();
                    try
                    {
                        PerformWrite(write);
                        _cache.Enqueue(write);
                    }
                    catch (Exception ex)
                    {
                        if (write.Manager != null)
                        {
                            SetError(write.Manager, Reason.WriteFailure, ex);
                        }
                    }
                }

                while (_bufferedReads.Count > 0 && ReadLimiter.TryProcess(_bufferedReads.Peek().Count / 2048))
                {
                    BufferedIO read;
                    lock (_bufferLock)
                        read = _bufferedReads.Dequeue();

                    try
                    {
                        PerformRead(read);
                        _cache.Enqueue(read);
                    }
                    catch (Exception ex)
                    {
                        if (read.Manager != null)
                        {
                            SetError(read.Manager, Reason.ReadFailure, ex);
                        }
                    }
                }
            };

            IOLoop.QueueTimeout(TimeSpan.FromSeconds(1), () =>
            {
                if (_disposed)
                {
                    return(false);
                }

                _readMonitor.Tick();
                _writeMonitor.Tick();
                _loopTask();
                return(true);
            });
        }
Ejemplo n.º 5
0
        private void CreateRateLimiters()
        {
            var downloader = new RateLimiter();
            downloadLimiter = new RateLimiterGroup();
            downloadLimiter.Add(new DiskWriterLimiter(DiskManager));
            downloadLimiter.Add(downloader);

            var uploader = new RateLimiter();
            uploadLimiter = new RateLimiterGroup();
            downloadLimiter.Add(new DiskWriterLimiter(DiskManager));
            uploadLimiter.Add(uploader);

            MainLoop.QueueTimeout(TimeSpan.FromSeconds(1), () =>
                                                               {
                                                                   downloader.UpdateChunks(
                                                                       Settings.GlobalMaxDownloadSpeed,
                                                                       TotalDownloadSpeed);
                                                                   uploader.UpdateChunks(Settings.GlobalMaxUploadSpeed,
                                                                                         TotalUploadSpeed);
                                                                   return !disposed;
                                                               });
        }
Ejemplo n.º 6
0
        internal DiskManager(ClientEngine engine, PieceWriter writer)
        {
            _bufferedReads = new Queue<BufferedIO>();
            _bufferedWrites = new Queue<BufferedIO>();
            _cache = new Cache<BufferedIO>(true).Synchronize();
            _engine = engine;
            ReadLimiter = new RateLimiter();
            _readMonitor = new SpeedMonitor();
            _writeMonitor = new SpeedMonitor();
            WriteLimiter = new RateLimiter();
            _writer = writer;

            _loopTask = delegate {
                if (_disposed)
                    return;

                while (_bufferedWrites.Count > 0 && WriteLimiter.TryProcess(_bufferedWrites.Peek ().buffer.Length / 2048))
                {
                    BufferedIO write;
                    lock (_bufferLock)
                        write = _bufferedWrites.Dequeue();
                    try
                    {
                        PerformWrite(write);
                        _cache.Enqueue (write);
                    }
                    catch (Exception ex)
                    {
                        if (write.Manager != null)
                            SetError(write.Manager, Reason.WriteFailure, ex);
                    }
                }

                while (_bufferedReads.Count > 0 && ReadLimiter.TryProcess(_bufferedReads.Peek().Count / 2048))
                {
                    BufferedIO read;
                    lock (_bufferLock)
                        read = _bufferedReads.Dequeue();

                    try
                    {
                        PerformRead(read);
                        _cache.Enqueue(read);
                    }
                    catch (Exception ex)
                    {
                        if (read.Manager != null)
                            SetError(read.Manager, Reason.ReadFailure, ex);
                    }
                }
            };

            IOLoop.QueueTimeout(TimeSpan.FromSeconds(1), () =>
                                                             {
                                                                 if (_disposed)
                                                                     return false;

                                                                 _readMonitor.Tick();
                                                                 _writeMonitor.Tick();
                                                                 _loopTask();
                                                                 return true;
                                                             });
        }
Ejemplo n.º 7
0
        private void InitializeTyrant()
        {
            this.haveMessagesReceived = 0;
            this.startTime = Stopwatch.GetTimestamp();

            this.rateLimiter = new RateLimiter();
            this.uploadRateForRecip = MARKET_RATE;
            this.lastRateReductionTime = DateTime.Now;
            this.lastMeasuredDownloadRate = 0;

            this.maxObservedDownloadSpeed = 0;
            this.roundsChoked = 0;
            this.roundsUnchoked = 0;
        }