-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Make several optimizations to worker pool #680
Conversation
@erikdubbelboer @kirillDanshin |
Thank you for the pull request. Interesting idea but can you show some benchmark results that this code is actually worth it? I have this feeling this will barely be any faster as there usually won't be many entries in |
I don't think so, in your case, http servers should be receiving high-traffic and continual http requests, which keeps workers active. Yet I believe there are more general scenarios that http servers get idle times frequently and it leads to many workers in Besides, binary-search ensures its time cost will be reduced from N to log2(N) on the average, I think we ought to give consideration to various scenarios as fasthttp is a framework, right? |
Can you show a small benchmark that for example shows that the binary search is faster than just the linear search for a slice of 10,100,1000,10000 entries for example. And then for each of those sizes have variations where |
Hi @erikdubbelboer
Benchmark code has been committed to this PR, please check it out, thanks~ |
|
@erikdubbelboer |
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.
Thanks! Those are exactly the benchmarks I wanted to see. It's much faster than I expected to be honest. We should definitely merge this change.
But I'm sorry, I meant I just want to see the benchmarks to make sure this would actually be a big improvement. Actually committing them in the code seems a bit overkill. Especially since you're not really benchmarking the function itself so any future changes won't affect the benchmarks and won't help us find issues.
Can you please remove the benchmarks, then I can merge the pull request. Thanks!
@erikdubbelboer |
Thanks! |
ready
that stores workers is sequential, the process of cleaning up expired workers can be speeded up by means of the binary-search algorithm;workerChan
, avoiding copy fromrange
;sync.Pool
as a more canonical way.Signed-off-by: Andy Pan panjf2000@gmail.com