-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
下载限速 #492
下载限速 #492
Conversation
(抱歉,我已经很努力忍住不笑了(doge)) |
@@ -733,6 +733,7 @@ private async Task<List<DownloadTask>> GetPkgVersionsAsync(string url) | |||
public async Task DownloadAsync(CancellationToken cancellationToken) | |||
{ | |||
const int bufferSize = 1 << 16; | |||
int speed = AppConfig.DowlondSpeed * 500; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
数字 500 含义不明
{ | ||
double tempData = ((speedPer - speed) < 1) ? 1 : speedPer - speed; | ||
int sleepMS = Convert.ToInt32(tempData * (1000 / speed) + 100); | ||
Thread.Sleep((sleepMS > 1000) ? 1000 : sleepMS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使用 Thread.Sleep
会阻塞当前线程
Thread.Sleep((sleepMS > 1000) ? 1000 : sleepMS); | ||
} | ||
} | ||
} | ||
await fs.WriteAsync(buffer.AsMemory(0, length), token).ConfigureAwait(false); | ||
Interlocked.Add(ref progressBytes, length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
因为这部分没有移动到 if (AppConfig.DowlondSpeed != 100)
的 else 分支中,实际下载速度大约是计算值的两倍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你的方法中 DownloadSpeed
参数仅限制了单线程的下载速度,多线程的下载速度总值会远远超过设定值。
首先感谢你愿意帮助 Starward 解决一些需要优化的痛点,并且做出了代码贡献。但是因为以上原因我不能接受你的 PR 请求。 |
很抱歉之前没看到消息,写的很烂 1. 使用 Thread.Sleep 会阻塞当前线程
2. 没有放到if (AppConfig.DowlondSpeed != 100) 的 else 分支中
3. 多线程
这个方法是判断每一个下载分段与由设置的下载速度计算出的预期分段时间进行比较, |
添加下载限速功能
UI没写还有当 DowlondSpeed = 100 时是无限制 单位是Mb/s