-
-
Notifications
You must be signed in to change notification settings - Fork 700
Revised threading system #3105
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
Revised threading system #3105
Conversation
just a set of threads that get recycled "ninja test" passes and dzsave seems to work, though pytest fails for some reason
move base stuff into thread.c, so we have a simple thread -> threadset -> threadpool layering
based on the original commit
so threadpool.c is now up to date
a bit less confusing
based on counting the number of blocked threads in each pool it works, but the improvement is not great :(
so operators can hint threadpool size (dzsave especially)
since flatten was taking 20% of CPU time for dzsave
now actually works
in the new openslideload rgb mode
oops, turned it off by mistake
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! I left some comments inline and was able to resolve the LSan CI failures by adding libMagickCore to the suppression file (commit kleisauke@5338676). The sink->sslock
also no longer seems necessary after this (commit kleisauke@b584140).
I had a quick go to test this implementation in wasm-vips, see commit kleisauke/wasm-vips@da8956e. The trick there is to initialize a fixed thread pool during vips_threadset_new()
and not let vips_threadset_run()
spawn more threads, see the corresponding patch and branch. Though, this didn't seem to work, it somehow exhausts the fixed thread pool. I'll investigate.
Co-authored-by: Kleis Auke Wolthuizen <github@kleisauke.nl>
Co-authored-by: Kleis Auke Wolthuizen <github@kleisauke.nl>
This reverts commit 4144049.
I confirm that fixes it.
Thanks! For Wasm, it needs to setup the fixed threadpool during wasm-vips had previously reverted commit 6946c3b for this purpose, but that probably wouldn't work on macOS, where we need to delay setting up the threadpool to ensure I wonder if we should expose Note that running the wasm-vips test suite still seems to exhaust the fixed threadpool, see for example this run: I'm not sure what's causing this, the previous GLib threadpool implementation didn't had this issue. It can be reproduced by running the test suite on the $ export VIPS_MAX_THREADS="$(($(nproc) + 3))"
$ echo $VIPS_MAX_THREADS
9 (+3 is the amount of background threads required by |
Ah, according to the |
Hooray!
Ah I wasn't sure, OK, let's move it. I hoped to delay making the threads until first use to help systems like macOS, but it sounds like that's not possible (or useful).
I was thinking it would be handy for testing, but you're right, not useful for most people outside wasm. We can leave it undocumented and unsupported.
I think it's two, isn't it? There's one thread for each of the two write behind buffers, plus the main thread (which we don't count). I see:
So concurrency 3 runs with six threads: 3 workers, 2 write-behind, one main thread. |
not first use
Perhaps we should add a queue like this to threadset? At the moment it just hard fails. Though I think there's maybe a danger of deadlock, ouch. |
Oh huh, perhaps I miscounted. Though, this one seems to fail. $ vips black x.jpg 100 100
$ VIPS_MAX_THREADS=5 VIPS_CONCURRENCY=3 vips autorot x.jpg x2.jpg
VipsThreadset: threadset is exhausted Commit kleisauke@a11afaa on the
Deadlocks are indeed the symptoms when things don't work out. For example, I also had to apply commit kleisauke@6100d34 and needed to configure libwebp with |
I think that example is running two pipelines:
Some libvips threads are optional (eg. when it tries to expand a threadpool), but some must happen or we'll deadlock (eg. it must have a thread watching a write-behind buffer). We could add API for the optional case. It'd make it a bit more robust against threadset exhaustion. |
Ah, you're right. libvips/libvips/convolution/gaussblur.c Line 129 in ea0912f
I've clarified with commit kleisauke/wasm-vips@acbfff6 why the +3 is needed.
GLib threadpool's uses the It's a bit unfortunate that WebAssembly has this limitation. :( |
and move the test tmp/ area into the builddir
I think we're done, let's merge and try living with it for a bit. Thank you very much for reviewing this thing! |
Upstream-Status: Inappropriate [Emscripten specific]
FWIW, I implemented this with commit kleisauke@fe02527 for wasm-vips (only the changes in VIPS_MAX_THREADS="$(($(nproc) + 3))" I'm not sure if it's worth upstreaming that, since it could easily deadlock when being used in combination with |
Oh, interesting. It'd be great if we could upstream everything and have wasm as a fully supported target. Maybe we could hide the extra code behind ifdef WASM? I suppose the downside is that libvips would then have code that was difficult to test, and added maintenance effort. What do you think? |
I'd like to officially support Wasm as a supported target in libvips. Indeed, you can just Unfortunately, the main blocker for this is GLib, see for example: I suppose this should be discussed in GLib first, especially commit kleisauke/glib@4ed9ec0 (since that would cause an ABI break). GLib currently deliberately ignores the For this reason, I marked the GLib patches as stalled in the "Upstream patches" item at Stable release for wasm-vips, but hopefully I can revisit that in the future. |
Ah I see. They would really hate an ABI break, but I can see it might be worthwhile to open a discussion about it and raise the issue. They might want to delay for glib-3.0. I did a quick search and couldn't see a statement from the glib maintainers on emscripten support. If they've not taken an official position, perhaps opening a PR with that change would be useful? |
I mentioned the patches and my intention to upstream them in this comment, but I plan to discuss this also on GNOME's Discourse instance (using the Though, perhaps I should check the /cc @RReverser you might also be interested in this. |
Ah sensible, yes I remember that PR being closed without comment. How can a PR not be actionable? Ah well. Sure, discourse is maybe a better place to start discussion. Please post a link here, I'd be interested to read. |
Fixes a regression introduced in commit 9248ab7 (PR libvips#3105).
Fixes a regression introduced in commit 9248ab7 (PR libvips#3105).
Fixes a regression introduced in commit 9248ab7 (PR libvips#3105).
Fixes a regression introduced in commit 9248ab7 (PR libvips#3105).
done:
todo: