Add MemoryIdler suppot to IOThreadPoolExecutor
authorDave Watson <davejwatson@fb.com>
Mon, 27 Oct 2014 17:11:03 +0000 (10:11 -0700)
committerdcsommer <dcsommer@fb.com>
Wed, 29 Oct 2014 23:06:51 +0000 (16:06 -0700)
commit4ebfdff303924da5636e512ef7268612cba7c803
tree2c8c4f5fd8b61da5affd9e0b5516659ce102922f
parent889093b27de6e53cf5e90eb3ff7006d0854eb646
Add MemoryIdler suppot to IOThreadPoolExecutor

Summary:
Idle memory in IO threads.   If loop is unused for a period of time, free associated memory, and call epoll again.

Had to add a new list of callbacks that don't make the loop nonblocking (i.e. using runInLoop() instead would use the nonblocking version of epoll).

Could bake this in to EventBase directly, but that seems like the wrong abstraction, since EventBase doesn't actually control the thread - for example, that approach would also free up memory for stack-allocated EventBases where they are used synchronously by clients.

This diff doesn't change IO scheduling at all - current IO work is round robin, so this probably only helps if the whole server is idle (at least until we add smarter scheduling)

Test Plan:
Based on top of D1585087.

fbconfig thrift/perf/cpp; fbmake dbg
_bin/thrift/perf/cpp/ThriftServer
_bin/thrift/perf/cpp/loadgen -num_threads=100 -weight_sendrecv=1 -cpp2 -async

Ran loadgen for a while, watched res memory in top.  Stopped loadgen.  After ~5 sec, res memory was much reduced.

Reviewed By: jsedgwick@fb.com

Subscribers: trunkagent, doug, fugalh, njormrod, folly-diffs@

FB internal diff: D1641057

Tasks: 5002425
folly/detail/MemoryIdler.h
folly/experimental/wangle/concurrent/IOThreadPoolExecutor.cpp
folly/io/async/EventBase.cpp
folly/io/async/EventBase.h