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

Set perf flags all at once #272

Merged
merged 1 commit into from
Apr 2, 2022
Merged

Set perf flags all at once #272

merged 1 commit into from
Apr 2, 2022

Conversation

sticnarf
Copy link

@sticnarf sticnarf commented Apr 1, 2022

This PR changes some bits of #237.

Considering our use cases in TiKV, although not really necessary, we frequently set perf levels around RocksDB operations. So, if we switch to perf flags, it requires us to set perf flags efficiently. And we have quite a few flags to set, setting flags one by one in #237 is not that efficient.

All flags can be saved in two words. So, we can achieve similar efficiency by setting all flags all at once. And meanwhile, we can flexibly specify which metrics we care about at runtime.

This PR also changes to use std::bitset and a named enum instead of handmade int array and anonymous enum. Hopefully they will make the code cleaner.

See tikv/rust-rocksdb#682 for the companion Rust wrapper

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
// & 0b111 means find the flag location is a alternative way to do mod
// operation
GET_FLAG(flag) ^= (uint64_t)0b1 << ((uint64_t)flag & (uint64_t)0b111);
PerfFlags NewPerfFlags(std::initializer_list<PerfFlag> l) {
Copy link
Member

Choose a reason for hiding this comment

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

Could you & them? And implement + for PerfFlags at rust side.

Copy link
Author

Choose a reason for hiding this comment

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

In which use case do you think we need & perf flags? Typically, we create some PerfFlags presets to use, so I don't know when we need to combine flags.

Copy link
Member

@tabokie tabokie Apr 1, 2022

Choose a reason for hiding this comment

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

(I misread the PerfFlag as a bitmap itself.) After implementing Add<PerfFlag, Output = PerfFlags> for PerfFlag and PerfFlags, you can composing a flags at rust side instead of creating an array of flags and let RocksDB handle it.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, sounds like a good idea.

Copy link
Author

Choose a reason for hiding this comment

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

I don't modify this rocksdb PR because the C wrappers are only needed to be implemented in rust-rocksdb.

Here, the NewPerfFlags is only for convenience in rocksdb tests.

The overloaded operators are implemented in tikv/rust-rocksdb#682. Then, we can create a PerfFlags by writing PerfFlag::A | PerfFlag::B | PerfFlag::C.

PTAL

Copy link
Member

Choose a reason for hiding this comment

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

Awesome

@tabokie tabokie merged commit 9dcc333 into tikv:6.4.tikv Apr 2, 2022
@tabokie tabokie mentioned this pull request May 9, 2022
39 tasks
tabokie pushed a commit to tabokie/rocksdb that referenced this pull request May 11, 2022
This PR changes some bits of tikv#237.

Considering our use cases in TiKV, _although not really necessary_, we frequently set perf levels around RocksDB operations. So, if we switch to perf flags, it requires us to set perf flags efficiently. And we have quite a few flags to set, setting flags one by one in tikv#237 is not that efficient.

All flags can be saved in two words. So, we **can** achieve similar efficiency by setting all flags all at once. And meanwhile, we can flexibly specify which metrics we care about at runtime.

This PR also changes to use `std::bitset` and a named enum instead of handmade int array and anonymous enum. Hopefully they will make the code cleaner.

See tikv/rust-rocksdb#682 for the companion Rust wrapper

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Signed-off-by: tabokie <xy.tao@outlook.com>
tabokie pushed a commit that referenced this pull request May 11, 2022
This PR changes some bits of #237.

Considering our use cases in TiKV, _although not really necessary_, we frequently set perf levels around RocksDB operations. So, if we switch to perf flags, it requires us to set perf flags efficiently. And we have quite a few flags to set, setting flags one by one in #237 is not that efficient.

All flags can be saved in two words. So, we **can** achieve similar efficiency by setting all flags all at once. And meanwhile, we can flexibly specify which metrics we care about at runtime.

This PR also changes to use `std::bitset` and a named enum instead of handmade int array and anonymous enum. Hopefully they will make the code cleaner.

See tikv/rust-rocksdb#682 for the companion Rust wrapper

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Signed-off-by: tabokie <xy.tao@outlook.com>
v01dstar pushed a commit to v01dstar/rocksdb that referenced this pull request Feb 8, 2024
This PR changes some bits of tikv#237.

Considering our use cases in TiKV, _although not really necessary_, we frequently set perf levels around RocksDB operations. So, if we switch to perf flags, it requires us to set perf flags efficiently. And we have quite a few flags to set, setting flags one by one in tikv#237 is not that efficient.

All flags can be saved in two words. So, we **can** achieve similar efficiency by setting all flags all at once. And meanwhile, we can flexibly specify which metrics we care about at runtime.

This PR also changes to use `std::bitset` and a named enum instead of handmade int array and anonymous enum. Hopefully they will make the code cleaner.

See tikv/rust-rocksdb#682 for the companion Rust wrapper

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Signed-off-by: tabokie <xy.tao@outlook.com>
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.

3 participants