Skip to content

Commit

Permalink
add max-cache-files to control memory
Browse files Browse the repository at this point in the history
  • Loading branch information
flabby committed Jul 14, 2016
1 parent 64ab01d commit dd995ba
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions conf/pika.conf
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ compression : snappy
max-background-flushes : 1
# max-background-compactions: default is 1, limited in [1, 4]
max-background-compactions : 1
# max-cache-files default is 5000
max-cache-files : 5000
2 changes: 2 additions & 0 deletions include/pika_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class PikaConf : public slash::BaseConf {
int target_file_size_base() { RWLock l(&rwlock_, false); return target_file_size_base_; }
int max_background_flushes() { RWLock l(&rwlock_, false); return max_background_flushes_; }
int max_background_compactions() { RWLock l(&rwlock_, false); return max_background_compactions_; }
int max_cache_files() { RWLock l(&rwlock_, false); return max_cache_files_; }
int expire_logs_nums() { RWLock l(&rwlock_, false); return expire_logs_nums_; }
int expire_logs_days() { RWLock l(&rwlock_, false); return expire_logs_days_; }
std::string conf_path() { RWLock l(&rwlock_, false); return conf_path_; }
Expand Down Expand Up @@ -149,6 +150,7 @@ class PikaConf : public slash::BaseConf {
std::string conf_path_;
int max_background_flushes_;
int max_background_compactions_;
int max_cache_files_;

//char username_[30];
//char password_[30];
Expand Down
13 changes: 11 additions & 2 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,12 @@ void InfoCmd::InfoLog(std::string &info) {

void InfoCmd::InfoData(std::string &info) {
std::stringstream tmp_stream;

int64_t db_size = slash::Du(g_pika_conf->db_path());
tmp_stream << "# Data" << "\r\n";
tmp_stream << "db_size:" << (slash::Du(g_pika_conf->db_path()) >> 20) << "M\r\n";
tmp_stream << "db_size:" << (db_size >> 20) << "M\r\n";
tmp_stream << "compression:" << g_pika_conf->compression() << "\r\n";
tmp_stream << "used_memory:" << db_size << "\r\n";

info.append(tmp_stream.str());
return;
Expand Down Expand Up @@ -787,6 +790,10 @@ void ConfigCmd::ConfigGet(std::string &ret) {
ret = "*2\r\n";
EncodeString(&ret, "max-background-compactions");
EncodeInt32(&ret, g_pika_conf->max_background_compactions());
} else if (get_item == "max-cache-files") {
ret = "*2\r\n";
EncodeString(&ret, "max-cache-files");
EncodeInt32(&ret, g_pika_conf->max_cache_files());
} else if (get_item == "expire-logs-days") {
ret = "*2\r\n";
EncodeString(&ret, "expire-logs-days");
Expand Down Expand Up @@ -820,7 +827,7 @@ void ConfigCmd::ConfigGet(std::string &ret) {
EncodeString(&ret, "no");
}
} else if (get_item == "*") {
ret = "*60\r\n";
ret = "*62\r\n";
EncodeString(&ret, "port");
EncodeInt32(&ret, g_pika_conf->port());
EncodeString(&ret, "thread-num");
Expand Down Expand Up @@ -863,6 +870,8 @@ void ConfigCmd::ConfigGet(std::string &ret) {
EncodeInt32(&ret, g_pika_conf->max_background_flushes());
EncodeString(&ret, "max-background-compactions");
EncodeInt32(&ret, g_pika_conf->max_background_compactions());
EncodeString(&ret, "max-cache-files");
EncodeInt32(&ret, g_pika_conf->max_cache_files());
EncodeString(&ret, "expire-logs-days");
EncodeInt32(&ret, g_pika_conf->expire_logs_days());
EncodeString(&ret, "expire-logs-nums");
Expand Down
7 changes: 7 additions & 0 deletions src/pika_conf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ int PikaConf::Load()
max_background_compactions_ = 4;
}

max_cache_files_ = 5000;
GetConfInt("max-cache-files", &max_cache_files_);
if (max_cache_files_ < -1) {
max_cache_files_ = 5000;
}

// daemonize
std::string dmz;
GetConfStr("daemonize", &dmz);
Expand Down Expand Up @@ -173,6 +179,7 @@ int PikaConf::ConfigRewrite() {
SetConfInt("target-file-size-base", target_file_size_base_);
SetConfInt("max-background-flushes", max_background_flushes_);
SetConfInt("max-background-compactions", max_background_compactions_);
SetConfInt("max-cache-files", max_cache_files_);
SetConfInt("expire-logs-nums", expire_logs_nums_);
SetConfInt("expire-logs-days", expire_logs_days_);
SetConfBool("slave-read-only", readonly_);
Expand Down
1 change: 1 addition & 0 deletions src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ PikaServer::PikaServer() :
option.target_file_size_base = g_pika_conf->target_file_size_base();
option.max_background_flushes = g_pika_conf->max_background_flushes();
option.max_background_compactions = g_pika_conf->max_background_compactions();
option.max_open_files = g_pika_conf->max_cache_files();
if (g_pika_conf->compression() == "none") {
option.compression = false;
}
Expand Down
2 changes: 1 addition & 1 deletion third/nemo
Submodule nemo updated from a1bbdb to 672662

0 comments on commit dd995ba

Please sign in to comment.