Skip to content
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

限速接口调用不生效,限速之后网速一直小于100Kb/s #951

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

SweetSalts
Copy link

@SweetSalts SweetSalts commented Jan 19, 2022

限速失败问题
背景
下载时发现调用限速接口时,限速不准确,接口无法调用。
在设置限速之后还会出现下载速度总是处于100Kb以下的情况。
https://github.com/AriaLyy/Aria/issues/884

问题复现
通过打log定位问题,最终发现是线程睡眠时间不准确导致的。

指定的睡眠时间是0.973489ms,但是实际上睡了41.95401ms。
限速就是通过控制线程睡眠时间来达到控制接收传输字节流速度的,如果sleep睡眠时间与指定的不一致就会出现限速不准确,会有10~40ms的差异。
同时,一旦进行了限速就会一直触发这个问题,所以才会有背景中提到的,一旦设置限速之后网速一直小于100Kb/s。

问题分析
Android系统中,后台线程调用sleep之后由于优先级较低,不能及时抢占cpu资源,所以会导致睡眠时间与指定的时间不符。

进一步验证:
编写demo验证

当应用处于前台时:睡眠时间基本准确。

当应用退到后台,也会出现睡眠时间不准确的现象。

问题解决
线程的优先级受到应用生命周期的影响,当应用退到后台对应的线程游戏级会降低。
同时,还可以显式设置线程的优先级来保证功能的正常。

下载的优先级从后台调整为默认之后,限速功能正常。

@SweetSalts
Copy link
Author

请帮忙修复该问题,谢谢~

@stale
Copy link

stale bot commented Jan 27, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jan 27, 2022
@stale stale bot removed the wontfix label Mar 5, 2024
Copy link

stale bot commented Mar 17, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant