-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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
net/http, x/net/netutil: Cannot Set TCP Connection Limitation for Go HTTP Server #36212
Comments
In what state? Only open sockets are limited by anything inside the app. |
As far as I understand, your code makes it so that more than 20 connections can be accepted simultaneously. However, after some connections are accepted, more connections can be accepted, so Do you think there's a bug somewhere, or is this a feature request? |
Hi @tv42
All status of these 100 sockets are ESTABLISHED.
|
@dmitshur Thanks for your explanation. I think I need a feature that only 20 connections can be accepted simultaneously. |
There are several reasons why you see a large connections number. First, netstat shows structures for both inbound and outbound connections. For example, for two connections you will see:
One structure for the server, one for the client. Secondly, netstat shows structures for connections in other states, for example TIME_WAIT:
In this case, we see only one living connection, but there are 5 rows. Thirdly, there is a difference between the This difference will be visible if you look at the number of open file descriptors for the application. Set the limit to 1 and send two requests simultaneously (yes, you need to set time.Sleep in the handler so that it does not end immediately): We look at the number of connections, one for the listening socket, two for incoming connections:
But we see only one file descriptor associated with the connection on port 62086.
Only when the first connection finish, the application will make another accept call and process the second connection on port 62010:
With LimitListener you can adjust the number of file descriptors for the server, but you cannot adjust the number of ESTABLISHED connections for the system. We can say that the system queues incoming connections and they are waiting for their To summarize, let’s say:
P.S. https://stackoverflow.com/questions/10002868/what-value-of-backlog-should-i-use |
@rokkerruslan thank you very very much. I got it. I can set the Anyway, thanks again for your help. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I have a piece of code to implement a simple HTTP server with golang.
Using wrk to test the connection limitation.
./wrk -t4 -c100 -d30s 'http://127.0.0.1:8000/hello'
What did you expect to see?
The number of established tcp connection should be limited to 20
What did you see instead?
netstat -an | grep 8000 | wc -l
The output is 102. It looks like the LimitListener does not make server reject the new incoming TCP connections when connection number is more than 20.
The text was updated successfully, but these errors were encountered: