tcp: Implement random initial msgport
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Wed, 28 Aug 2013 07:11:43 +0000 (15:11 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Thu, 29 Aug 2013 05:22:54 +0000 (13:22 +0800)
commit1c92f416ac0f54e65f9410f71f4a4e4e0a3e72f3
treec9055ffc878cd313eab49369e5fca3276b6b267f
parentbefb03d795a212a2ccaeaba0b632ada0033b7adb
tcp: Implement random initial msgport

After e368a6e95e2cd9556a3e0fc43167d2dcf3a8253f, it is found that the
left bottle neck of nonblocking TCP connect(2) performance is that all
socket(2) and initial TCP connect operation (bind laddr and lport) are
all carried out in netisr0; CPU0 is 100% busy during test.

The idea of random initial msgport for TCP is that instead of using
netisr0's msgport as initial msgport, we could use any of the available
netisr msgport to carry out socket(2) and initial TCP connect operation.

Most of parts of TCP are already ready for random initial msgport, only
TCP pru_listen requires trivial modification to fix the socket msgport
to netisr0's msgport (which is required to perform global wild hashtable
updating).

As of this commit, the current CPU's netisr msgport will be selected as
TCP socket's initial msgport, if random initial msgport is enabled.

Sysctl node kern.ipc.rand_initport is added to disable this optimization.
It is enabled by default.

This commit improves both nonblocking TCP connect(2) and blocking TCP
connect(2) performance.

Nonblocking connect(2) performance measurement (i7-2600 w/ bnx(4)), using
tools/tools/netrate/accept_connect/kq_connect_client:

    kq_connect_client -4 SERVADDR -p SERVPORT -i 8 -c 32 -l 30
    (8 processes, each creates 32 connections simultaniously)

16 run average:
    random initial msgport          netisr0 msgport
      263915.17 conns/s            220979.89 conns/s

This commit gives ~19% performance improvement for nonblocking connect(2)

Blocking connect(2) performance measurement (i7-2600 w/ bnx(4)), using
tools/tools/netrate/accept_connect/connect_client:

    connect_client -4 SERVADDR -p SERVPORT -i 256 -l 30
    (256 processes)

16 run average:
    random initial msgport          netisr0 msgport
      240235.23 conns/s            198312.87 conns/s

This commit gives ~21% performance improvement for blocking connect(2)
sys/kern/uipc_msg.c
sys/kern/uipc_socket.c
sys/net/netmsg.h
sys/netinet/in_proto.c
sys/netinet/tcp_usrreq.c
sys/sys/protosw.h