Skip to content

Commit

Permalink
feat: support dynamic set max-conn-rbuf-size (OpenAtomFoundation#2434)
Browse files Browse the repository at this point in the history
OpenAtomFoundation#2425

Signed-off-by: HappyUncle <[email protected]>
  • Loading branch information
happy-v587 authored and liuyuecai committed Mar 14, 2024
1 parent 1866ad1 commit c7e7ba2
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 13 deletions.
3 changes: 1 addition & 2 deletions conf/pika.conf
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,8 @@ disable_auto_compactions : false
sync-window-size : 9000

# Maximum buffer size of a client connection.
# Only three values are valid here: [67108864(64MB) | 268435456(256MB) | 536870912(512MB)].
# [NOTICE] Master and slaves must have exactly the same value for the max-conn-rbuf-size.
# Supported Units [K|M|G]. Its default unit is in [bytes] and its default value is 268435456(256MB).
# Supported Units [K|M|G]. Its default unit is in [bytes] and its default value is 268435456(256MB). The value range is [64MB, 1GB].
max-conn-rbuf-size : 268435456


Expand Down
3 changes: 1 addition & 2 deletions docs/ops/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ identify-binlog-type : new
# 主从同步流量控制的的窗口,主从高延迟情形下可以通过提高该参数提高同步性能。默认值9000最大值90000。
sync-window-size : 9000
# 处理客户端连接请求的最大缓存大小,可配置的数值为67108864(64MB) 或 268435456(256MB) 或 536870912(512MB)
# 默认是268435456(256MB),需要注意的是主从的配置需要一致。
# 处理客户端连接请求的最大缓存大小,默认是268435456(256MB),范围为[64MB, 1GB],需要注意的是主从的配置需要一致。
# 单条命令超过此buffer大小,服务端会自动关闭与客户端的连接。
max-conn-rbuf-size : 268435456
Expand Down
8 changes: 8 additions & 0 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2183,6 +2183,7 @@ void ConfigCmd::ConfigSet(std::shared_ptr<DB> db) {
"zset-cache-start-direction",
"zset-cache-field-num-per-key",
"cache-lfu-decay-time",
"max-conn-rbuf-size",
});
res_.AppendStringVector(replyVt);
return;
Expand Down Expand Up @@ -2629,6 +2630,13 @@ void ConfigCmd::ConfigSet(std::shared_ptr<DB> db) {
}
g_pika_conf->SetAclLogMaxLen(static_cast<int>(ival));
res_.AppendStringRaw("+OK\r\n");
} else if (set_item == "max-conn-rbuf-size") {
if (pstd::string2int(value.data(), value.size(), &ival) == 0 || ival < PIKA_MAX_CONN_RBUF_LB || ival > PIKA_MAX_CONN_RBUF_HB * 2) {
res_.AppendStringRaw( "-ERR Invalid argument \'" + value + "\' for CONFIG SET 'max-conn-rbuf-size'\r\n");
return;
}
g_pika_conf->SetMaxConnRbufSize(static_cast<int>(ival));
res_.AppendStringRaw("+OK\r\n");
} else {
res_.AppendStringRaw("-ERR Unsupported CONFIG parameter: " + set_item + "\r\n");
}
Expand Down
9 changes: 6 additions & 3 deletions src/pika_conf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,12 @@ int PikaConf::Load() {
// max conn rbuf size
int tmp_max_conn_rbuf_size = PIKA_MAX_CONN_RBUF;
GetConfIntHuman("max-conn-rbuf-size", &tmp_max_conn_rbuf_size);
if (tmp_max_conn_rbuf_size == PIKA_MAX_CONN_RBUF_LB || tmp_max_conn_rbuf_size == PIKA_MAX_CONN_RBUF_HB) {
max_conn_rbuf_size_.store(tmp_max_conn_rbuf_size);
if (tmp_max_conn_rbuf_size <= PIKA_MAX_CONN_RBUF_LB) {
max_conn_rbuf_size_.store(PIKA_MAX_CONN_RBUF_LB);
} else if (tmp_max_conn_rbuf_size >= PIKA_MAX_CONN_RBUF_HB * 2) {
max_conn_rbuf_size_.store(PIKA_MAX_CONN_RBUF_HB * 2);
} else {
max_conn_rbuf_size_.store(PIKA_MAX_CONN_RBUF);
max_conn_rbuf_size_.store(tmp_max_conn_rbuf_size);
}

// rocksdb blob configure
Expand Down Expand Up @@ -675,6 +677,7 @@ int PikaConf::ConfigRewrite() {
SetConfInt("consensus-level", consensus_level_.load());
SetConfInt("replication-num", replication_num_.load());
SetConfStr("slow-cmd-list", pstd::Set2String(slow_cmd_set_, ','));
SetConfInt("max-conn-rbuf-size", max_conn_rbuf_size_.load());
// options for storage engine
SetConfInt("max-cache-files", max_cache_files_);
SetConfInt("max-background-compactions", max_background_compactions_);
Expand Down
3 changes: 1 addition & 2 deletions tests/assets/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,8 @@ slave-priority : 100
sync-window-size : 9000

# Maximum buffer size of a client connection.
# Only three values are valid here: [67108864(64MB) | 268435456(256MB) | 536870912(512MB)].
# [NOTICE] Master and slaves must have exactly the same value for the max-conn-rbuf-size.
# Supported Units [K|M|G]. Its default unit is in [bytes] and its default value is 268435456(256MB).
# Supported Units [K|M|G]. Its default unit is in [bytes] and its default value is 268435456(256MB). The value range is [64MB, 1GB].
max-conn-rbuf-size : 268435456


Expand Down
3 changes: 1 addition & 2 deletions tests/conf/pika.conf
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,8 @@ slave-priority : 100
sync-window-size : 9000

# Maximum buffer size of a client connection.
# Only three values are valid here: [67108864(64MB) | 268435456(256MB) | 536870912(512MB)].
# [NOTICE] Master and slaves must have exactly the same value for the max-conn-rbuf-size.
# Supported Units [K|M|G]. Its default unit is in [bytes] and its default value is 268435456(256MB).
# Supported Units [K|M|G]. Its default unit is in [bytes] and its default value is 268435456(256MB). The value range is [64MB, 1GB].
max-conn-rbuf-size : 268435456


Expand Down
3 changes: 1 addition & 2 deletions tools/kubeblocks_helm/pika/config/pika-config.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,8 @@ slave-priority : 100
sync-window-size : 9000

# Maximum buffer size of a client connection.
# Only three values are valid here: [67108864(64MB) | 268435456(256MB) | 536870912(512MB)].
# [NOTICE] Master and slaves must have exactly the same value for the max-conn-rbuf-size.
# Supported Units [K|M|G]. Its default unit is in [bytes] and its default value is 268435456(256MB).
# Supported Units [K|M|G]. Its default unit is in [bytes] and its default value is 268435456(256MB). The [minimum] value is 67108864(64MB).
max-conn-rbuf-size : 268435456


Expand Down

0 comments on commit c7e7ba2

Please sign in to comment.