Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Move thread pool exhaustion logging to separate func.

Kishore Nallanbc9e24fb57c3
diff --git a/include/threadpool.h b/include/threadpool.h
index d4b939a2..c9c3fd41 100644
--- a/include/threadpool.h
+++ b/include/threadpool.h
@@ -12,6 +12,7 @@ public:
explicit ThreadPool(size_t);
template<class F, class... Args>
decltype(auto) enqueue(F&& f, Args&&... args);
+ void log_exhaustion();
void shutdown();
private:
// need to keep track of threads so we can join them
@@ -77,10 +78,6 @@ decltype(auto) ThreadPool::enqueue(F&& f, Args&&... args)
// don't allow enqueueing after stopping the pool
if(!stop) {
- if(tasks.size() >= workers.size()) {
- LOG(WARNING) << "Threadpool exhaustion detected, task_queue_len: "
- << tasks.size() << ", thread_pool_len: " << workers.size();
- }
tasks.emplace(std::move(task));
}
}
@@ -99,3 +96,11 @@ inline void ThreadPool::shutdown() {
worker.join();
}
}
+
+inline void ThreadPool::log_exhaustion() {
+ std::unique_lock<std::mutex> lock(queue_mutex);
+ if(tasks.size() >= workers.size()) {
+ LOG(WARNING) << "Threadpool exhaustion detected, task_queue_len: "
+ << tasks.size() << ", thread_pool_len: " << workers.size();
+ }
+}
diff --git a/src/http_server.cpp b/src/http_server.cpp
index 547e3e4b..262f5c9c 100644
--- a/src/http_server.cpp
+++ b/src/http_server.cpp
@@ -705,6 +705,7 @@ int HttpServer::process_request(const std::shared_ptr<http_req>& request, const
handler->http_server->get_thread_pool();
// LOG(INFO) << "Before enqueue res: " << response
+ thread_pool->log_exhaustion();
thread_pool->enqueue([rpath, message_dispatcher, request, response]() {
// call the API handler
//LOG(INFO) << "Wait for response " << response.get() << ", action: " << rpath->_get_action();