-
Notifications
You must be signed in to change notification settings - Fork 17.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
Timer related go routine schedule problems under high concurrency #40786
Comments
Time = ~10ms + time for SendResponse You should measure it like ...
|
Yeah, you are right, but this is async call, the effect should be very small. And the client also find this timeout issue.-------- 原始邮件 --------发件人: Chotepud Teo <[email protected]>日期: 2020年8月14日周五 傍晚6:12收件人: golang/go <[email protected]>抄送: Li wen <[email protected]>, Author <[email protected]>主 题: Re: [golang/go] Timer related go routine schedule problems under high concurrency (#40786)
func RecieveRequest(req Request) {
// tic here
done := Process(req) // done is a channel to get the response to send, process usually will be done in 6 ms
select {
case result := <-done:
SendResponse(result)
case <-time.After(time.Duration(10 * time.Millisecond):
SendResponse(ServerTimeOut) // ServerTimeOut is a predefined response
}
// toc here
}
Time = ~10ms + time for SendResponse
You should measure it like ...
func RecieveRequest(req Request) {
// tic here
done := Process(req) // done is a channel to get the response to send, process usually will be done in 6 ms
select {
case result := <-done:
SendResponse(result)
case <-time.After(time.Duration(10 * time.Millisecond):
// toc here
SendResponse(ServerTimeOut) // ServerTimeOut is a predefined response
}
}
—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe.
|
The only way to be sure it's the timer and not |
Thanks, I will do further test.-------- 原始邮件 --------发件人: Chotepud Teo <[email protected]>日期: 2020年8月14日周五 晚上7:08收件人: golang/go <[email protected]>抄送: Li wen <[email protected]>, Author <[email protected]>主 题: Re: [golang/go] Timer related go routine schedule problems under high concurrency (#40786)
The only way to be sure it's the timer and not SendResponse that's taking longer than expected is to time it as such.
—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe.
|
@AlexRouSg Hello, thanks for your adivice, I have done the test exactly after the timer is fired. I have edited the description. and the result is same. |
Yes, this looks like a dup of #38860. Closing as a dup, but please comment if you disagree. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Latest is 1.15, so I think the answer should be No
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I write a server to handle requests from clients. I hope for each connection the server should process it in a limited time, for example 10ms, which means no matter has the server done the work or not, it should give a respones to the client when the time reachs 10ms. Pseudo-codes are here:
What did you expect to see?
I use tic-toc to messure the actual time interval, the actual time interval should be within 10ms, or a little bit more than 10ms.
What did you see instead?
under low concurrency, most request is processed normally, but there are still very few(under 0.01%) requests' actual process intervals are like 15ms.
under high concurrency, situation worsened. There are more(above 0.1%) actual intervals are larger than 10ms, and the worst case could reach 50~500 ms, which will cause the client timeout.
I think timers should be correct since there is nothing like tight-loop in the codes, during ervery schedule event the processor would check the timer heap to fire those should be fired. Then the problem seems to be the scheduler itself, the scheduler seems not be able to schedule the timer related goroutines to run immediately. But this is just my guess, I'm not sure.
So is this phenomenon normal? Or I did something wrong?
If my guess is correct, should the timer related routines be pushed on the front of the queue?
Hope someone could help, thanks.
The text was updated successfully, but these errors were encountered: