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

Use std::thread::available_parallelism() instead of num_cpus dependency #257

Closed
tatsuya6502 opened this issue Apr 23, 2023 · 0 comments · Fixed by #277
Closed

Use std::thread::available_parallelism() instead of num_cpus dependency #257

tatsuya6502 opened this issue Apr 23, 2023 · 0 comments · Fixed by #277
Milestone

Comments

@tatsuya6502
Copy link
Member

We might want to replace a dependency num_cpus crate with std::thread::available_parallelism() once we update moka's minimum supported Rust version (MSRV) to Rust 1.64.

  • std::thread::available_parallelism() function was added to Rust 1.59.0.
    • But Linux cgroup v2 support was added to the function in Rust 1.61.0.
    • And Linux cgroup v1 support was added to the function in Rust 1.64.0.

See rayon-rs/rayon#937 for details.

Without Linux cgroup v1/v2 support, available_parallelism() will ignore the CPU quota provided by a Linux container runtime such as Docker.

Rust 1.64.0 was released on September 22, 2022. It was 7 months ago from now and our MSRV policy already allows Rust 1.64.0.

https://github.com/moka-rs/moka/#minimum-supported-rust-versions

It will keep a rolling MSRV policy of at least 6 months.

As of moka v0.10, it uses num_cpus to decide the number of global worker threads. In the future, we will remove the worker threads, but we will start to use it to decide the number of the internal hash table segments.

@tatsuya6502 tatsuya6502 added this to the v0.11.2 milestone Jun 3, 2023
tatsuya6502 added a commit that referenced this issue Jun 6, 2023
- Replace `num_cpus::get()` with `std::thread::available_concurrency()` introduced
  in Rust 1.59.0.
- NOTE: `available_concurrency()` requires Rust 1.64.0 or newer to work reliably in
  some Linux container environment. #257
tatsuya6502 added a commit that referenced this issue Jun 6, 2023
- Replace `num_cpus::get()` with `std::thread::available_concurrency()` introduced
  in Rust 1.59.0.
- NOTE: `available_concurrency()` requires Rust 1.64.0 or newer to work reliably in
  some Linux container environment. #257
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 a pull request may close this issue.

1 participant