From: Otto Moerbeek Date: Tue, 25 Jan 2022 14:42:05 +0000 (+0100) Subject: Change TaskQueue to be no longer thread local X-Git-Tag: auth-4.7.0-alpha1~19^2~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f14f56f4be12a03bb247900f3bc893dc6842e763;p=thirdparty%2Fpdns.git Change TaskQueue to be no longer thread local --- diff --git a/pdns/recursordist/rec-main.cc b/pdns/recursordist/rec-main.cc index b00e42f9d4..9f3a63db61 100644 --- a/pdns/recursordist/rec-main.cc +++ b/pdns/recursordist/rec-main.cc @@ -1801,8 +1801,6 @@ static void houseKeeping(void*) } t_running = true; - runTaskOnce(g_logCommonErrors); - struct timeval now, past; Utility::gettimeofday(&now, nullptr); past = now; @@ -1822,7 +1820,10 @@ static void houseKeeping(void*) Utility::gettimeofday(&t_last_prune, nullptr); } - if (RecThreadInfo::self().isHandler()) { + const auto& info = RecThreadInfo::self(); + + if (RecThreadInfo::self().isTaskThread()) { + runTaskOnce(g_logCommonErrors); if (now.tv_sec - s_last_ZTC_prune > 60) { s_last_ZTC_prune = now.tv_sec; static map ztcStates; @@ -1831,6 +1832,9 @@ static void houseKeeping(void*) RecZoneToCache::ZoneToCache(ztc.second, ztcStates.at(ztc.first)); } } + } + + if (info.isHandler()) { if (now.tv_sec - s_last_RC_prune > 5) { g_recCache->doPrune(g_maxCacheEntries); g_negCache->prune(g_maxCacheEntries / 10); @@ -2058,7 +2062,7 @@ void* recursorThread() // Use primes, it avoid not being scheduled in cases where the counter has a regular pattern. // We want to call handler thread often, it gets scheduled about 2 times per second - if ((threadInfo.isHandler() && s_counter % 11 == 0) || s_counter % 499 == 0) { + if (((threadInfo.isHandler() || threadInfo.isTaskThread()) && s_counter % 11 == 0) || s_counter % 499 == 0) { MT->makeThread(houseKeeping, 0); } diff --git a/pdns/recursordist/rec-taskqueue.cc b/pdns/recursordist/rec-taskqueue.cc index 000af77dd6..60e1d48e6b 100644 --- a/pdns/recursordist/rec-taskqueue.cc +++ b/pdns/recursordist/rec-taskqueue.cc @@ -21,11 +21,12 @@ */ #include "rec-taskqueue.hh" #include "taskqueue.hh" +#include "lock.hh" #include "logger.hh" #include "stat_t.hh" #include "syncres.hh" -static thread_local pdns::TaskQueue t_taskQueue; +static LockGuarded s_taskQueue; static pdns::stat_t s_almost_expired_tasks_pushed; static pdns::stat_t s_almost_expired_tasks_run; static pdns::stat_t s_almost_expired_tasks_exceptions; @@ -70,29 +71,29 @@ static void resolve(const struct timeval& now, bool logErrors, const pdns::Resol void runTaskOnce(bool logErrors) { - t_taskQueue.runOnce(logErrors); + s_taskQueue.lock()->runOnce(logErrors); } void pushAlmostExpiredTask(const DNSName& qname, uint16_t qtype, time_t deadline) { ++s_almost_expired_tasks_pushed; pdns::ResolveTask task{qname, qtype, deadline, true, resolve}; - t_taskQueue.push(std::move(task)); + s_taskQueue.lock()->push(std::move(task)); } uint64_t getTaskPushes() { - return broadcastAccFunction([] { return t_taskQueue.getPushes(); }); + return s_taskQueue.lock()->getPushes(); } uint64_t getTaskExpired() { - return broadcastAccFunction([] { return t_taskQueue.getExpired(); }); + return s_taskQueue.lock()->getExpired(); } uint64_t getTaskSize() { - return broadcastAccFunction([] { return t_taskQueue.getSize(); }); + return s_taskQueue.lock()->size(); } uint64_t getAlmostExpiredTasksPushed() diff --git a/pdns/recursordist/taskqueue.cc b/pdns/recursordist/taskqueue.cc index 11be99ef20..817bd94e21 100644 --- a/pdns/recursordist/taskqueue.cc +++ b/pdns/recursordist/taskqueue.cc @@ -85,19 +85,4 @@ void TaskQueue::runAll(bool logErrors) } } -uint64_t* TaskQueue::getPushes() const -{ - return new uint64_t(d_pushes); -} - -uint64_t* TaskQueue::getExpired() const -{ - return new uint64_t(d_expired); -} - -uint64_t* TaskQueue::getSize() const -{ - return new uint64_t(size()); -} - } /* namespace pdns */ diff --git a/pdns/recursordist/taskqueue.hh b/pdns/recursordist/taskqueue.hh index 5bd53029b9..3094079ae8 100644 --- a/pdns/recursordist/taskqueue.hh +++ b/pdns/recursordist/taskqueue.hh @@ -77,9 +77,16 @@ public: ResolveTask pop(); bool runOnce(bool logErrors); // Run one task if the queue is not empty void runAll(bool logErrors); - uint64_t* getPushes() const; - uint64_t* getExpired() const; - uint64_t* getSize() const; + + uint64_t getPushes() + { + return d_pushes; + } + + uint64_t getExpired() + { + return d_expired; + } private: queue_t d_queue;