diff options
author | kulikov <kulikov@yandex-team.com> | 2023-07-21 13:59:33 +0300 |
---|---|---|
committer | kulikov <kulikov@yandex-team.com> | 2023-07-21 13:59:33 +0300 |
commit | 5706cb392271ea40eab053314e7c0f4d9d4547ba (patch) | |
tree | 72bce210dc3747df1d9319fc9f56b848852d2aab /library/cpp/http/server/http.cpp | |
parent | 122a6055cef2bc785407c69b33b858a07b319e66 (diff) | |
download | ydb-5706cb392271ea40eab053314e7c0f4d9d4547ba.tar.gz |
try to get rid of locks and allocations for elastic queue thread pool
In case of heavy load and high rps current thread pool implementation seems to have problems at least with contention on lock inside condvar (long futex wait calls from http server listener thread), so try to implement something more efficient:
- replace condvar with TEventCounter implementation without internal lock (pthread condvar maintains waiters wakeup order, thread pool doesn't need it);
- introduce well-known bounded mpmc queue over ring buffer;
- get rid of TDecrementingWrapper;
- add options to turn on new pool in library/cpp/http/server and search/daemons (will remove after adoption);
- make elastic queue ut check both versions;
- workaround problems with android/arm build targets.
Diffstat (limited to 'library/cpp/http/server/http.cpp')
-rw-r--r-- | library/cpp/http/server/http.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/library/cpp/http/server/http.cpp b/library/cpp/http/server/http.cpp index 2dd407dcef..ecdd93ab56 100644 --- a/library/cpp/http/server/http.cpp +++ b/library/cpp/http/server/http.cpp @@ -2,6 +2,7 @@ #include "http_ex.h" #include <library/cpp/threading/equeue/equeue.h> +#include <library/cpp/threading/equeue/fast.h> #include <util/generic/buffer.h> #include <util/generic/intrlist.h> @@ -405,8 +406,8 @@ public: : TImpl( parent, cb, - MakeThreadPool<TSimpleThreadPool>(factory, options.UseElasticQueues, cb, options.RequestsThreadName), - MakeThreadPool<TThreadPool>(factory, options.UseElasticQueues, nullptr, options.FailRequestsThreadName), + MakeThreadPool<TSimpleThreadPool>(factory, options, cb, options.RequestsThreadName), + MakeThreadPool<TThreadPool>(factory, options, nullptr, options.FailRequestsThreadName), options) { } @@ -456,21 +457,30 @@ public: private: template <class TThreadPool_> - static THolder<IThreadPool> MakeThreadPool(IThreadFactory* factory, bool elastic, ICallBack* callback = nullptr, const TString& threadName = {}) { + static THolder<IThreadPool> MakeThreadPool(ICallBack* callback, const IThreadPool::TParams& params) { + if (callback) { + return MakeHolder<TThreadPoolBinder<TThreadPool_, THttpServer::ICallBack>>(callback, params); + } else { + return MakeHolder<TThreadPool_>(params); + } + } + + template <class TThreadPool_> + static THolder<IThreadPool> MakeThreadPool(IThreadFactory* factory, const TOptions& options, ICallBack* callback = nullptr, const TString& threadName = {}) { if (!factory) { factory = SystemThreadFactory(); } THolder<IThreadPool> pool; const auto params = IThreadPool::TParams().SetFactory(factory).SetThreadName(threadName); - if (callback) { - pool = MakeHolder<TThreadPoolBinder<TThreadPool_, THttpServer::ICallBack>>(callback, params); - } else { - pool = MakeHolder<TThreadPool_>(params); - } - if (elastic) { - pool = MakeHolder<TElasticQueue>(std::move(pool)); + if (options.UseFastElasticQueues) { + pool = MakeThreadPool<TFastElasticQueue>(callback, params); + } else { + pool = MakeThreadPool<TThreadPool_>(callback, params); + if (options.UseElasticQueues) { + pool = MakeHolder<TElasticQueue>(std::move(pool)); + } } return pool; |