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

Defining the amount of threads in use for sync functions #19

Closed
ivergara opened this issue Oct 1, 2019 · 3 comments
Closed

Defining the amount of threads in use for sync functions #19

ivergara opened this issue Oct 1, 2019 · 3 comments

Comments

@ivergara
Copy link

ivergara commented Oct 1, 2019

How is the number of threads launched for an asynchronous function being decorated with unsync? Is there a possibility to define that number? If it's not possible out of the box, how could I start approaching that?

@alex-sherman
Copy link
Owner

alex-sherman commented Oct 1, 2019

The async loop runs in a single thread and "regular" functions decorated with @unsync without setting cpu_bound = True will run in a ThreadPoolExecutor.

Assuming your referring to the later, without any arguments ThreadPoolExecutor will overprovision (see max_workers) in Python 3.5 and later, creating 5 threads per core. If that's insufficient I think you can just overwrite unsync.thread_executor = concurrent.futures.ThreadPoolExecutor(max_workers = 9000).

I'm curious what your workload is that would you would notice this, is it really doing hundreds of IO bound operations?

@ivergara
Copy link
Author

ivergara commented Oct 1, 2019

Thanks for the answer. Indeed it was the later.

I'm not noticing it at the moment, but I was preemptively wondering how to control the number of threads, particularly at different steps. For example, due to a limitation on external resources, I could be limited by the number of threads accessing that resource but then local downstream processing could benefit from more threads.

@alex-sherman
Copy link
Owner

Makes sense. I'll close this for now since I think just assigning over unsync.thread_executor will cover your scenario.

Feel free to reopen, or open a PR if you'd like to add a cleaner API or something for setting the number of threads. My own opinion is that a function like unsync.set_max_thread_workers(n) is less clean than just assigning to thread_executor.

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

No branches or pull requests

2 participants