Monday, July 02, 2007

Ruby: unable to extend cache

Over the weekend I used Ruby in anger for the first time.

The project was to extract JPEG images from a CD of photos I just got back from the lab. The CD has 4 rolls of 36 exposures & 2 rolls of 24 exposures on it.

I used ImageMagick’s Ruby library rmagick. Each photo was rotated (if needed), cropped, resized (for a thumbnail) and branded. So that is a couple of transitory images and two images saved back to disc.

The error text produced was ‘unable to extend cache’. I googled this and came up with four items. None of them these had a solution.

Based on the text, it was either a memory or disc space issue. So I kicked off saidar and ran the ruby code. Sure enough I watch the /tmp partition (2 GB) be steadily consumed and the run then fall over.

After digging around for anything on Ruby destructors & garbage collection, I got a break. My first lead came from a Space Babies blog post and its comments. In the comment, one of rmagick’s developers Tim Hunter refers to a 2004 Hints & Tips post titled Help! My script runs out of memory!.

After adding ‘CG.start’ into the main loop, the run didn’t go over 0.5% of the /tmp partition.

Gnoll110

Technorati tags:

No comments: