Replies: 5 comments 17 replies
|
Hello @qdegraeve, Could you share some details about the sample images you used? For example, progressive JPEGs will need a lot of memory to process. |
|
I made a tiny test program: #!/usr/bin/ruby
require 'vips'
target_width = ARGV[0].to_i
ARGV[1..].each do |filename|
thumb = Vips::Image.thumbnail(filename, target_width)
dirname = File.dirname filename
basename = File.basename filename, ".*"
output_filename = "#{dirname}/thumb_#{basename}.jpg"
puts "writing #{output_filename} ..."
thumb.write_to_file output_filename
endI used this test image (6k x 4k JPEG, 1.2mb): I made a test dataset like this: Then ran the thumbnailer like this: So it made the 19 thumbnails in 900ms and needed a peak of 98mb of memory. There's little concurrency in thumbnailing, so you can turn off the libvips threadpool and save some time and memory. This makes a relatively big difference on this PC since it has 32 hardware threads. You'll see less of a change on typical machines: 78mb peak and 600ms. If you run with no images, you can see the startup cost: So starting ruby and libvips needs 54mb and 110ms. Subtracting the two, the actual image processing is around 24mb and 500ms. |
|
I looked at the original issue more carefully and I think your graphs might not be including subprocesses, could that be correct?
You can make a little shell script that reproduces this behaviour, for example: #!/bin/bash
for filename in $*; do
echo processing $filename ...
for size in 910x650 200x150; do
convert $filename -resize ${size} $filename-$size.jpg
done
doneThe If I run that script ^^ on 15 of your test images I see: So it takes 18.5s and needs a peak of 350mb of memory ( You could speed up the One drawback of ruby-vips is that the heavy processing is happening directly in your web server process. While it's quick, this has two big downsides:
|
|
Hi @jcupitt , thanks a lot for your help and all the tips you gave me. I have try to build a docker image with your script inside and run it and there was no issue at all. The memory usage graph stayed very flat. In the meantime I saw another github thread where you said that on debian |




Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi there,
I will forward the issue I opened in the Shrine repo as it may belongs here. I was considering using ruby-vips instead of image_magick in my Rails projects to resize images but while it is super fast, the memory consumption is not at all what I expected. I'm not sure what this issue is related to so maybe anybody here will have an idea.
My leads are:
The original discussion is here => shrinerb/shrine#686
I copy here the question:
recently we tried tu move out from Imagemagick to Vips to improve performances of derivatives processing as we use it a lot.
We had great expectations but unfortunately, the result is not at all what we expected in terms of memory consumption.
While the processing speed is increased by between 5 and 10 times, the memory is increased as well by 2.
I do not have a precise measure but I have graphs that represent the same exact flow, with the same pictures (all around 5 mb) to be processed.
In the example we try to process each image, with sidekiq and a throttle configured with a concurrency of 1. There is 19 images to be processed and here are the graphs :
With VIPS
With ImageMagick
Maybe there something I miss or do not understande.
My configuration is a container build with ruby-3.2-bookworm-slim, libvips 8.15, rails 6.1 , shrine 3.4 and sidekiq 7.2
For now I will stay with ImageMagick but if you have any clue on what is happening that would be great.
Ask me if you need further details
Regards
Quentin
All reactions