-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Revised RocksDB-Related Parameters in Pika #2728
fix: Revised RocksDB-Related Parameters in Pika #2728
Conversation
…cally changeable 2 allow user to config max-background-flushes and max-background-compactions to -1 while max-background-jobs is given 3 add conf item delayed-write-rate and make it dynamically changeable 4 add conf item max-compaction-bytes and make it dynamically changeable 4 revised the comment of rate-limiter-auto-tuned in pika.conf
WalkthroughThe recent updates to the Pika configuration and codebase introduce detailed comments, new settings for controlling background jobs, write rates, and compaction bytes, as well as dynamic rate-limiter adjustments. The enhancements aim to fine-tune and dynamically manage the performance and scalability of the database, ensuring smoother operations and better resource management. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant PikaAdmin
participant PikaConf
participant PikaServer
User ->> PikaAdmin: ConfigSet (delayed-write-rate, max-compaction-bytes)
PikaAdmin ->> PikaConf: SetDelayedWriteRate(value), SetMaxCompactionBytes(value)
PikaConf ->> PikaServer: Update Configuration
PikaServer -) User: Configuration Updated
User ->> PikaAdmin: ConfigGet
PikaAdmin ->> PikaConf: GetDelayedWriteRate(), GetMaxCompactionBytes()
PikaConf -) PikaAdmin: Return Values
PikaAdmin -) User: Return Configuration Values
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 9
Outside diff range and nitpick comments (3)
src/pika_conf.cc (2)
369-369
: Improve the clarity of the comment regardingrate_limiter_auto_tuned_
.The comment on line 369 could be more descriptive. Consider revising it to clearly explain under what conditions
rate_limiter_auto_tuned_
defaults totrue
and the implications of this setting.
761-763
: Document the dynamic nature ofrate-limiter-bandwidth
,delayed-write-rate
, andmax-compaction-bytes
.While the changes make these settings dynamically changeable, the code comments do not reflect this. Adding comments to document the dynamic nature of these settings would improve code readability and maintainability.
include/pika_conf.h (1)
975-975
: The update tothrottle_bytes_per_second_
to200 << 20
(200MB/s) seems to be a hardcoded value change. Consider making this configurable if not already to enhance flexibility.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (5)
- conf/pika.conf (3 hunks)
- include/pika_conf.h (6 hunks)
- src/pika_admin.cc (3 hunks)
- src/pika_conf.cc (7 hunks)
- src/pika_server.cc (3 hunks)
Files not summarized due to errors (1)
- src/pika_conf.cc: Error: Server error. Please try again later.
Additional comments not posted (11)
conf/pika.conf (2)
243-244
: The added comments provide clear guidance on the benefits of adjustingmax-subcompactions
. This should help users optimize their Pika instances based on specific needs.
373-385
: The introduction ofdelayed-write-rate
andmax-compaction-bytes
with dynamic adjustability is a crucial update for better managing write operations and compaction processes in high-load environments. The comments are informative, explaining default behaviors and conditions effectively.src/pika_conf.cc (1)
391-395
: Ensure the default value formax_compaction_bytes_
is consistent with expected behavior.Please confirm that the default value for
max_compaction_bytes_
is indeed 25 times thetarget_file_size_base_
, as this is critical for ensuring optimal performance and stability.Verification successful
The default value for
max_compaction_bytes_
is correctly set to 25 timestarget_file_size_base_
, which aligns with the expected behavior.
src/pika_conf.cc
:max_compaction_bytes_ = target_file_size_base_ * 25;
include/pika_conf.h
:int target_file_size_base_ = 0;
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the default value for max_compaction_bytes_ aligns with RocksDB's expected defaults. # Test: Search for the default value usage in RocksDB configuration handling. rg --type cpp $'max_compaction_bytes_ ='Length of output: 227
Script:
#!/bin/bash # Description: Verify the definition and usage of target_file_size_base_ to ensure consistency with max_compaction_bytes_. # Search for the definition of target_file_size_base_ rg --type cpp 'target_file_size_base_' # Search for the usage of target_file_size_base_ in the codebase rg --type cpp 'target_file_size_base_'Length of output: 997
include/pika_conf.h (5)
258-262
: The implementation ofmax_compaction_bytes()
method seems correct and aligns with the PR objectives to makemax-compaction-bytes
dynamically changeable.
288-291
: The implementation ofdelayed_write_rate()
method seems correct and aligns with the PR objectives to add and makedelayed-write-rate
dynamically changeable.
742-746
: The methodSetDelayedWriteRate
correctly implements the functionality to dynamically change thedelayed-write-rate
. Good use of theTryPushDiffCommands
to handle configuration changes.
748-752
: The methodSetMaxCompactionBytes
correctly implements the functionality to dynamically change themax-compaction-bytes
. This aligns with the PR objectives.
893-894
: Setting default values ofmax_background_flushes_
andmax_background_compactions_
to-1
whenmax_background_jobs
is specified is a significant change. Ensure that this logic is handled correctly in the runtime configuration logic to avoid unintended behavior.Verification successful
The code in
pika_conf.cc
shows thatmax_background_jobs_
is set to the sum ofmax_background_flushes_
andmax_background_compactions_
, with default values provided ifmax_background_jobs_
is not explicitly specified. This confirms that the logic for settingmax_background_flushes_
andmax_background_compactions_
whenmax_background_jobs
is specified is handled correctly.
max_background_compactions_
is initialized and bounded between 2 and 8.max_background_jobs_
is calculated as the sum ofmax_background_flushes_
andmax_background_compactions_
, with default values if not specified.This ensures that the values are appropriately set and managed.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the handling logic for max_background_flushes and max_background_compactions when max_background_jobs is specified. # Test: Search for the logic handling these configurations. Expect: Proper checks and balances in place. rg --type cpp $'max_background_jobs' include/Length of output: 253
Script:
#!/bin/bash # Description: Verify the handling logic for max_background_flushes_ and max_background_compactions_ in relation to max_background_jobs. # Search for the handling logic of max_background_flushes_ rg --type cpp 'max_background_flushes_' include/ # Search for the handling logic of max_background_compactions_ rg --type cpp 'max_background_compactions_' include/Length of output: 394
Script:
#!/bin/bash # Description: Verify the handling logic for max_background_flushes_ and max_background_compactions_ in relation to max_background_jobs. # Search for the usage of max_background_jobs in the codebase rg --type cpp 'max_background_jobs' .Length of output: 1184
Script:
#!/bin/bash # Description: Extract the relevant code from pika_conf.cc to verify the handling logic for max_background_flushes_ and max_background_compactions_. # Extract the relevant code around max_background_jobs in pika_conf.cc rg --context 10 'max_background_jobs' src/pika_conf.ccLength of output: 2337
src/pika_server.cc (2)
1302-1302
: Ensure themax_compaction_bytes
value is being set correctly.This change allows for dynamic adjustment of the
max_compaction_bytes
setting, aligning with the PR's objectives to enhance RocksDB parameter management.
1307-1307
: Verify the correct functioning ofdelayed_write_rate
.The addition of the
delayed_write_rate
configuration item is consistent with PR objectives to make this setting dynamically changeable, improving write performance under load.src/pika_admin.cc (1)
2379-2391
: Validatenew_max_compaction_bytes
for non-positive values.The setting for
max_compaction_bytes
should be checked for non-positive values to ensure that the configuration is robust and prevents potential issues in compaction behavior.- if (pstd::string2int(value.data(), value.size(), &new_max_compaction_bytes) == 0 || new_max_compaction_bytes <= 0) { + if (pstd::string2int(value.data(), value.size(), &new_max_compaction_bytes) == 0 || new_max_compaction_bytes < 0) {Likely invalid or redundant comment.
if (pstd::stringmatch(pattern.data(), "delayed-write-rate", 1) != 0) { | ||
elements += 2; | ||
EncodeString(&config_body, "delayed-write-rate"); | ||
EncodeNumber(&config_body, g_pika_conf->delayed_write_rate()); | ||
} | ||
|
||
if (pstd::stringmatch(pattern.data(), "max-compaction-bytes", 1) != 0) { | ||
elements += 2; | ||
EncodeString(&config_body, "max-compaction-bytes"); | ||
EncodeNumber(&config_body, g_pika_conf->max_compaction_bytes()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure proper handling when delayed_write_rate
is set to zero or negative.
Consider adding validation to ensure delayed_write_rate
is not set to zero or negative values, which could potentially cause unexpected behavior or performance issues.
int64_t new_delayed_write_rate = 0; | ||
if (pstd::string2int(value.data(), value.size(), &new_delayed_write_rate) == 0 || new_delayed_write_rate <= 0) { | ||
res_.AppendStringRaw("-ERR Invalid argument \'" + value + "\' for CONFIG SET 'delayed-write-rate'\r\n"); | ||
return; | ||
} | ||
std::unordered_map<std::string, std::string> options_map{{"delayed_write_rate", value}}; | ||
storage::Status s = g_pika_server->RewriteStorageOptions(storage::OptionType::kDB, options_map); | ||
if (!s.ok()) { | ||
res_.AppendStringRaw("-ERR Set delayed-write-rate wrong: " + s.ToString() + "\r\n"); | ||
return; | ||
} | ||
g_pika_conf->SetDelayedWriteRate(new_delayed_write_rate); | ||
res_.AppendStringRaw("+OK\r\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate new_delayed_write_rate
for non-positive values.
The setting for delayed_write_rate
should be checked for non-positive values to prevent potential misconfigurations that could affect system performance.
- if (pstd::string2int(value.data(), value.size(), &new_delayed_write_rate) == 0 || new_delayed_write_rate <= 0) {
+ if (pstd::string2int(value.data(), value.size(), &new_delayed_write_rate) == 0 || new_delayed_write_rate < 0) {
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
int64_t new_delayed_write_rate = 0; | |
if (pstd::string2int(value.data(), value.size(), &new_delayed_write_rate) == 0 || new_delayed_write_rate <= 0) { | |
res_.AppendStringRaw("-ERR Invalid argument \'" + value + "\' for CONFIG SET 'delayed-write-rate'\r\n"); | |
return; | |
} | |
std::unordered_map<std::string, std::string> options_map{{"delayed_write_rate", value}}; | |
storage::Status s = g_pika_server->RewriteStorageOptions(storage::OptionType::kDB, options_map); | |
if (!s.ok()) { | |
res_.AppendStringRaw("-ERR Set delayed-write-rate wrong: " + s.ToString() + "\r\n"); | |
return; | |
} | |
g_pika_conf->SetDelayedWriteRate(new_delayed_write_rate); | |
res_.AppendStringRaw("+OK\r\n"); | |
int64_t new_delayed_write_rate = 0; | |
if (pstd::string2int(value.data(), value.size(), &new_delayed_write_rate) == 0 || new_delayed_write_rate < 0) { | |
res_.AppendStringRaw("-ERR Invalid argument \'" + value + "\' for CONFIG SET 'delayed-write-rate'\r\n"); | |
return; | |
} | |
std::unordered_map<std::string, std::string> options_map{{"delayed_write_rate", value}}; | |
storage::Status s = g_pika_server->RewriteStorageOptions(storage::OptionType::kDB, options_map); | |
if (!s.ok()) { | |
res_.AppendStringRaw("-ERR Set delayed-write-rate wrong: " + s.ToString() + "\r\n"); | |
return; | |
} | |
g_pika_conf->SetDelayedWriteRate(new_delayed_write_rate); | |
res_.AppendStringRaw("+OK\r\n"); |
@@ -349,7 +349,7 @@ int PikaConf::Load() { | |||
// rate-limiter-bandwidth | |||
GetConfInt64("rate-limiter-bandwidth", &rate_limiter_bandwidth_); | |||
if (rate_limiter_bandwidth_ <= 0) { | |||
rate_limiter_bandwidth_ = 2000 * 1024 * 1024; // 2000MB/s | |||
rate_limiter_bandwidth_ = 1024LL << 30; // 1024GB/s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider validating the rate_limiter_bandwidth_
to ensure it's within a reasonable range.
To prevent potential misconfiguration, it would be wise to add a validation step to ensure the rate_limiter_bandwidth_
is within a reasonable range before setting it to 1024GB. This can help avoid situations where an incorrect configuration could lead to performance degradation or system instability.
// max-background-flushes and max-background-compactions should both be -1 or both not | ||
GetConfInt("max-background-flushes", &max_background_flushes_); | ||
if (max_background_flushes_ <= 0) { | ||
if (max_background_flushes_ <= 0 && max_background_flushes_ != -1) { | ||
max_background_flushes_ = 1; | ||
} | ||
if (max_background_flushes_ >= 6) { | ||
max_background_flushes_ = 6; | ||
} | ||
|
||
GetConfInt("max-background-compactions", &max_background_compactions_); | ||
if (max_background_compactions_ <= 0) { | ||
if (max_background_compactions_ <= 0 && max_background_compactions_ != -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor the handling of -1
values for max_background_flushes_
and max_background_compactions_
.
The handling of -1
values for max_background_flushes_
and max_background_compactions_
could be streamlined to reduce redundancy and improve clarity. Consider extracting this logic into a helper function that can be reused for both settings.
GetConfInt64("delayed-write-rate", &delayed_write_rate_); | ||
if (delayed_write_rate_ <= 0) { | ||
// set 0 means let rocksDB infer from rate-limiter(by default, rate-limiter is 1024GB, delayed_write_rate will be 512GB) | ||
// if rate-limiter is nullptr, it would be set to 16MB by RocksDB | ||
delayed_write_rate_ = 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarify the interaction between delayed_write_rate_
and rate_limiter
.
The comment on line 451 suggests a dependency between delayed_write_rate_
and rate_limiter
. It would be beneficial to add explicit checks or documentation in the code to clarify how these settings interact, especially in cases where rate_limiter
might be null.
@@ -645,7 +660,7 @@ | |||
// throttle-bytes-per-second | |||
GetConfInt("throttle-bytes-per-second", &throttle_bytes_per_second_); | |||
if (throttle_bytes_per_second_ <= 0) { | |||
throttle_bytes_per_second_ = 207200000; | |||
throttle_bytes_per_second_ = 200LL << 20; //200 MB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate the throttle_bytes_per_second
setting to prevent potential misconfigurations.
Given the significant impact that throttle_bytes_per_second
can have on system performance, adding a validation step to ensure this setting is within a practical range would be prudent. This can help prevent scenarios where an overly aggressive or too lenient setting could affect system stability.
@@ -2459,7 +2508,7 @@ | |||
g_pika_conf->SetMaxCacheFiles(static_cast<int>(ival)); | |||
res_.AppendStringRaw("+OK\r\n"); | |||
} else if (set_item == "max-background-compactions") { | |||
if (pstd::string2int(value.data(), value.size(), &ival) == 0) { | |||
if (pstd::string2int(value.data(), value.size(), &ival) == 0 || ival <= 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check for non-positive values in max-background-compactions
.
It is crucial to validate max-background-compactions
to ensure that it does not accept non-positive values, which are logically incorrect and could disrupt the database's performance.
- if (pstd::string2int(value.data(), value.size(), &ival) == 0 || ival <= 0) {
+ if (pstd::string2int(value.data(), value.size(), &ival) == 0 || ival < 0) {
Committable suggestion was skipped due to low confidence.
* 1 set the default value of rate-limiter to 1024GB and make it dynamically changeable 2 allow user to config max-background-flushes and max-background-compactions to -1 while max-background-jobs is given 3 add conf item delayed-write-rate and make it dynamically changeable 4 add conf item max-compaction-bytes and make it dynamically changeable 4 revised the comment of rate-limiter-auto-tuned in pika.conf --------- Co-authored-by: cjh <[email protected]>
) * 1 set the default value of rate-limiter to 1024GB and make it dynamically changeable 2 allow user to config max-background-flushes and max-background-compactions to -1 while max-background-jobs is given 3 add conf item delayed-write-rate and make it dynamically changeable 4 add conf item max-compaction-bytes and make it dynamically changeable 4 revised the comment of rate-limiter-auto-tuned in pika.conf * fix bugs --------- Co-authored-by: cjh <[email protected]>
) * 1 set the default value of rate-limiter to 1024GB and make it dynamically changeable 2 allow user to config max-background-flushes and max-background-compactions to -1 while max-background-jobs is given 3 add conf item delayed-write-rate and make it dynamically changeable 4 add conf item max-compaction-bytes and make it dynamically changeable 4 revised the comment of rate-limiter-auto-tuned in pika.conf --------- Co-authored-by: cjh <[email protected]>
1 set the default value of rate-limiter to 1024GB and make it dynamically changeable
2 allow user to config max-background-flushes and max-background-compactions to -1 while max-background-jobs is given
3 add conf item delayed-write-rate and make it dynamically changeable
4 add conf item max-compaction-bytes and make it dynamically changeable
4 revised the comment of rate-limiter-auto-tuned in pika.conf
Summary by CodeRabbit
New Features
delayed-write-rate
.max-compaction-bytes
.max-background-jobs
,max-background-flushes
, andmax-background-compactions
.Improvements
Error Handling