-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Optionally disable thread pools in sync::Cache
#165
Conversation
- Rename current thread-pool based `Housekeeper` to `ThreadPoolHousekeeper`. - Add `BlockingHousekeeper`. - Add `thread_pool_enabled` method to `sync::CacheBuilder`.
Update `BlockingHousekeeper` to trigger applying read and/or write operations not only when the channel len becomes long enough but also when a certain amount of time has passed.
Add `#[cfg(..)]` to some methods in `housekeeper` module to prevent compiler warnings for unused methods.
Try not to get the current time twice in a write path.
- Fix the time-interval handling in `BlockingHousekeeper`. - Add test cases to ensure the thread pools are disabled.
Fix compile errors when `default-features` is specified.
pulldown-cmark v0.9.2 requires Rust 2021 edition.
pulldown-cmark v0.9.2 requires Rust 2021 edition.
I ran a short performance test using mokabench to see if disabling the thread pools would cause performance degradation. I see no impact; hit ratio remained almost same, and the differences in duration were within ±3% (except one with +5%). |
Remove the debugging codes that were already commented out.
Revert unnecessary changes in `dash::base_cache` module.
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.
Changes needed. I will work on them tomorrow (Sunday).
@@ -64,14 +75,8 @@ impl ThreadPoolRegistry { | |||
// https://github.com/moka-rs/moka/pull/39#issuecomment-916888859 | |||
// https://github.com/seanmonstar/num_cpus/issues/69 | |||
let num_threads = num_cpus::get().max(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.
In next PR, change this to remember the value returned from num_cpus::get
(by using once_cell
for example). The value should not change during the whole application lifetime.
Run tests on CI to check if enabling/disabling the thread pools work as expected.
All tests with Rust nightly and /home/runner/.cargo/bin/rustc -V
rustc 1.64.0-nightly (4493a0f47 2022-08-02)
...
error[E0407]: method `backtrace` is not a member of trait `StdError`
Error: --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/anyhow-1.0.0/src/context.rs:136:5
|
136 | / fn backtrace(&self) -> Option<&Backtrace> {
137 | | self.error.backtrace()
138 | | }
| |_____^ not a member of trait `StdError` I will try to workaround them in tomorrow morning (UTC+0800). anyhow 1.0.60 has been yanked because it did not compile with stable compiler. NOTE: anyhow is only a dev-dependency for us. |
- Earlier versions will not compile with recent nightly compiler: rustc 1.64.0-nightly (4493a0f47 2022-08-02) - Note that the latest version of anyhow is 1.0.59.
Never mind. Raising the minimal version of a dev-dependency "anyhow" from 1.0.0 to 1.0.19 fixed the compile errors with recent nightly compilers. (The latest anyhow version is 1.0.59) |
Write the doc comment for `sync::CacheBuilder::thread_pool_enabled`.
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.
Merging.
Changes
API Changes
thread_pool_enabled
method with abool
parameter tosync::CacheBuilder
.false
, it will disable the thread pool for the housekeeper for the cache being built.Internal Changes
Housekeeper
toThreadPoolHousekeeper
.BlockingHousekeeper
.