This is a simple program which is setup to serve as many Wakkas as possible.
If you run the client, you can tune the number of goroutine on the client to make it go faster. If you run out of open files, run ulimit -n
to find out your current number of openable files, and then double it with ulimit -n <n>
. Repeat this until you stop running out of files.
If you change the program so that the client closes the connection, you run out of sockets instead, because the sockets stick around in TIME_WAIT
state instead of being closed instantly. If you are at a loss for sockets, ensure your clients aren't closing the connection first.
The server spawns a goroutine for every connection it gets, writes "Wakka Wakka!" and closes the connection. Another goroutine prints how many people have gotten two Wakkas every two seconds, and finally, a 3rd goroutine prints the final count before exiting.
- Download Gist
go run server.go
go run client.go
ulimit -n 4196
go run client.go
The ulimit change is limited to your current terminal and will not bring down your system. Once you close that terminal it will go back to the original limit of (usually) 1024.