-
Notifications
You must be signed in to change notification settings - Fork 106
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
Implement a global threadpool for faster builds. #283
base: master
Are you sure you want to change the base?
Conversation
Fixes rbuchberger#225 This implements a global Concurrent::ThreadPoolExecutor from concurrent-ruby to avoid memory blowup, and de-duplicates files before generation so we no longer need to rely on filesystem consistency to avoid double-generating images. This is an alternate to rbuchberger#282 with a litle bit more complexity, but with the added benefits that all image generation can happen in a single ThreadPool.
This is amazing work! It's not so complicated considering the benefits it provides. I like this version better, though it might be worth testing a few builds to make sure it's faster by enough to justify the added complexity. I'm still on a work trip, get home Saturday, so the earliest I can pull this down and test it will be monday. Just from reading, my initial criticism is I don't super like the The tests on this project are a bit of a hot mess (sorry about that, I had learning to do), but I'd like to see a few tests of this behavior as well. I can handle that part if you're not up for it. We should also add a configuration option to disable it, in case someone has issues. (This code gets run in all sorts of weird environments) Again, thank you so much! this is as big of an improvement as switching from imagemagick to libvips, which was huge. |
Instead, we add a wait method, and ensure unit tests call wait before checking for expectations. This involved a litle bit of refactoring to have all tests call wait in the before_teardown hook.
Thanks for the kind words @rbuchberger! And thanks for this package - it's so useful! I refactored the tests so I could remove |
If I could request one quick improvement, as someone who's dorked around with threading this in the past for performance (your method is better than mine, for sure!): Can the number of parallel threads be configurable in the config files somewhere? Or, if it already is, document how to adjust it. I use some systems that are high on CPU count to RAM ratios (one of my little ARM boxes is 6C/4GB), and some of the resizes can use enough RAM to really choke the rest of the system out. Thanks! |
This approach does not seem to actually work - it still creates one threadpool per tag. Back to the drawing board for a bit to make it a full global |
That's right - every There's a |
I the code working by changing
However, I'm having a lot of trouble testing it like that. The hardest part for me has been figuring out how to stub an option globally - I added a |
@aebrahim - We're out of my area of experience here - I've never played with multithreaded Ruby code. Closest I've gotten is asynchronous javascript. Our tests are synchronous, so would calling Edit: I commented before reading your new commit, looks like that's pretty much what you're doing. Hmm, I'll have to do some learning here |
I suspect most of my problems are coming from trying to read parameters. Maybe I will update this to remove all the parameter reading code and see if I can get tests to pass that way, and then leave it for someone else to figure out how to read parameters? WDYT? |
Hmm... Not sure I follow - which parameters do you mean? |
Fixes #225
This implements a global
Concurrent::ThreadPoolExecutor
from concurrent-ruby to avoid memory blowup, and de-duplicates files before generation so we no longer need to rely on filesystem consistency to avoid double-generating images.This is an alternate to #282 with a little bit more complexity, but with the added benefits that all image generation can happen in a single
ThreadPoolExecutor
.