public async Task SendData_RateLimited() { // Allow 1 megabyte worth of data var oneMegabyte = 1 * 1024 * 1024; var limiter = new RateLimiter(); limiter.UpdateChunks(oneMegabyte, oneMegabyte); await NetworkIO.SendAsync(Incoming, new byte[oneMegabyte], 0, oneMegabyte, limiter, null, null); var expectedChunks = (int)Math.Ceiling(oneMegabyte / (double)NetworkIO.ChunkLength); Assert.AreEqual(expectedChunks, Incoming.Sends.Count, "#1"); }
public async Task SendData_RateLimited() { // Allow 1 megabyte worth of data var oneMegabyte = 1 * 1024 * 1024; var limiter = new RateLimiter(); limiter.UpdateChunks(oneMegabyte, oneMegabyte, NetworkIO.ChunkLength); using var releaser = MemoryPool.Default.Rent(oneMegabyte, out Memory <byte> buffer); await NetworkIO.SendAsync(Incoming, buffer, limiter, null, null); var expectedChunks = (int)Math.Ceiling(oneMegabyte / (double)NetworkIO.ChunkLength); Assert.AreEqual(expectedChunks, Incoming.Sends.Count, "#1"); }
void CreateRateLimiters() { RateLimiter downloader = new RateLimiter(); downloadLimiter = new RateLimiterGroup(); downloadLimiter.Add(new DiskWriterLimiter(DiskManager)); downloadLimiter.Add(downloader); RateLimiter uploader = new RateLimiter(); uploadLimiter = new RateLimiterGroup(); uploadLimiter.Add(uploader); MainLoop.QueueTimeout(TimeSpan.FromSeconds(1), delegate { downloader.UpdateChunks(Settings.GlobalMaxDownloadSpeed, TotalDownloadSpeed); uploader.UpdateChunks(Settings.GlobalMaxUploadSpeed, TotalUploadSpeed); return(!Disposed); }); }
public async Task ReceiveData_RateLimited() { // Allow 1 megabyte worth of data var oneMegabyte = 1 * 1024 * 1024; var limiter = new RateLimiter(); limiter.UpdateChunks(oneMegabyte, oneMegabyte); using var r1 = SocketMemoryPool.Default.Rent(oneMegabyte, out var sendBuffer); using var r2 = SocketMemoryPool.Default.Rent(oneMegabyte, out var receiveBuffer); await Outgoing.SendAsync(sendBuffer); await NetworkIO.ReceiveAsync(Incoming, receiveBuffer, limiter, null, null); var expectedChunks = (int)Math.Ceiling(oneMegabyte / (double)NetworkIO.ChunkLength); Assert.AreEqual(expectedChunks, Incoming.Receives.Count, "#1"); }
void LogicTick() { tickCount++; if (tickCount % 2 == 0) { downloadLimiter.UpdateChunks(Settings.MaximumDownloadSpeed, TotalDownloadSpeed); uploadLimiter.UpdateChunks(Settings.MaximumUploadSpeed, TotalUploadSpeed); } ConnectionManager.CancelPendingConnects(); ConnectionManager.TryConnect(); DiskManager.Tick(); for (int i = 0; i < allTorrents.Count; i++) { allTorrents[i].Mode.Tick(tickCount); } RaiseStatsUpdate(new StatsUpdateEventArgs()); }
internal DiskManager(ClientEngine engine, PieceWriter writer) { this.bufferedReads = new Queue <BufferedIO>(); this.bufferedWrites = new Queue <BufferedIO>(); this.engine = engine; this.ReadLimiter = new RateLimiter(); this.readMonitor = new SpeedMonitor(); this.writeMonitor = new SpeedMonitor(); this.WriteLimiter = new RateLimiter(); this.Writer = writer; IOLoop.QueueTimeout(TimeSpan.FromSeconds(1), () => { readMonitor.Tick(); writeMonitor.Tick(); WriteLimiter.UpdateChunks(engine.Settings.MaxWriteRate, WriteRate); ReadLimiter.UpdateChunks(engine.Settings.MaxReadRate, ReadRate); ProcessBufferedIO(); return(!Disposed); }); }
void CreateRateLimiters() { RateLimiter downloader = new RateLimiter(); downloadLimiter = new RateLimiterGroup(); downloadLimiter.Add(new DiskWriterLimiter(DiskManager)); downloadLimiter.Add(downloader); RateLimiter uploader = new RateLimiter(); uploadLimiter = new RateLimiterGroup(); downloadLimiter.Add(new DiskWriterLimiter(DiskManager)); uploadLimiter.Add(uploader); ClientEngine.MainLoop.QueueTimeout(TimeSpan.FromSeconds(1), delegate { downloader.UpdateChunks(Settings.GlobalMaxDownloadSpeed, TotalDownloadSpeed); uploader.UpdateChunks(Settings.GlobalMaxUploadSpeed, TotalUploadSpeed); return !disposed; }); }