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