-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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 Polars ThreadPool #1927
Use Polars ThreadPool #1927
Conversation
🙌 |
Is there a flag / option to prevent implicit (accidental) pool creation in Rayon? |
Don't know.. It would be beneficial indeed. |
Maybe calling https://docs.rs/rayon/1.0.0/rayon/struct.ThreadPoolBuilder.html#method.build_global at the tests teardown would help this (it fails if global threadpool exists) |
It's a smart idea. However it requires to run tests that shouldn't be run (in PR for example) for the moment because That's a little bit tricky 🤪 |
This might be even better. Drop the polars threadpool in teardown and if miri complains after the test, the global threadpool was initialized. I'm not sure what issues miri has right now, but if it's about lingering threads after test run, then this might work. |
How to drop the Polars ThreadPool ? |
I didn't use it before, but maybe https://docs.rs/rayon/1.5.1/rayon/struct.ThreadPool.html#impl-Drop?
|
From what I understand, the ThreadPool is declared static as it can be seen here: polars/polars/polars-core/src/lib.rs Line 28 in fafde8d
Therefore it can't be dropped. I don't know if it is possible to change that in Polars and be able to manipulate the ThreadPool for the tests with those tricks while keeping an optimized behavior for the usual crate usage. |
Would it help if instead of using the lazy_static! {
pub static ref REG: Arc<Registry> = Arc::new(Registry::new(ThreadPoolBuilder::new()
.num_threads(
std::env::var("POLARS_MAX_THREADS")
.map(|s| s.parse::<usize>().expect("integer"))
.unwrap_or_else(|_| num_cpus::get())
))?);
} and then we'd be able to create the POOL as |
It is difficult for me to understand how or why it would work. I don't think so but I might be wrong. Do not hesitate to test the code yourself to achieve a complete implementation of your idea, the Rust compiler will help you. |
@ibENPC you are right, |
@alippai thank you for the work, the problem is clearer. If we run the tests sequentially we might find a solution by using an unsafe modification of POOL or another unsafe method. Otherwise it seems to imply a random game with data races 🤪 @ritchie46 Is it a problem to use
I can open an issue if you think that the discussion is worth it. |
IMO it doesn't matter that miri doesn't run for all tests. If it can do that one day, great. But I don't want to reduce perf, so we can run a test. |
As mentioned here: #1925 (comment)