nbd: Rewrite thread passing to use semaphore rather than pipe
commite897ed70f2242252f5785a1c5463cba98a7f6c9b
authorEric Blake <eblake@redhat.com>
Sat, 25 May 2019 16:53:22 +0000 (25 11:53 -0500)
committerEric Blake <eblake@redhat.com>
Sat, 25 May 2019 18:09:32 +0000 (25 13:09 -0500)
tree66140edb0043dfd23f9268e123227b383efa596c
parent8c64ad342f4edd4d8e46abc77d7c2cfac084ff97
nbd: Rewrite thread passing to use semaphore rather than pipe

I ran some local testing on my Fedora 29 system via:
$ ./nbdkit memory 1m
$ for i in `seq 10`; do
    ./nbdkit -U - --filter=stats nbd \
      statsappend=true statsfile=$file hostname=localhost port=10809 \
      --run '~/libnbd/examples/threaded-reads-and-writes $unixsocket'
  done

Pre-patch, the runs averaged  1.266s, 1.30E+08 bits/s
Post-patch, the runs averaged 1.154s, 1.42E+08 bits/s

This is roughly 9% performance gain, all because semaphores are
lighter weight than pipes for inter-thread locking.  The refactoring
will also make it a bit easier to incorporate the use of libnbd.

Signed-off-by: Eric Blake <eblake@redhat.com>
plugins/nbd/nbd.c