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

Optionally disable thread pools in sync::Cache #165

Merged
merged 17 commits into from
Aug 3, 2022

Conversation

tatsuya6502
Copy link
Member

Changes

API Changes

  • Add thread_pool_enabled method with a bool parameter to sync::CacheBuilder.
    • If called with false, it will disable the thread pool for the housekeeper for the cache being built.

Internal Changes

  • Rename current thread-pool based Housekeeper to ThreadPoolHousekeeper.
  • Add BlockingHousekeeper.

- Rename current thread-pool based `Housekeeper` to `ThreadPoolHousekeeper`.
- Add `BlockingHousekeeper`.
- Add `thread_pool_enabled` method to `sync::CacheBuilder`.
@tatsuya6502 tatsuya6502 added the enhancement New feature or request label Jul 9, 2022
@tatsuya6502 tatsuya6502 added this to the v0.9.1 milestone Jul 9, 2022
@tatsuya6502 tatsuya6502 self-assigned this Jul 9, 2022
@tatsuya6502 tatsuya6502 modified the milestones: v0.9.1, v0.9.2, v0.9.3 Jul 16, 2022
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.
@tatsuya6502
Copy link
Member Author

tatsuya6502 commented Jul 30, 2022

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.
Copy link
Member Author

@tatsuya6502 tatsuya6502 left a 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);
Copy link
Member Author

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.

src/sync/builder.rs Outdated Show resolved Hide resolved
src/sync/cache.rs Show resolved Hide resolved
Run tests on CI to check if enabling/disabling the thread pools work
as expected.
@tatsuya6502
Copy link
Member Author

tatsuya6502 commented Aug 3, 2022

All tests with Rust nightly and cargo update -Z minimal-versions are failing now. It seems anyhow 1.0.0 no longer compiles with recent nightly compilers.

/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. But maybe 1.0.60 is the only version that will compile with recent nightly compilers?

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.
@tatsuya6502
Copy link
Member Author

But maybe 1.0.60 is the only version that will compile with recent nightly compilers?

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`.
Copy link
Member Author

@tatsuya6502 tatsuya6502 left a comment

Choose a reason for hiding this comment

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

Merging.

@tatsuya6502 tatsuya6502 marked this pull request as ready for review August 3, 2022 23:51
@tatsuya6502 tatsuya6502 merged commit 7805070 into master Aug 3, 2022
@tatsuya6502 tatsuya6502 deleted the disable-housekeeper-threads branch August 3, 2022 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant