mapleFU commented on code in PR #1855:
URL: https://github.com/apache/kvrocks/pull/1855#discussion_r1375395791
##########
src/server/server.cc:
##########
@@ -1680,6 +1677,64 @@ void Server::AdjustOpenFilesLimit() {
}
}
+void Server::AdjustWorkerThreads() {
+ auto new_worker_threads = static_cast<size_t>(config_->workers);
+ if (new_worker_threads == worker_threads_.size()) {
+ return;
+ }
+ size_t delta = 0;
+ if (new_worker_threads > worker_threads_.size()) {
+ delta = new_worker_threads - worker_threads_.size();
+ increaseWorkerThreads(delta);
+ LOG(INFO) << "[server] Increase worker threads to " << new_worker_threads;
+ return;
+ }
+
+ delta = worker_threads_.size() - new_worker_threads;
+ LOG(INFO) << "[server] Decrease worker threads to " << new_worker_threads;
+ decreaseWorkerThreads(delta);
+}
+
+void Server::increaseWorkerThreads(size_t delta) {
+ std::vector<std::unique_ptr<WorkerThread>> new_threads;
+ for (size_t i = 0; i < delta; i++) {
+ auto worker = std::make_unique<Worker>(this, config_);
+ auto worker_thread = std::make_unique<WorkerThread>(std::move(worker));
+ worker_thread->Start();
+ worker_threads_.emplace_back(std::move(worker_thread));
+ }
+}
+
+void Server::decreaseWorkerThreads(size_t delta) {
+ auto current_worker_threads = worker_threads_.size();
+ auto remain_worker_threads = current_worker_threads - delta;
Review Comment:
Yeah
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]