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: 64511+ Concurrent TCP sessions (address already in use) #6176
Labels
Comments
Comment 3 by paul@vanbrouwershaven.com: Here is a demo code that is running 60k concurrent connections with a timeout of 2 seconds. http://play.golang.org/p/mQZ2nlUQsr Please note that you need to increase your file descriptors as below and you a multicore system to properly run this code! sysctl -w fs.file-max=999999 ulimit -n `cat /proc/sys/fs/file-max` The code will print a status output like below every 5 seconds: 2013/08/19 10:51:33 GO: 60007 || TCP: ESTABLISHED 4 SYN_SENT 28232 || ERROR: dial tcp 10.2.149.179:80: address already in use /tmp/count.sh contains a count on current open tcp sessions: #!/bin/sh netstat -n | awk '/^tcp/ {t[$NF]++}END{for(state in t){print state, t[state]} }' |
Comment 4 by paul@vanbrouwershaven.com: Here is a demo code that is running 60k concurrent connections with a timeout of 2 seconds. http://play.golang.org/p/mQZ2nlUQsr Please note that you need to increase your file descriptors as below and a multicore system to properly run this code! sysctl -w fs.file-max=999999 ulimit -n `cat /proc/sys/fs/file-max` The code will print a status output like below every 5 seconds: 2013/08/19 10:51:33 GO: 60007 || TCP: ESTABLISHED 4 SYN_SENT 28232 || ERROR: dial tcp 10.2.149.179:80: address already in use /tmp/count.sh contains a count on current open tcp sessions: #!/bin/sh netstat -n | awk '/^tcp/ {t[$NF]++}END{for(state in t){print state, t[state]} }' |
Comment 6 by paul@vanbrouwershaven.com: This problem is kernel related. By specifying the ports in LocalAddr you can indeed bypass the kernel problem. The actual problem in my code was 'solved' by removing a go channel that was counting the number of cross routine completed connections, unfortunately connections where completing faster than the channel could process them. Increasing the channel buffer was only delaying the problem. While you still have to take care of the "address already in use" error as it will happen sometime when you select a port that is used by a tcp session outside the go program. With the code from the first post in this issue you can make millions of concurrent tcp connections with golang. |
Instead of picking source addresses in the app, you should be able to configure your routing to pick from multiple source addresses. On linux, iproute2's "ip ro add ... src ..." and "equalize" options should prove useful, or go for policy routing if you must. It'll still pick a source address first, and then try to find a free port, so the balancing is stochastic at best. But this seems better to me than putting all this logic in the app. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by paul@vanbrouwershaven.com:
The text was updated successfully, but these errors were encountered: