• Logged in as geography
  • Last visit: Today 21:29:23

#1 Yesterday 20:47:30

geography
Member
From: NYC
Registered: 2005-03-17
Posts: 10
E-mail  Website

Lighttpd says Insufficient memory (case 4)

I have a rails app that downloads images found on the web. I'm running it through lighttpd and everything works fine unless it is a large image (Like over 500k).

Then lighttpd throughs this error:

Insufficient memory (case 4)

Has anyone else encountered this? What exactly could be the root of this error?

Online

#2 Yesterday 22:06:50

jqshenker
Member
From: Palo Alto, CA
Registered: 2005-09-06
Posts: 422
E-mail  Website

Re: Lighttpd says Insufficient memory (case 4)

Yeah, it's the limits. Are you downloading it, or resizing it as well? Downloading usually isn't the problem, it's the resizing that breaks.

Offline

#3 Yesterday 22:12:28

julik
Member
From: Utrecht, Netherlands
Registered: 2005-03-12
Posts: 137
E-mail  Website

Re: Lighttpd says Insufficient memory (case 4)

that doesn't feel well

Online

#4 Today 03:46:42

geography
Member
From: NYC
Registered: 2005-03-17
Posts: 10
E-mail  Website

Re: Lighttpd says Insufficient memory (case 4)

I'm resizing it too. But that is not where it dies.
It dies right before I write it to disk (With Magick::Image.write from RMagick)

Online

#5 Today 04:14:08

jqshenker
Member
From: Palo Alto, CA
Registered: 2005-09-06
Posts: 422
E-mail  Website

Re: Lighttpd says Insufficient memory (case 4)

geography wrote:

I'm resizing it too. But that is not where it dies.
It dies right before I write it to disk (With Magick::Image.write from RMagick)


I meant "resizing" as anything to do with RMagick. There've been a couple threads on this, search around. Resizing you image before upload or not using RMagick and instead using ImageMagick via the commandline might or might not work.... basically you can't do much, unfortunately.

Offline

#6 Today 04:17:28

cch
Member
Registered: 2005-03-21
Posts: 108
E-mail

Re: Lighttpd says Insufficient memory (case 4)

what if you use open(fname, 'w'){|f|f.write img.to_blob} ?

Offline

#7 Today 15:44:42

geography
Member
From: NYC
Registered: 2005-03-17
Posts: 10
E-mail  Website

Re: Lighttpd says Insufficient memory (case 4)

Using open(fname, 'w'){|f|f.write img.to_blob} has the same problem... I guess I'll try and run it from the command line but that seems like a drastic step. Why is the memory so limited, shouldn't the server be able to save 500k files, or does imageMagick have a very high overhead?

Online

#8 Today 17:03:28

jqshenker
Member
From: Palo Alto, CA
Registered: 2005-09-06
Posts: 422
E-mail  Website

Re: Lighttpd says Insufficient memory (case 4)

RMagick does leak memory in some versions (there's a patched version of file_column which resizes via the commandline), but I'm not sure why you can't resize larger images. It doesn't take that much memory.

Offline

#9 Today 19:04:21

geography
Member
From: NYC
Registered: 2005-03-17
Posts: 10
E-mail  Website

Re: Lighttpd says Insufficient memory (case 4)

So what i've learned so far...

TextDrive has a memory limit.
-When using RMagick in a rails app running with fcgi and lighttpd this memory limit is exceeded.
-When the memory limit is exceeded the fcgi process is killed (No expcetions caught or anything in Ruby... the process ends)
-The problem occurs when writing images to disk (With either File.open or Image.write)
-The problem still occurs if I call GC.starts after RMagick calls

Here is what I don't get...
-Why is the memory limit so low (Or why does a simple RMagick call take up so much memory? My dispatch procs take up around 50 megs, I can't imagine that opening a 600k file would come close to using that much memory)
-Would putting my RMagick code in a different thread allow me to have more memory at my disposal?

Online

#10 Today 19:29:11

cch
Member
Registered: 2005-03-21
Posts: 108
E-mail

Re: Lighttpd says Insufficient memory (case 4)

the memory limit is 100mb.

watch your process as you make the upload to see how high it goes. also try resizing an image using a standalone (no rails) ruby script and see how much memory it uses this way.

Offline

#11 Today 21:13:19

geography
Member
From: NYC
Registered: 2005-03-17
Posts: 10
E-mail  Website

Re: Lighttpd says Insufficient memory (case 4)

So after some investigation it seems like RMagick is a total memory hog.

I load a 750k image with this tiny standalone ruby program...

image = nil
open(filepath) do |f|

image = Magick::Image.from_blob(f.read).first
end
image.write("image.jpg")

Monitoring the mem usage (using top) I get this 8th column is mem usuage

#File being downloaded
7198 ruby 7.6% 0:04.83 2 15 60 3.37M+ 2.65M 4.88M+ 44.5M+
7198 ruby 14.4% 0:05.01 2 15 68 18.1M+ 2.73M+ 20.0M+ 80.9M+
7198 ruby 35.0% 0:05.49 2 15 67 41.8M+ 2.73M 43.7M+ 80.8M-

#File being loading into Magick::Image
7198 ruby 0.1% 0:05.49 2 15 67 41.8M 2.73M 43.7M 80.8M-
7198 ruby 0.1% 0:05.49 2 15 67 41.8M 2.73M 43.7M 80.8M-

#File being written to disk
7198 ruby 3.4% 0:05.53 2 15 72 43.4M+ 2.73M 45.3M+ 122M+
7198 ruby 55.9% 0:06.29 2 15 72 61.1M+ 2.73M 63.0M+ 122M
7198 ruby 48.4% 0:06.93 2 15 72 76.1M+ 2.73M 78.1M+ 122M
7198 ruby 48.2% 0:07.55 2 15 67 42.5M- 2.73M 44.4M- 80.8M-

So I guess the moral is RMagick eats up a ton of memory. I can't really see anyway around this problem though, maybe using the command line would eat up less memory (which is what I'll try next)

Last edited by geography (Today 21:29:17)

Online

#12 Today 21:55:36

cch
Member
Registered: 2005-03-21
Posts: 108
E-mail

Re: Lighttpd says Insufficient memory (case 4)

Yea, now you have to know whether it's RMagick specifically, or ImageMagick itself that is a memory hog.

I suppose it goes memory hungry because it expands a full uncompressed 24bit bitmap to memory, and that's innevitably large. (entirely uninformed hunch)

There's ruby-GD as an alternative, but it doesn't look nearly as nice, and I've never used it, and I don't know if it'd be more or less of a hog.

Last edited by cch (Today 21:56:17)

Offline

Quick post

Write your message and submit keeping in mind that this is not an official support forum.

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson