mirror of
https://github.com/MariaDB/server.git
synced 2025-01-15 19:42:28 +01:00
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.
This commit is contained in:
parent
2ba79aba2b
commit
f6e9600f42
1 changed files with 8 additions and 3 deletions
|
@ -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 */
|
||||
if (now - idle_since > max_idle_time)
|
||||
if (now - idle_since > max_idle_time && m_active_threads.empty())
|
||||
{
|
||||
idle_since= invalid_timestamp;
|
||||
switch_timer(timer_state_t::OFF);
|
||||
|
@ -743,6 +743,12 @@ bool thread_pool_generic::add_thread()
|
|||
if (n_threads >= m_max_threads)
|
||||
return false;
|
||||
|
||||
/*
|
||||
Deadlock danger exists, so monitor pool health
|
||||
with maintenance timer.
|
||||
*/
|
||||
switch_timer(timer_state_t::ON);
|
||||
|
||||
if (n_threads >= m_min_threads)
|
||||
{
|
||||
auto now = std::chrono::system_clock::now();
|
||||
|
@ -753,8 +759,6 @@ bool thread_pool_generic::add_thread()
|
|||
Throttle thread creation and wakeup deadlock detection timer,
|
||||
if is it off.
|
||||
*/
|
||||
switch_timer(timer_state_t::ON);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -837,6 +841,7 @@ thread_pool_generic::thread_pool_generic(int min_threads, int max_threads) :
|
|||
|
||||
// start the timer
|
||||
m_maintenance_timer.set_time(0, (int)m_timer_interval.count());
|
||||
m_timer_state = timer_state_t::ON;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue