From b5c7e2de4e4760f554d32eec4ffb8b6f1fb44a25 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sat, 6 Dec 2014 19:21:30 +0100 Subject: [PATCH] Make the ThreadPool spawn fewer threads --- lib/base/threadpool.cpp | 15 +++++++-------- lib/base/threadpool.hpp | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/base/threadpool.cpp b/lib/base/threadpool.cpp index aee587e66..2a814134f 100644 --- a/lib/base/threadpool.cpp +++ b/lib/base/threadpool.cpp @@ -265,18 +265,17 @@ void ThreadPool::ManagerThreadProc(void) int tthreads = wthreads - alive; - /* Make sure there is at least one thread per CPU */ - int ncput = std::max(static_cast(Application::GetConcurrency()) / QUEUECOUNT, 4U); - if (alive + tthreads < ncput) - tthreads = ncput - alive; + /* Make sure there is at least one thread per queue */ + if (alive + tthreads < 1) + tthreads = 1 - alive; - /* Don't kill more than 8 threads at once. */ - if (tthreads < -8) - tthreads = -8; + /* Don't kill more than 2 threads at once. */ + if (tthreads < -2) + tthreads = -2; /* Spawn more workers if there are outstanding work items. */ if (tthreads > 0 && pending > 0) - tthreads = 8; + tthreads = 2; if (m_MaxThreads != UINT_MAX && (alive + tthreads) * (sizeof(m_Queues) / sizeof(m_Queues[0])) > m_MaxThreads) tthreads = m_MaxThreads / (sizeof(m_Queues) / sizeof(m_Queues[0])) - alive; diff --git a/lib/base/threadpool.hpp b/lib/base/threadpool.hpp index afae6c0b8..04faa19ec 100644 --- a/lib/base/threadpool.hpp +++ b/lib/base/threadpool.hpp @@ -30,7 +30,7 @@ namespace icinga { -#define QUEUECOUNT 4 +#define QUEUECOUNT 4U enum SchedulerPolicy {