Golang Performance Tips
Below is some advice and notes that I wish I had when writing Go to deal with high amounts of requests (20k+/second). Have any extra tips? Leave them in the comments!
Kernel Tuning Step 1 is making sure your host OS isn’t going to keel over when you start making thousands of requests/second or hammering the CPU.
Update /etc/sysctl.conf to have these lines:
1net.ipv4.tcp_tw_reuse = 1 2net.ipv4.tcp_tw_recycle = 1 3net.ipv4.ip_local_port_range = 50000 ip_local_port_range - at the default of 30,000 and not modifying the tw_reuse and tw_recycle properties, we’re effectively limited to 500 connections/second to a server. If this is still not enough you can configure additional IP’s on the server and cycle between them.
Josh Rendek