Example of Linux SO_REUSEPORT
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
root Added example SO_REUSEPORT servers (Ruby and Python) Nov 7, 2015
README.md Note some connections may be lost when removing a process Nov 19, 2017


Linux port sharding demo

Demo showing how to use the SO_REUSEPORT linux socket option, allowing multiple processes to listen on the same TCP or UDP port.

Example available in Ruby and Python (both do the same thing):

What is this?


See my really quick Linux Port Sharding walkthrough first.


  • If you're on Linux with kernel 3.9 or later (check with uname -v), you can just run the Python or Ruby scripts directly.
  • If you're on Mac OSX, fret not, install Docker and run make, which will install a working Docker image and drop you into a ready to go tmux session, where you can call the scripts.


Run the server, it listens on port 1234. Connect to it with netcat or telnet to see it do something: nc localhost 1234.

Now run another server process, and a few more. You'll see the kernel allows these all to listen on the same port.

Connect to the port. You'll see the kernel picks one of the processes and allows it to handle it. Next time it may be another process.

You can add and remove processes. You can even run both the Python and Ruby processes at the same time and the kernel will share the workload. However, note that queued connections which have not been accepted will be lost when stopping a process.