From 68b3382ef7e0f7795b9a601aae73adc2f8ef9873 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Wed, 29 Nov 2023 09:14:57 -0500 Subject: global thread worker pools (#577) - Improvement: Use two global worker thread pools instead of ad-hoc creation of worker pools --- src/zenstore/cas.cpp | 3 ++- src/zenstore/gc.cpp | 14 ++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) (limited to 'src/zenstore') diff --git a/src/zenstore/cas.cpp b/src/zenstore/cas.cpp index c6bfda8b9..d38099117 100644 --- a/src/zenstore/cas.cpp +++ b/src/zenstore/cas.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -106,7 +107,7 @@ CasImpl::Initialize(const CidStoreConfiguration& InConfig) // Initialize payload storage { - WorkerThreadPool WorkerPool(3, "CasImpl::Initialize"); + WorkerThreadPool& WorkerPool = GetSmallWorkerPool(); std::vector> Work; Work.emplace_back( WorkerPool.EnqueueTask(std::packaged_task{[&]() { m_LargeStrategy.Initialize(m_Config.RootDirectory, IsNewStore); }})); diff --git a/src/zenstore/gc.cpp b/src/zenstore/gc.cpp index b53ca4bab..e2ab34d1e 100644 --- a/src/zenstore/gc.cpp +++ b/src/zenstore/gc.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include "cas.h" @@ -610,18 +611,11 @@ GcManager::CollectGarbage(const GcSettings& Settings) RwLock::SharedLockScope GcLock(m_Lock); - int WorkerThreadPoolCount = 0; - if (!Settings.SingleThread) - { - const size_t MaxHwTreadUse = Max((std::thread::hardware_concurrency() / 4u), 1u); - WorkerThreadPoolCount = gsl::narrow(Min(MaxHwTreadUse, m_GcReferencers.size())); - } - Result.ReferencerStats.resize(m_GcReferencers.size()); std::unordered_map, GcCompactStoreStats*> StoreCompactors; RwLock StoreCompactorsLock; - WorkerThreadPool ThreadPool(WorkerThreadPoolCount, "GCV2"); + WorkerThreadPool& ThreadPool = Settings.SingleThread ? GetSyncWorkerPool() : GetSmallWorkerPool(); ZEN_INFO("GCV2: Removing expired data from {} referencers", m_GcReferencers.size()); if (!m_GcReferencers.empty()) @@ -1932,8 +1926,8 @@ GcScheduler::ScrubStorage(bool DoDelete, std::chrono::seconds TimeSlice) Stopwatch Timer; ZEN_INFO("scrubbing STARTING (delete mode => {})", DoDelete); - WorkerThreadPool ThreadPool{4, "scrubber"}; - ScrubContext Ctx{ThreadPool, Deadline}; + WorkerThreadPool& ThreadPool = GetSmallWorkerPool(); + ScrubContext Ctx{ThreadPool, Deadline}; try { -- cgit v1.2.3