|
14 | 14 | #include <folly/Memory.h> |
15 | 15 | #include <glog/logging.h> |
16 | 16 |
|
| 17 | +#include <thrift/lib/cpp/concurrency/ThreadManager.h> |
17 | 18 | #include <thrift/lib/cpp2/server/ThriftServer.h> |
18 | 19 |
|
19 | 20 | #include "cpp/Destructible.h" |
@@ -138,6 +139,9 @@ CreateCppServerResult* c_create_cpp_server( |
138 | 139 | apache::thrift::TFactory factoryFn, |
139 | 140 | int desiredPort, |
140 | 141 | int workers, |
| 142 | + const int* poolSizeOverridePriorities, |
| 143 | + const size_t* poolSizeOverrideSizes, |
| 144 | + size_t numPoolSizeOverrides, |
141 | 145 | const apache::thrift::concurrency::PRIORITY* methodPriorities, |
142 | 146 | const bool* methodOneways, |
143 | 147 | const char** methodNames, |
@@ -173,6 +177,25 @@ CreateCppServerResult* c_create_cpp_server( |
173 | 177 | cppServer->setNumCPUWorkerThreads(workers); |
174 | 178 | } |
175 | 179 |
|
| 180 | + if (numPoolSizeOverrides > 0) { |
| 181 | + // Start from PriorityThreadManager's own defaults and override only the |
| 182 | + // priorities the caller asked for, so we never duplicate or drift from |
| 183 | + // the default pool sizing. |
| 184 | + auto poolSizes = apache::thrift::concurrency::PriorityThreadManager:: |
| 185 | + defaultThreadCounts(cppServer->getNumCPUWorkerThreads()); |
| 186 | + for (size_t i = 0; i < numPoolSizeOverrides; i++) { |
| 187 | + const int priority = poolSizeOverridePriorities[i]; |
| 188 | + if (priority >= 0 && |
| 189 | + priority < |
| 190 | + static_cast<int>(apache::thrift::concurrency::N_PRIORITIES)) { |
| 191 | + poolSizes[priority] = poolSizeOverrideSizes[i]; |
| 192 | + } |
| 193 | + } |
| 194 | + cppServer->setThreadManagerType( |
| 195 | + apache::thrift::ThriftServer::ThreadManagerType::PRIORITY); |
| 196 | + cppServer->setThreadManagerPoolSizes(poolSizes); |
| 197 | + } |
| 198 | + |
176 | 199 | return new CreateCppServerResult(HsLeft, std::move(cppServer)); |
177 | 200 | } catch (const std::exception& e) { |
178 | 201 | auto exStr = e.what(); |
|
0 commit comments