Default to using folly::LifoSem
authorMarc Celani <marccelani@fb.com>
Mon, 28 Apr 2014 17:09:16 +0000 (10:09 -0700)
committerDave Watson <davejwatson@fb.com>
Tue, 20 May 2014 19:53:56 +0000 (12:53 -0700)
commit9b5a1e4b0de245bdd2315f90a3ffd3888ee40ec2
treead98d53b46397e3af2115a845a6c5c9f7bf506f2
parent6205123a736c70d73e9878939a9af5c49f3832c5
Default to using folly::LifoSem

Summary:
Unless a service is overloaded, it should be able to clear
its queue frequently. When this happens, threads fall asleep until
more work is available in the queue. Waking up threads in LIFO
order gives us a lot of benefits. First, threads that were most
recently active are more likely to be mapped to the same cpu core
and thereby experience better L1 cache hit rate. Second, we can
madvise away jemalloc arenas on very idle threads. If we wake up
threads in FIFO order, we will never get a thread to remain idle
long enough for this to be worthwhile.

folly::LifoSem does just that. Benchmark in which the queue is
allowed to drain show that we get a substantial increase in
throughput by waking up threads in LIFO order.

Test Plan:
QueueBenchmark results summary:
As expected, benchmarks run faster in the case where the queue is
able to frequently drain itself, particularly in cases where the
number of threads is large. Benchmarks run slower when the
consumers cannot keep up with the producers, particularly when we
reach the queue capacity and we need to synchronize between
producers and consumers. However, in this case I think we care
less about the overhead of the queue itself and more about how
quickly we can shed the actual underlying load.

Reviewed By: davejwatson@fb.com

FB internal diff: D1298343
folly/IndexedMemPool.h
folly/LifoSem.h