diff --git a/src/box/box.cc b/src/box/box.cc index f98318e9427e12980ae063e2157ecc3e64e67e0b..710a2e0c00be88474df46e0f03c874931d58c1a2 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -626,6 +626,25 @@ engine_init() engine_register(sophia); } +/** + * @brief Reduce the current number of threads in the thread pool to the + * bare minimum. Doesn't prevent the pool from spawning new threads later + * if demand mounts. + */ +static void +thread_pool_trim() +{ + /* + * Trim OpenMP thread pool. + * Though we lack the direct control the workaround below works for + * GNU OpenMP library. The library stops surplus threads on entering + * a parallel region. Can't go below 2 threads due to the + * implementation quirk. + */ +#pragma omp parallel num_threads(2) + ; +} + static inline void box_init(void) { @@ -696,6 +715,11 @@ box_init(void) engine_end_recovery(); + /* + * Recovery inflates the thread pool quite a bit (due to parallel sort). + */ + thread_pool_trim(); + rmean_cleanup(rmean_box); if (recovery_has_replica(recovery))