tdb: workaround starvation problem in locking entire database.
commit5720be02c69109f1a6f5a16ecdeb2d79cc555498
authorRusty Russell <rusty@rustcorp.com.au>
Fri, 13 Aug 2010 16:43:26 +0000 (14 02:13 +0930)
committerJeremy Allison <jra@samba.org>
Fri, 13 Aug 2010 17:49:56 +0000 (13 10:49 -0700)
tree4d72428768ebabb7b88ad6fc27ea7a578c960e41
parentb7ecdd9a188c1b06d8244a926d3bd59d5fcfdc29
tdb: workaround starvation problem in locking entire database.

We saw tdb_lockall() take 71 seconds under heavy load; this is because Linux
(at least) doesn't prevent new small locks being obtained while we're waiting
for a big log.

The workaround is to do divide and conquer using non-blocking chainlocks: if
we get down to a single chain we block.  Using a simple test program where
children did "hold lock for 100ms, sleep for 1 second" the time to do
tdb_lockall() dropped signifiantly.  There are ln(hashsize) locks taken in
the contended case, but that's slow anyway.

More analysis is given in my blog at http://rusty.ozlabs.org/?p=120

This may also help transactions, though in that case it's the initial
read lock which uses this gradual locking routine; the update-to-write-lock
code is separate and still tries to update in one go.

Even though ABI doesn't change, minor version bumped so behavior change
can be easily detected.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
(cherry picked from commit 11ab43084b10cf53b530cdc3a6036c898b79ca38)
lib/tdb/ABI/tdb-1.2.3.sigs [new file with mode: 0644]
lib/tdb/common/lock.c
lib/tdb/configure.ac
lib/tdb/wscript