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

feat(config): add rocksdb.nocompression_for_first_n_levels to allow configure levels without compression #2605

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from

Conversation

paragor
Copy link
Contributor

@paragor paragor commented Oct 17, 2024

references: #2602

add rocksdb.nocompression_for_first_levels to allow configure levels without compression

kvrocks.conf Outdated Show resolved Hide resolved
@paragor paragor force-pushed the add_config_nocompression_for_first_levels branch from 7001a61 to 198699e Compare October 17, 2024 10:04
@paragor paragor force-pushed the add_config_nocompression_for_first_levels branch from 198699e to 2f03090 Compare October 17, 2024 12:28
@PragmaTwice
Copy link
Member

From the CI log, we need to add vector.reserve() before the loop containing vector.push_back().

@paragor paragor force-pushed the add_config_nocompression_for_first_levels branch from 2f03090 to e49ff75 Compare October 17, 2024 15:15
@paragor
Copy link
Contributor Author

paragor commented Oct 17, 2024

From the CI log, we need to add vector.reserve() before the loop containing vector.push_back().

thank you, didnt see it.
fixed

for (int i = 0; i < config->rocks_db.nocompression_for_first_n_levels; i++) {
compression_levels_builder.emplace_back("kNoCompression");
}
for (size_t i = config->rocks_db.nocompression_for_first_n_levels;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to check at the beginning of the callback that nocompression_for_first_n_levels <= compression_per_level.size().

Also you can make a variable for compression_per_level.size().

Copy link
Contributor Author

@paragor paragor Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was thinking that boundary check is unnecessary, because kvrocks has hardcoded 7 lvles of compactions. but it is ok, i add it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -201,6 +201,8 @@ Config::Config() {
new EnumField<rocksdb::CompressionType>(&rocks_db.compression, compression_types,
rocksdb::CompressionType::kNoCompression)},
{"rocksdb.compression_level", true, new IntField(&rocks_db.compression_level, 32767, INT_MIN, INT_MAX)},
{"rocksdb.nocompression_for_first_n_levels", false,
new IntField(&rocks_db.nocompression_for_first_n_levels, 2, 0, 7)},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering why it's 7 here? maybe we can add some comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kvrocks support only 7 levels of leveled compaction, ok i stay a comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think rather than a comment, we can use a constexpr valuable like KVROCKS_MAX_LSM_LEVEL = 7, and use it in config and here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where should i declare const? in config.h or storage.h?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh i see config.h best place for it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok to be in config.h

@paragor paragor force-pushed the add_config_nocompression_for_first_levels branch 2 times, most recently from 8f7f87d to 0268b9c Compare October 17, 2024 17:32
@paragor paragor force-pushed the add_config_nocompression_for_first_levels branch from 0268b9c to 5fb1224 Compare October 17, 2024 17:49
Comment on lines -376 to +391
if (option.name == v) {
if (option.type == srv->GetConfig()->rocks_db.compression) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering if this change here is just to make the comparison condition more concrete, or it has to be changed to make nocompression_for_first_levels work? Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously it compare value that come to callback. callback was used once when "compression" option set. Now callback call twice - for set "compression" and for set "nocompression_for_first_n_levels", so value may be name of compression or levels count that no need compression.

if i make two separate callback, it will have dublicate code, because this two options closely related.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont know how make this code better, if you have solution, plz share with me :)
i never write in c++ before

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit weird to reuse the same function...@git-hulk do you have any better idea here? There're 2 configs about compression and would set the system once...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no better solution for now because both two configurations will affect the same rocksdb option. It's weird while compared to other configurations, but it looks reasonable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we separate it to:

set_compression_method_callback
set_no_compression_level_callback

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mapleFU Do you mean this?

rocksdb::Status set_rocksdb_compression(CompressionType compression, int nocompression_for_first_n_levels) {
   ...
}

rocksdb::Status set_compression_method_callback() {
   ...
   set_rocksdb_compression(compression, nocompression_for_first_n_levels)
}

rocksdb::Status set_no_compression_level_callback() {
  ...
  set_rocksdb_compression(compression, nocompression_for_first_n_levels)
}

If yes, I'm good with it.

@paragor paragor force-pushed the add_config_nocompression_for_first_levels branch from 5fb1224 to 590becd Compare October 18, 2024 05:52
@PragmaTwice PragmaTwice changed the title feat(config): add rocksdb.nocompression_for_first_levels to allow configure levels without compression feat(config): add rocksdb.nocompression_for_first_n_levels to allow configure levels without compression Oct 18, 2024
@paragor
Copy link
Contributor Author

paragor commented Oct 18, 2024

@PragmaTwice what do you think about rename nocompression_for_first_n_levels -> start_compression_level?

Copy link
Member

@mapleFU mapleFU left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So AFAIK, just like #2607 . You'd like to enable compression on L1 ( or even L0 ) for write intensive case?

src/config/config.cc Outdated Show resolved Hide resolved
src/storage/storage.cc Outdated Show resolved Hide resolved
@mapleFU
Copy link
Member

mapleFU commented Oct 18, 2024

Perhaps, if you're a heavy write system, maybe you can enable different compression in different level, like lz4 in low level and zstd in high level...

@wanghenshui
Copy link
Contributor

maybe we could specific compression setting by level? user could mark l0/l1 as snappy or lz4 compression style

l0/l1 nocompression is common type of usage, use or not,

rocksdb.nocompression_for_first_n_levels indicate user could make l2/l3... no compression, user may not know about rocksdb stuff, make them confused about what senerio to use it

instead, let user specifc what compression style level used, maybe more clear.

@paragor
Copy link
Contributor Author

paragor commented Oct 18, 2024

So AFAIK, just like #2607 . You'd like to enable compression on L1 ( or even L0 ) for write intensive case?

yes, write 128MB compressed data on disk is better, than write uncompressed 1 GB data on disk. Now cpu usage is only 1/8 cores. so i need able to load cpu and decrease disk usage.

it is not general case, but in my case it will help me to use disks with fewer throughput and as a consequence of ec2 limitations - cheaper ec2 instance

@paragor
Copy link
Contributor Author

paragor commented Oct 18, 2024

maybe we could specific compression setting by level? user could mark l0/l1 as snappy or lz4 compression style

I think this is a good point
Something similar to the more advanced settings in kvrocks. By default, the "compression" settings are used, but if the new setting "compression_by_levels" is specified, it takes precedence, and the "compression" setting is ignored.

@mapleFU
Copy link
Member

mapleFU commented Oct 18, 2024

Maybe we should first check this in, would you mind fix the comments firstly?

@paragor paragor force-pushed the add_config_nocompression_for_first_levels branch from 590becd to 9cef6d6 Compare October 18, 2024 09:07
@paragor paragor requested a review from mapleFU October 18, 2024 09:08
# By default disabled for the first two levels, because it may contain the
# frequently accessed data, so it'd be better to use uncompressed data to
# save the CPU.
# Value: [0, 7] (upper boundary is rocksdb levels count)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Value: [0, 7] (upper boundary is rocksdb levels count)
# Value: [0, 7] (upper boundary is kvrocks maximum levels count)

Would above being better?

@@ -201,6 +201,8 @@ Config::Config() {
new EnumField<rocksdb::CompressionType>(&rocks_db.compression, compression_types,
rocksdb::CompressionType::kNoCompression)},
{"rocksdb.compression_level", true, new IntField(&rocks_db.compression_level, 32767, INT_MIN, INT_MAX)},
{"rocksdb.nocompression_for_first_n_levels", false,
new IntField(&rocks_db.nocompression_for_first_n_levels, 2, 0, 7)},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think rather than a comment, we can use a constexpr valuable like KVROCKS_MAX_LSM_LEVEL = 7, and use it in config and here

Comment on lines -376 to +391
if (option.name == v) {
if (option.type == srv->GetConfig()->rocks_db.compression) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit weird to reuse the same function...@git-hulk do you have any better idea here? There're 2 configs about compression and would set the system once...

Copy link

sonarcloud bot commented Oct 18, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
48.4% Coverage on New Code (required ≥ 50%)

See analysis details on SonarCloud

@PragmaTwice
Copy link
Member

PragmaTwice commented Oct 18, 2024

@PragmaTwice what do you think about rename nocompression_for_first_n_levels -> start_compression_level?

Nice. But seems compression_start_level or compression_begin_level is better to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants