Skip to content

Commit

Permalink
add a new configuration item control Thread Pool size
Browse files Browse the repository at this point in the history
  • Loading branch information
Axlgrep committed Jan 17, 2019
1 parent 6ba7f06 commit 05794f5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions conf/pika.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
port : 9221
# Thread Number
thread-num : 1
# Thread Pool Size
thread-pool-size : 8
# Sync Thread Number
sync-thread-num : 6
# Item count of sync thread queue
Expand Down
5 changes: 4 additions & 1 deletion include/pika_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class PikaConf : public slash::BaseConf {
bool write_binlog() {RWLock l(&rwlock_, false); return write_binlog_;}
std::string identify_binlog_type() {RWLock l(&rwlock_, false); return identify_binlog_type_;}
int thread_num() { RWLock l(&rwlock_, false); return thread_num_; }
int thread_pool_size() { RWLock l(&rwlock_, false); return thread_pool_size_; }
int sync_thread_num() { RWLock l(&rwlock_, false); return sync_thread_num_; }
int sync_buffer_size() { RWLock l(&rwlock_, false); return sync_buffer_size_; }
std::string log_path() { RWLock l(&rwlock_, false); return log_path_; }
Expand Down Expand Up @@ -104,7 +105,8 @@ class PikaConf : public slash::BaseConf {
TryPushDiffCommands("timeout", std::to_string(value));
timeout_ = value;
}
void SetSlaveof(const std::string& value) {
void SetThreadPoolSize(const int value) { RWLock l(&rwlock_, true); thread_pool_size_ = value; }
void SetSlaveof(const std::string value) {
RWLock l(&rwlock_, true);
TryPushDiffCommands("slaveof", value);
slaveof_ = value;
Expand Down Expand Up @@ -245,6 +247,7 @@ class PikaConf : public slash::BaseConf {
std::string slaveof_;
int slave_priority_;
int thread_num_;
int thread_pool_size_;
int sync_thread_num_;
int sync_buffer_size_;
std::string log_path_;
Expand Down
8 changes: 8 additions & 0 deletions src/pika_conf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ int PikaConf::Load()
if (thread_num_ > 24) {
thread_num_ = 24;
}
GetConfInt("thread-pool-size", &thread_pool_size_);
if (thread_pool_size_ <= 0) {
thread_pool_size_ = 8;
}
if (thread_pool_size_ > 24) {
thread_pool_size_ = 24;
}
GetConfInt("sync-thread-num", &sync_thread_num_);
if (sync_thread_num_ <= 0) {
sync_thread_num_ = 3;
Expand Down Expand Up @@ -301,6 +308,7 @@ int PikaConf::ConfigRewrite() {

SetConfInt("port", port_);
SetConfInt("thread-num", thread_num_);
SetConfInt("thread-pool-size", thread_pool_size_);
SetConfInt("sync-thread-num", sync_thread_num_);
SetConfInt("sync-buffer-size", sync_buffer_size_);
SetConfStr("log-path", log_path_);
Expand Down
2 changes: 1 addition & 1 deletion src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ PikaServer::PikaServer() :
pika_trysync_thread_ = new PikaTrysyncThread();
monitor_thread_ = new PikaMonitorThread();
pika_pubsub_thread_ = new pink::PubSubThread();
pika_thread_pool_ = new pink::ThreadPool(8, 100000);
pika_thread_pool_ = new pink::ThreadPool(g_pika_conf->thread_pool_size(), 100000);

//for (int j = 0; j < g_pika_conf->binlogbg_thread_num; j++) {
for (int j = 0; j < g_pika_conf->sync_thread_num(); j++) {
Expand Down

0 comments on commit 05794f5

Please sign in to comment.