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

Implement a threadpool for faster builds. #282

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aebrahim
Copy link

Fixes #225

Uses 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.

In my experience on a 4 core/8 thread system, this optimization halves my build times.

@aebrahim
Copy link
Author

I don't really know ruby (this is my first ruby PR) so please review carefully!

@rbuchberger
Copy link
Owner

This is amazing work, thank you! I've been wanting this forever.

I'm out of town on a work trip at the moment so I can't easily pull it down and test it, but I'll get back to you as soon as I can once I get a chance to.

aebrahim added a commit to aebrahim/jekyll_picture_tag that referenced this pull request Sep 22, 2022
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.
@aebrahim
Copy link
Author

Thanks so much! I have 2 versions, this one and #283 - both of which do the same thing but in different ways

@rbuchberger
Copy link
Owner

@aebrahim - you mind if I go ahead and merge this version, then replace it if we get the global thread pool working?

@aebrahim
Copy link
Author

Sounds good to me!

@antoinevth
Copy link

Using JPT for an image-heavy website, I was really pleased to see this PR. I've tried to use it, but I came across this error:

/usr/share/gems/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/abstract_executor_service.rb:88:in `block in fallback_action': Concurrent::RejectedExecutionError (Concurrent::RejectedExecutionError)
	from /usr/share/gems/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/executor/ruby_executor_service.rb:27:in `post'
	from /usr/share/gems/bundler/gems/jekyll_picture_tag-4c4b75ff77c7/lib/jekyll_picture_tag/srcsets/basic.rb:82:in `block in build_files'
	from /usr/share/gems/bundler/gems/jekyll_picture_tag-4c4b75ff77c7/lib/jekyll_picture_tag/srcsets/basic.rb:81:in `each'
	from /usr/share/gems/bundler/gems/jekyll_picture_tag-4c4b75ff77c7/lib/jekyll_picture_tag/srcsets/basic.rb:81:in `build_files'
	from /usr/share/gems/bundler/gems/jekyll_picture_tag-4c4b75ff77c7/lib/jekyll_picture_tag/srcsets/basic.rb:31:in `files'
	from /usr/share/gems/bundler/gems/jekyll_picture_tag-4c4b75ff77c7/lib/jekyll_picture_tag/srcsets/basic.rb:35:in `to_a'
	from /usr/share/gems/bundler/gems/jekyll_picture_tag-4c4b75ff77c7/lib/jekyll_picture_tag/srcsets/basic.rb:39:in `to_s'
	from /usr/share/gems/bundler/gems/jekyll_picture_tag-4c4b75ff77c7/lib/jekyll_picture_tag/output_formats/basic.rb:57:in `add_srcset'
	from /usr/share/gems/bundler/gems/jekyll_picture_tag-4c4b75ff77c7/lib/jekyll_picture_tag/output_formats/picture.rb:39:in `build_source'
	from /usr/share/gems/bundler/gems/jekyll_picture_tag-4c4b75ff77c7/lib/jekyll_picture_tag/output_formats/picture.rb:26:in `block in build_sources'
	from /usr/share/gems/bundler/gems/jekyll_picture_tag-4c4b75ff77c7/lib/jekyll_picture_tag/output_formats/picture.rb:26:in `collect'
	from /usr/share/gems/bundler/gems/jekyll_picture_tag-4c4b75ff77c7/lib/jekyll_picture_tag/output_formats/picture.rb:26:in `build_sources'
	from /usr/share/gems/bundler/gems/jekyll_picture_tag-4c4b75ff77c7/lib/jekyll_picture_tag/output_formats/picture.rb:66:in `base_markup'
	from /usr/share/gems/bundler/gems/jekyll_picture_tag-4c4b75ff77c7/lib/jekyll_picture_tag/output_formats/basic.rb:10:in `to_s'
	from /usr/share/gems/bundler/gems/jekyll_picture_tag-4c4b75ff77c7/lib/jekyll_picture_tag.rb:71:in `render'

I've also tried using concurrent-ruby in it's 1.1.10 version with no luck. I don't know how I could fix this issue, as I've never developed in Ruby... @aebrahim, have you used this implementation recently ?

@rbuchberger
Copy link
Owner

@antoinevth - Sorry it's not in a working state! This has been on the back burner a bit for me, but you're not the first one to mention how useful this would be. I'll try and find time to get it working, though no promises.

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

Successfully merging this pull request may close these issues.

Thread pools for faster builds?
3 participants