Magick.NET slows down over time while processing a large batch of images?
Posted: 2018-04-07T12:16:24-07:00
Hi,
I'm using Magick.NET-Q16-AnyCPU (7.4.3) with .NET Core 2.0, need to batch process ~25,000 images, (make square, resize to large/thumb), just using a single thread at the moment:
It processes the first 300-400 images in 10-15 seconds, but then grinds to a halt, from there on it takes up to 10s per image. All the images are of a similar size / content, the memory usage remains low so there's no leak, I just can't figure out why all of a sudden it goes slow. Tested on three different computers all with the same outcome. Does anyone know why this might be happening?
Edit: it's the Resize command that starts slowing down, for the first images:
Edit2: Ok, so when the slowdown starts imagemagick starts writing to %temp%/magick-* instead of (presumably) doing the operations in memory. Why is it doing this? The process is only using 100mb memory, the machine has 32GB memory with ~26GB free.
I'm using Magick.NET-Q16-AnyCPU (7.4.3) with .NET Core 2.0, need to batch process ~25,000 images, (make square, resize to large/thumb), just using a single thread at the moment:
Code: Select all
using (MagickImage image = new MagickImage(inputFile))
{
image.ColorFuzz = new Percentage(1);
image.Trim();
var largestDimension = Math.Max(image.Width, image.Height);
image.BackgroundColor = MagickColor.FromRgb(255, 255, 255);
image.Extent(largestDimension, largestDimension, Gravity.Center);
image.Format = MagickFormat.Jpg;
image.Quality = 65;
image.Resize(600, 600);
image.Write(largeOutputFile);
image.Resize(200, 200);
image.Write(thumbOutputFile);
}
Edit: it's the Resize command that starts slowing down, for the first images:
After ~300 images:500x331px
Trim: 2.9678ms
Extent: 4.4123ms
Large: 24.8456ms
Thumb: 14.398ms
-
500x275px
Trim: 2.5952ms
Extent: 3.477ms
Large: 17.557ms
Thumb: 13.7364ms
-
500x357
Trim: 5.8368ms
Extent: 12.1412ms
Large: 2656.029ms
Thumb: 18.721ms
-
500x298
Trim: 5.7799ms
Extent: 11.5524ms
Large: 2647.8159ms
Thumb: 22.1286ms
-
500x261
Trim: 5.9073ms
Extent: 12.3215ms
Large: 2743.2966ms
Thumb: 19.2876ms
-
Edit2: Ok, so when the slowdown starts imagemagick starts writing to %temp%/magick-* instead of (presumably) doing the operations in memory. Why is it doing this? The process is only using 100mb memory, the machine has 32GB memory with ~26GB free.