From 72053457a045a1eaf9453d464632cee75bc3010a Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Wed, 19 May 2021 18:42:43 -0400 Subject: [PATCH] optimize curl worker thread a good amount --- filecache.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/filecache.cpp b/filecache.cpp index eb31360..125f0ec 100644 --- a/filecache.cpp +++ b/filecache.cpp @@ -125,6 +125,10 @@ void FileCacheWorkerThread::stop() { } void FileCacheWorkerThread::loop() { + timeval timeout; + timeout.tv_sec = 1; + timeout.tv_usec = 0; + while (!m_stop) { if (m_handles.size() == 0) { std::unique_lock lock(m_queue_mutex); @@ -133,7 +137,8 @@ void FileCacheWorkerThread::loop() { m_cv.wait(lock); } - if (m_handles.size() < Abaddon::Get().GetSettings().GetCacheHTTPConcurrency()) { + static const auto concurrency = Abaddon::Get().GetSettings().GetCacheHTTPConcurrency(); + if (m_handles.size() < concurrency) { std::optional entry; m_queue_mutex.lock(); if (m_queue.size() > 0) { @@ -171,8 +176,20 @@ void FileCacheWorkerThread::loop() { } } - //int fds; - //curl_multi_wait(m_multi_handle, nullptr, 0, 10, &fds); + fd_set fdread; + fd_set fdwrite; + fd_set fdexcep; + int maxfd = -1; + FD_ZERO(&fdread); + FD_ZERO(&fdwrite); + FD_ZERO(&fdexcep); + curl_multi_fdset(m_multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); + if (maxfd == -1) { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } else { + select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout); + } + curl_multi_perform(m_multi_handle, &m_running_handles); int num_msgs;