简体   繁体   English

monotorrent-writeRate / readRate不起作用

[英]monotorrent - writeRate/readRate not working

i'm using monotorrent that downloads a 20GB~ file, when monotorrent creates the files the memory and CPU reaches maximum which slows the computer and even overheat it, so i wanted to limit the memory usage by limiting the write rate. 我正在使用下载20GB〜文件的monotorrent,当monotorrent创建文件时,内存和CPU达到最大值,这会减慢计算机甚至使其过热,因此我想通过限制写入速率来限制内存使用量。

here's what i have tried:- 这是我尝试过的:

, i checked around and found that you can limit read/write rate of the engine using this code:- ,我检查了一下,发现可以使用以下代码来限制引擎的读写速度:-

EngineSettings engineSettings = new EngineSettings(downloadsPath, port);
                engineSettings.PreferEncryption = true;
                engineSettings.AllowedEncryption = EncryptionTypes.All;
                engineSettings.MaxWriteRate = **maximum write rate in bytes**;
                engineSettings.MaxReadRate = **maximum read rate in bytes**;
                engineSettings.GlobalMaxDownloadSpeed = **max download in bytes**;

the download rate worked but it didn't limited the memory usage, so i checked the write rate value in runtime using this code 下载速率有效,但它没有限制内存使用,因此我使用此代码在运行时检查了写入速率值

 MessageBox.Show(engine.DiskManager.WriteRate.ToString());

and it returned 0 , so instead of adding MaxWriteRate to the EngineSettings i went into EngineSettings.cs and added a default value to MaxWriteRate by changing this code:- 和它返回0 ,这样反而增加MaxWriteRateEngineSettings我走进EngineSettings.cs并添加了默认值MaxWriteRate通过改变这样的代码: -

public int MaxWriteRate
        {
            get { return 5000; }
            set { maxWriteRate = 5000; }
        }

and it didn't limited the memory usage also the WriteRate value returned 0, so i went into DiskManager.cs and added a default value to WriteRate by changing this code:- 并且它不限制内存使用量, WriteRate值也返回0,因此我进入DiskManager.cs并通过更改此代码将默认值添加到WriteRate :-

public int WriteRate
        {
            get { return 5000; }
        }

now WriteRate value returned 5000 but it didn't limited the memory usage, then i stuck and didn't found anything else to change, 现在WriteRate值返回了5000,但它没有限制内存的使用,然后我卡住了,没有发现其他需要更改的地方,

does anyone know why it's not working? 有谁知道为什么它不起作用? i'm thinking that WriteRate is not even about limiting the writing speed. 我在想WriteRate甚至不是在限制写入速度。

When downloading a torrent, the download speed is limited by three things: 下载torrent时,下载速度受以下三点限制:

1) The maximum allowed download speed speed for the TorrentManager 2) The maximum allowed download speed overall 3) No more than 4MB of data is held in memory while waiting to be written to disk. 1)TorrentManager所允许的最大下载速度2)总体上所允许的最大下载速度3)等待写入磁盘时,内存中保存的数据不超过4MB。

Specifically on the third point, if there are more than 4MB of pieces held in memory then no further Socket.Receive calls will be made until that data is flushed. 特别是在第三点上,如果内存中保存的内存超过4MB,则将不再进行Socket.Receive调用,直到刷新数据为止。 https://github.com/mono/monotorrent/blob/caac16cffd95749febe04c3f7cf22567c3e40432/src/MonoTorrent/MonoTorrent.Client/RateLimiters/DiskWriterLimiter.cs#L43-L46 https://github.com/mono/monotorrent/blob/caac16cffd95749febe04c3f7cf22567c3e40432/src/MonoTorrent/MonoTorrent.Client/RateLimiters/DiskWriterLimiter.cs#L43-L46

This screenshot shows what happens today when you specify a max write rate of 2 * 1024 * 1024 (2,048 kB/sec): 此屏幕快照显示了当您将最大写入速率指定为2 * 1024 * 1024(2,048 kB / sec)时今天发生的情况: 在此处输入图片说明

The download rate auto-limits because the 4MB buffer fills up, which means setting the max disk write rate ends up limiting both download rate and memory consumption. 下载速度会自动限制,因为4MB缓冲区已满,这意味着设置最大磁盘写入速度最终会限制下载速度和内存消耗。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM