Commit f6e9600f authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

MDEV-33840 tpool- switch to longer maintainence timer interval, if pool is idle

Previous solution, that would entirely switch timer off, turned out
to be deadlock prone.

This patch fixed previous attempt to switch between long/short interval
periods in MDEV-24295. Now, initial state of the timer is fixed (it is ON).
Also, avoid switching timer to longer periods if there is any activity in
the pool.
parent 2ba79aba
...@@ -644,7 +644,7 @@ void thread_pool_generic::check_idle(std::chrono::system_clock::time_point now) ...@@ -644,7 +644,7 @@ void thread_pool_generic::check_idle(std::chrono::system_clock::time_point now)
} }
/* Switch timer off after 1 minute of idle time */ /* Switch timer off after 1 minute of idle time */
if (now - idle_since > max_idle_time) if (now - idle_since > max_idle_time && m_active_threads.empty())
{ {
idle_since= invalid_timestamp; idle_since= invalid_timestamp;
switch_timer(timer_state_t::OFF); switch_timer(timer_state_t::OFF);
...@@ -743,6 +743,12 @@ bool thread_pool_generic::add_thread() ...@@ -743,6 +743,12 @@ bool thread_pool_generic::add_thread()
if (n_threads >= m_max_threads) if (n_threads >= m_max_threads)
return false; return false;
/*
Deadlock danger exists, so monitor pool health
with maintenance timer.
*/
switch_timer(timer_state_t::ON);
if (n_threads >= m_min_threads) if (n_threads >= m_min_threads)
{ {
auto now = std::chrono::system_clock::now(); auto now = std::chrono::system_clock::now();
...@@ -753,8 +759,6 @@ bool thread_pool_generic::add_thread() ...@@ -753,8 +759,6 @@ bool thread_pool_generic::add_thread()
Throttle thread creation and wakeup deadlock detection timer, Throttle thread creation and wakeup deadlock detection timer,
if is it off. if is it off.
*/ */
switch_timer(timer_state_t::ON);
return false; return false;
} }
} }
...@@ -837,6 +841,7 @@ thread_pool_generic::thread_pool_generic(int min_threads, int max_threads) : ...@@ -837,6 +841,7 @@ thread_pool_generic::thread_pool_generic(int min_threads, int max_threads) :
// start the timer // start the timer
m_maintenance_timer.set_time(0, (int)m_timer_interval.count()); m_maintenance_timer.set_time(0, (int)m_timer_interval.count());
m_timer_state = timer_state_t::ON;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment