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

vips_concurrency_set analog #425

Open
q3cpma opened this issue Sep 22, 2023 · 5 comments
Open

vips_concurrency_set analog #425

q3cpma opened this issue Sep 22, 2023 · 5 comments

Comments

@q3cpma
Copy link

q3cpma commented Sep 22, 2023

Hello, is there a way to limit concurrency from within a pyvips using process? I'll probably need it to do process based SMP instead of using internal threads.

Sorry in advance if it's right under my eyes, but perusing the documentation didn't help.

@jcupitt
Copy link
Member

jcupitt commented Sep 22, 2023

You can set the env var VIPS_CONCURRENCY to set the threadpool size.

Though libvips will automatically size down threadpools if the host machine becomes overloaded (ie. VIPS_CONCURRENCY really sets the maximum threadpool size), so it may be unnecessary.

@q3cpma
Copy link
Author

q3cpma commented Sep 22, 2023

I see, the variable is read only during module import, right? At least my experimentation says so.

About the self-balancing, does it use load average or something else? Interesting feature.

@jcupitt
Copy link
Member

jcupitt commented Sep 22, 2023

That's true, just on import. It's a single per-process setting.

You can also set concurrency on an image, then downstream processing on that image will use that setting.

The adaptive pool sizing works by counting blocked threads. If a thread stops on a mutex, it looks up its threadpool and increments an "n-blocked-threads" counter on the pool. The thread work unit dispatcher watches this variable and (with a bit of hysteresis) sizes the pool up and down so that only a few threads are blocked. Pools starts off with concurrency / 2 workers, then either grow or shrink depending on the workload.

Pools generally size on IO, but they'll size on system load too, since a heavily loaded system will tend to leave workers blocked.

@jcupitt
Copy link
Member

jcupitt commented Sep 22, 2023

You can see the sizing like this:

$ vips copy st-francis.jpg x.jpg --vips-info
VIPS-INFO: 12:47:28.607: threadpool completed with 4 workers

That's very IO bound, so the pool is small (this PC has 32 hardware threads).

If I do something with more CPU load, the pool sizes larger:

$ vips gaussblur st-francis.jpg x.jpg 20 --vips-info
VIPS-INFO: 12:49:28.429: gaussblur mask width 71
VIPS-INFO: 12:49:28.429: threadpool completed with 2 workers
VIPS-INFO: 12:49:28.429: threadpool completed with 2 workers
VIPS-INFO: 12:49:28.429: threadpool completed with 2 workers
VIPS-INFO: 12:49:28.430: threadpool completed with 2 workers
VIPS-INFO: 12:49:28.432: convi: using C path
VIPS-INFO: 12:49:28.432: threadpool completed with 2 workers
VIPS-INFO: 12:49:28.432: threadpool completed with 1 workers
VIPS-INFO: 12:49:28.432: threadpool completed with 1 workers
VIPS-INFO: 12:49:28.433: threadpool completed with 1 workers
VIPS-INFO: 12:49:28.435: convi: using vector path
VIPS-INFO: 12:50:06.403: threadpool completed with 32 workers

@q3cpma
Copy link
Author

q3cpma commented Sep 22, 2023

Thanks for the detail.

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