Skip to content
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

Conversation

cheniujh
Copy link
Collaborator

@cheniujh cheniujh commented Jun 13, 2024

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

    • Introduced dynamic control over write rates with delayed-write-rate.
    • Added a limit to the number of bytes in a single compaction with max-compaction-bytes.
    • Enhanced configuration flexibility with max-background-jobs, max-background-flushes, and max-background-compactions.
  • Improvements

    • Enabled dynamic adjustments to rate limiter bandwidth.
    • Improved documentation and guidelines within the configuration for better usability.
  • Error Handling

    • Enhanced error handling for setting and validating new configurations.

cheniujh added 2 commits June 13, 2024 21:58
…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
Copy link

coderabbitai bot commented Jun 13, 2024

Walkthrough

The 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

Files Change Summaries
conf/pika.conf Added comments, new settings (max-background-jobs, delayed-write-rate, max-compaction-bytes), and dynamic rate limiter adjustments.
include/pika_conf.h Introduced new methods and variables related to compaction bytes and write rates, updated default values, and improved initialization.
src/pika_admin.cc Enhanced ConfigCmd for new configurations handling (delayed-write-rate, max-compaction-bytes), including encoding/decoding and validation.
src/pika_server.cc Updated InitStorageOptions to leverage new configurations (max_compaction_bytes, delayed_write_rate).

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
Loading

Poem

In the land of code, where bytes do play,
With new configs here to save the day.
Subcompactions rise, background jobs do twirl,
Writes flow gracefully, like a dance in a swirl.
From flushes to rates, new changes align,
Oh, code and configs, a harmony divine.


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the ☢️ Bug Something isn't working label Jun 13, 2024
Copy link

@coderabbitai coderabbitai bot left a 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 regarding rate_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 to true and the implications of this setting.


761-763: Document the dynamic nature of rate-limiter-bandwidth, delayed-write-rate, and max-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 to throttle_bytes_per_second_ to 200 << 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

Commits

Files that changed from the base of the PR and between 84cdb18 and 674f5c0.

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 adjusting max-subcompactions. This should help users optimize their Pika instances based on specific needs.


373-385: The introduction of delayed-write-rate and max-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 for max_compaction_bytes_ is consistent with expected behavior.

Please confirm that the default value for max_compaction_bytes_ is indeed 25 times the target_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 times target_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 of max_compaction_bytes() method seems correct and aligns with the PR objectives to make max-compaction-bytes dynamically changeable.


288-291: The implementation of delayed_write_rate() method seems correct and aligns with the PR objectives to add and make delayed-write-rate dynamically changeable.


742-746: The method SetDelayedWriteRate correctly implements the functionality to dynamically change the delayed-write-rate. Good use of the TryPushDiffCommands to handle configuration changes.


748-752: The method SetMaxCompactionBytes correctly implements the functionality to dynamically change the max-compaction-bytes. This aligns with the PR objectives.


893-894: Setting default values of max_background_flushes_ and max_background_compactions_ to -1 when max_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 that max_background_jobs_ is set to the sum of max_background_flushes_ and max_background_compactions_, with default values provided if max_background_jobs_ is not explicitly specified. This confirms that the logic for setting max_background_flushes_ and max_background_compactions_ when max_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 of max_background_flushes_ and max_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.cc

Length of output: 2337

src/pika_server.cc (2)

1302-1302: Ensure the max_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 of delayed_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: Validate new_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.

Comment on lines +1930 to +1940
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());
}
Copy link

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.

Comment on lines +2365 to +2377
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");
Copy link

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.

Suggested change
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
Copy link

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.

Comment on lines +422 to +432
// 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) {
Copy link

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.

Comment on lines +448 to +453
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;
}
Copy link

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
Copy link

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) {
Copy link

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.

@wangshao1 wangshao1 self-requested a review June 17, 2024 04:03
@cheniujh cheniujh added 4.0.0 3.5.5 and removed ☢️ Bug Something isn't working labels Jun 18, 2024
@AlexStocks AlexStocks merged commit f95f867 into OpenAtomFoundation:unstable Jun 18, 2024
16 checks passed
chejinge pushed a commit that referenced this pull request Jul 31, 2024
* 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]>
cheniujh added a commit to cheniujh/pika that referenced this pull request Sep 24, 2024
)

* 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]>
cheniujh added a commit to cheniujh/pika that referenced this pull request Sep 24, 2024
)

* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants