简体   繁体   中英

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.

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:-

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:-

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,

does anyone know why it's not working? i'm thinking that WriteRate is not even about limiting the writing speed.

When downloading a torrent, the download speed is limited by three things:

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.

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. 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): 在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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