[PATCH] SO_REUSEPORT support for listen sockets

Sepherosa Ziehau sepherosa at gmail.com
Fri Jul 26 08:07:58 UTC 2013

Hi all,

I have the following preliminary patch to enable SO_REUSEPORT feature
on listen sockets:

The basic idea of the above patch is:
- Defer the listen socket creation until work processes are forked
- Work process creates listen socket, and set SO_REUSEPORT before bind(2)
- Accept mutex is no longer needed, since worker process is not
contended on the single listen socket anymore

The SO_REUSEPORT sockopt on Linux:

The SO_REUSEPORT sockopt on DragonFlyBSD:

The non-blocking accept(2) w/ SO_REUSEPORT performance improvement on

The preliminary httperf test shows w/ "so_reuseport on" gives me ~33%
req/s performance improvement on DragonFlyBSD:

httperf is running as:
httperf --server=$server_name --wsess=5000,1,1 --max-conn=4

Same testing machines and network configuration as in:

Each client runs 16 above httperf test, except the box w/ bce, which
runs 8 above httperf.

The nginx w/ "so_reuseport on" is doing 49852 reqs/s (4 run avg) and
there are 35%~40% idle time on each hyperthread.
The nginx w/o "so_reuseport on" is doing 37386 reqs/s (4 run avg).

Any feedbacks are welcome.

Best Regards,

Tomorrow Will Never Die

More information about the nginx-devel mailing list