提交 dd995ba6 编写于 作者: Z zhaoanan

add max-cache-files to control memory

上级 64ab01df
......@@ -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
......@@ -46,6 +46,7 @@ public:
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_; }
......@@ -149,6 +150,7 @@ private:
std::string conf_path_;
int max_background_flushes_;
int max_background_compactions_;
int max_cache_files_;
//char username_[30];
//char password_[30];
......
......@@ -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;
......@@ -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");
......@@ -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");
......@@ -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");
......
......@@ -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);
......@@ -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_);
......
......@@ -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;
}
......
Subproject commit a1bbdbdf2c82fa5573eae901c530fbb101368965
Subproject commit 672662ae5df3b4df0f639a4bd2cd2c1f7be43d9b
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册