You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-08-01 06:46:55 +03:00
MCOL-5044 Adding EXTRA thread logic into FairThreadPool
This commit is contained in:
committed by
Roman Nozdrin
parent
6cff14997d
commit
0e8014db02
@ -35,7 +35,7 @@ namespace threadpool
|
||||
{
|
||||
FairThreadPool::FairThreadPool(uint targetWeightPerRun, uint highThreads, uint midThreads, uint lowThreads,
|
||||
uint ID)
|
||||
: weightPerRun(targetWeightPerRun), id(ID)
|
||||
: weightPerRun(targetWeightPerRun), id(ID), stopExtra_(false)
|
||||
{
|
||||
boost::thread* newThread;
|
||||
size_t numberOfThreads = highThreads + midThreads + lowThreads;
|
||||
@ -74,6 +74,20 @@ void FairThreadPool::addJob_(const Job& job, bool useLock)
|
||||
|
||||
if (useLock)
|
||||
lk.lock();
|
||||
// If some threads have blocked (because of output queue full)
|
||||
// Temporarily add some extra worker threads to make up for the blocked threads.
|
||||
if (blockedThreads_ > extraThreads_)
|
||||
{
|
||||
stopExtra_ = false;
|
||||
newThread = threads.create_thread(ThreadHelper(this, PriorityThreadPool::Priority::EXTRA));
|
||||
newThread->detach();
|
||||
++extraThreads_;
|
||||
}
|
||||
else if (blockedThreads_ == 0)
|
||||
{
|
||||
// Release the temporary threads -- some threads have become unblocked.
|
||||
stopExtra_ = true;
|
||||
}
|
||||
|
||||
auto jobsListMapIter = txn2JobsListMap_.find(job.txnIdx_);
|
||||
if (jobsListMapIter == txn2JobsListMap_.end()) // there is no txn in the map
|
||||
@ -140,6 +154,13 @@ void FairThreadPool::threadFcn(const PriorityThreadPool::Priority preferredQueue
|
||||
|
||||
if (weightedTxnsQueue_.empty())
|
||||
{
|
||||
// If this is an EXTRA thread due toother threads blocking, and all blockers are unblocked,
|
||||
// we don't want this one any more.
|
||||
if (preferredQueue == PriorityThreadPool::Priority::EXTRA && stopExtra_)
|
||||
{
|
||||
--extraThreads_;
|
||||
return;
|
||||
}
|
||||
newJob.wait(lk);
|
||||
continue; // just go on w/o re-taking the lock
|
||||
}
|
||||
|
@ -107,6 +107,23 @@ class FairThreadPool
|
||||
{
|
||||
return jobsRunning_.load(std::memory_order_relaxed);
|
||||
}
|
||||
// If a job is blocked, we want to temporarily increase the number of threads managed by the pool
|
||||
// A problem can occur if all threads are running long or blocked for a single query. Other
|
||||
// queries won't get serviced, even though there are cpu cycles available.
|
||||
// These calls are currently protected by respondLock in sendThread(). If you call from other
|
||||
// places, you need to consider atomicity.
|
||||
void incBlockedThreads()
|
||||
{
|
||||
++blockedThreads_;
|
||||
}
|
||||
void decBlockedThreads()
|
||||
{
|
||||
--blockedThreads_;
|
||||
}
|
||||
uint32_t blockedThreadCount()
|
||||
{
|
||||
return blockedThreads_;
|
||||
}
|
||||
|
||||
protected:
|
||||
private:
|
||||
@ -160,6 +177,10 @@ class FairThreadPool
|
||||
std::atomic<size_t> jobsRunning_{0};
|
||||
std::atomic<size_t> threadCounts_{0};
|
||||
std::atomic<bool> stop_{false};
|
||||
|
||||
std::atomic<uint32_t> blockedThreads_{0};
|
||||
std::atomic<uint32_t> extraThreads_{0};
|
||||
bool stopExtra_;
|
||||
};
|
||||
|
||||
} // namespace threadpool
|
Reference in New Issue
Block a user