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
runtime: network read using a lot of CPU #52341
Comments
That would force us to use
Unix kernels do not support this kind of operation, and of course we couldn't use it in general as the I'm not sure how to interpret your profile. You didn't show us the complete program. It's normal for a program that doesn't do anything other than read from the network to spend most of its time reading from the network; what else might it be doing? You also didn't tell us what kind of network traffic it is handling. It's not clear to me that there is anything we can do here, though I would be happy to hear specific tested suggestions. The Go networking code is optimized for handling many different network connections simultaneously. That does mean that it is not optimized for handling a single network connection; that case works fine but it does use more CPU time than is strictly required. |
Hey thanks for replying! You are right my application is not handling high number of connections. In most cases there would be at most 5 - 6 connections. And the connections are usually very busy, serving more than 5K QPS traffic per connection. And the network is in TCP. I understand |
I don't know of a way to do that. |
Got it. Do you think it makes sense to do some event based implementations, using |
Yes, since the Go runtime already uses |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes. This issue is more of a feature request than a bug fix.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
My code is running a tcp server and read from connection in a for loop
The problem is the syscall.read is 50% of the total CPU, see the profiling below

Looking at https://github.com/golang/go/blob/master/src/internal/poll/fd_unix.go#L163-L167
My theory is that on line 163 it calls syscall.read to read the socket, and syscall.read returns error when there is nothing to read. Then on line 167 it calls fd.pd.waitRead() to wait for data. And when data arrives at the connection, the fd is notified and continue to read. I'm seeing two problems here,
The text was updated successfully, but these errors were encountered: