Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# monotorrent-写入/读取速率不工作_C#_Winforms_Monotorrent - Fatal编程技术网

C# monotorrent-写入/读取速率不工作

C# monotorrent-写入/读取速率不工作,c#,winforms,monotorrent,C#,Winforms,Monotorrent,我正在使用monotorrent下载一个20GB的文件,当monotorrent创建文件时,内存和CPU达到最大值,这会降低计算机速度,甚至使计算机过热,因此我想通过限制写入速率来限制内存使用 以下是我尝试过的内容:- ,我四处查看,发现您可以使用以下代码限制引擎的读/写速率:- EngineSettings engineSettings = new EngineSettings(downloadsPath, port); engineSettings.Prefe

我正在使用monotorrent下载一个20GB的文件,当monotorrent创建文件时,内存和CPU达到最大值,这会降低计算机速度,甚至使计算机过热,因此我想通过限制写入速率来限制内存使用

以下是我尝试过的内容:-

,我四处查看,发现您可以使用以下代码限制引擎的读/写速率:-

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**;
public int MaxWriteRate
        {
            get { return 5000; }
            set { maxWriteRate = 5000; }
        }
public int WriteRate
        {
            get { return 5000; }
        }
下载速率起作用了,但它并没有限制内存使用,所以我使用这段代码在运行时检查了写速率值

 MessageBox.Show(engine.DiskManager.WriteRate.ToString());
它返回了
0
,因此我没有将
MaxWriteRate
添加到
enginesetings
中,而是进入
enginesetings.cs
并通过更改此代码将默认值添加到
MaxWriteRate
:-

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**;
public int MaxWriteRate
        {
            get { return 5000; }
            set { maxWriteRate = 5000; }
        }
public int WriteRate
        {
            get { return 5000; }
        }
而且它没有限制内存使用,
WriteRate
值返回0,因此我进入
DiskManager.cs
并通过更改此代码为
WriteRate添加了一个默认值:-

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**;
public int MaxWriteRate
        {
            get { return 5000; }
            set { maxWriteRate = 5000; }
        }
public int WriteRate
        {
            get { return 5000; }
        }
现在
WriteRate
值返回5000,但它没有限制内存使用,然后我卡住了,没有发现任何其他要更改的内容


有人知道它为什么不起作用吗?我认为
WriteRate
甚至不是限制写入速度。

下载torrent时,下载速度受到三个方面的限制:

1) TorrentManager允许的最大下载速度 2) 总体允许的最大下载速度 3) 在等待写入磁盘时,内存中保存的数据不超过4MB

特别是在第三点上,如果内存中保存的数据超过4MB,则在刷新该数据之前,不会再发出Socket.Receive调用

此屏幕截图显示了当您指定最大写入速率为2*1024*1024(2048 kB/秒)时今天发生的情况:

下载速率自动限制,因为4MB缓冲区已满,这意味着设置最大磁盘写入速率最终会限制下载速率和内存消耗