tikv/tikv
GitHub で見るconsider reducing the mutex contention in the worker thread pool
Open
#2,586 opened on 2017年12月14日
component/performancehelp wanted
説明
I find that our worker thread pool uses the traditional mutex + condition var mechanism for the thread interaction.
The task queue is also handled in the mutex, this may cause the frequent lock contention even the task queue has enough tasks and the worker doesn't need to wait.
I abstract the queue from the mutex and use a spinlock to lock separately, do some benchmarks and find the performance increased, see:
./origin_thread_pool
Using 8 threads
204678 QPS
185131 QPS
186840 QPS
165325 QPS
./spin_thread_pool 8
Using 8 threads
232116 QPS
244754 QPS
216727 QPS
235721 QPS
So I think it is worth to re-improve the worker thread pool.
The benchmark cases:
Origin: https://gist.github.com/siddontang/fa81a59e7234e9960f8514785af69e1e Spinlock: https://gist.github.com/siddontang/5b4b023475a55e0d4898117790a224c9
/cc @BusyJay @zhangjinpeng1987 @wentaoxu