bounded_pool_executor icon indicating copy to clipboard operation
bounded_pool_executor copied to clipboard

Speed (bounded_pool_executor slower)

Open SaschaHeyer opened this issue 5 years ago • 1 comments

Hi

do you have any idea why BoundedThreadPoolExecutor is slower as ThreadPoolExecutor? Machine has 4 CPUs ThreadPoolExecutor executor is using by default 5*CPU = 20 which equals the BoundedThreadPoolExecutor max_workers.

Before

with concurrent.futures.ThreadPoolExecutor() as executor:
        future_to_feature = {executor.submit(extract_features, filename): filename for filename in files}
        for future in concurrent.futures.as_completed(future_to_feature):
        ...

After

with BoundedThreadPoolExecutor(max_workers=20) as worker:
    for file in files:
    ...

SaschaHeyer avatar Aug 26 '20 08:08 SaschaHeyer

Hello, i'm not the owner of this repository but this is totally normal, what happens is that unlike ThreadPoolExecutor, BoundedPoolExecutor will only put a net worker when another one is finished, this avoid the memory leaking problem that ThreadPoolExecutor still has, so you wan't to make sure that all the workers finish as soon as possible, if you have some kind of timeout in your function for example make sure to put it as low as you can.

GabrielBigardi avatar Aug 20 '21 12:08 GabrielBigardi