-
Notifications
You must be signed in to change notification settings - Fork 165
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
opt: downloader #1019
Merged
Merged
opt: downloader #1019
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Eric-Joker
force-pushed
the
better-limiter
branch
from
August 5, 2024 12:14
951b7db
to
fa6f26a
Compare
Eric-Joker
force-pushed
the
better-limiter
branch
from
August 5, 2024 12:45
a317b09
to
ada8190
Compare
@Scighost 打扰,但这个有时间看看可以merge了?( |
Eric-Joker
force-pushed
the
better-limiter
branch
from
August 7, 2024 03:26
ada8190
to
ed5821c
Compare
可以试试这个 internal static class TokenBucketRateLimiterExtension
{
public static int Acquire(this TokenBucketRateLimiter rateLimiter, int permits, out TimeSpan retryAfter)
{
int count = Math.Min(permits, (int)Volatile.Read(ref PrivateGetTokenCount(rateLimiter)));
return rateLimiter.AttemptAcquire(count).TryGetMetadata(MetadataName.RetryAfter, out retryAfter) ? 0 : count;
}
// private double _tokenCount;
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "_tokenCount")]
private static extern ref double PrivateGetTokenCount(TokenBucketRateLimiter rateLimiter);
} |
Eric-Joker
force-pushed
the
better-limiter
branch
3 times, most recently
from
August 7, 2024 08:52
e2c3552
to
af1414f
Compare
谢谢,好用,用了( |
Eric-Joker
force-pushed
the
better-limiter
branch
from
August 7, 2024 09:00
af1414f
to
e6fda22
Compare
@Eric-Joker 我最终实际体验了一下还是改成了下面的样子 |
emm?没太明白,现在的实现就是根据ReadAsync返回的值来租用令牌的 |
Eric-Joker
force-pushed
the
better-limiter
branch
from
August 8, 2024 04:20
e6fda22
to
4c2f2a0
Compare
我的实现是尝试获取buffer长度的令牌,然后再读的,由于读取的长度可能会比buffer小所以我加了返还 |
Eric-Joker
force-pushed
the
better-limiter
branch
from
August 8, 2024 05:50
26ff097
to
6e45321
Compare
Co-authored-by: DismissedLight <[email protected]>
Eric-Joker
force-pushed
the
better-limiter
branch
from
August 8, 2024 06:10
6e45321
to
05208d3
Compare
其实我突然发现,都已经lock了,理论上是不需要Volatile.Read的 |
谢谢你的贡献 |
1 task
Eric-Joker
added a commit
to Eric-Joker/Starward
that referenced
this pull request
Sep 27, 2024
* refactor: download limiter * opt: Decrease the time interval for replenishing tokens * fix: crash by NumberBox possibly being -21e * Improve more precise speed limits Co-authored-by: DismissedLight <[email protected]> * opt: reduce downloader writes * refactor: simplify rate limiting --------- Co-authored-by: DismissedLight <[email protected]> Co-authored-by: Scighost <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#1003 反复重做,重开个pr。
与当前限速器的区别:
close #996 , close #997