The Joyent Community

A place where the Joyent community can gather, help each other out, and stay informed.

You are not logged in.

#1 2005-11-19 20:47:30

geography
New member
From: NYC
Registered: 2005-03-17
Posts: 13
Website  Expertise

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?

Offline

 

#2 2005-11-19 22:06:50

jqshenker
Member
From: Palo Alto, CA
Registered: 2005-09-06
Posts: 721
Website  Expertise

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.


~Jacob

Offline

 

#3 2005-11-19 22:12:28

julik
Member
From: Utrecht, Netherlands
Registered: 2005-03-12
Posts: 224
Website  Expertise

Re: Lighttpd says Insufficient memory (case 4)

that doesn't feel well

Offline

 

#4 2005-11-20 03:46:42

geography
New member
From: NYC
Registered: 2005-03-17
Posts: 13
Website  Expertise

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)

Offline

 

#5 2005-11-20 04:14:08

jqshenker
Member
From: Palo Alto, CA
Registered: 2005-09-06
Posts: 721
Website  Expertise

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.


~Jacob

Offline

 

#6 2005-11-20 04:17:28

cch
Member
Registered: 2005-03-21
Posts: 675
Website  Expertise

Re: Lighttpd says Insufficient memory (case 4)

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

Offline

 

#7 2005-11-20 15:44:42

geography
New member
From: NYC
Registered: 2005-03-17
Posts: 13
Website  Expertise

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?

Offline

 

#8 2005-11-20 17:03:28

jqshenker
Member
From: Palo Alto, CA
Registered: 2005-09-06
Posts: 721
Website  Expertise

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.


~Jacob

Offline

 

#9 2005-11-20 19:04:21

geography
New member
From: NYC
Registered: 2005-03-17
Posts: 13
Website  Expertise

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?

Offline

 

#10 2005-11-20 19:29:11

cch
Member
Registered: 2005-03-21
Posts: 675
Website  Expertise

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 2005-11-20 21:13:19

geography
New member
From: NYC
Registered: 2005-03-17
Posts: 13
Website  Expertise

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 (2005-11-20 21:29:17)

Offline

 

#12 2005-11-20 21:55:36

cch
Member
Registered: 2005-03-21
Posts: 675
Website  Expertise

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 (2005-11-20 21:56:17)

Offline

 

#13 2005-11-20 22:23:29

jqshenker
Member
From: Palo Alto, CA
Registered: 2005-09-06
Posts: 721
Website  Expertise

Re: Lighttpd says Insufficient memory (case 4)

ImageMagick isn't a memory hog (or not as much of one, at least). RMagick is. GD might take more, definitely not a solution. The lightest-weight out of all of the image processing libraries is probably Imlib2 (has mature Ruby bindings, too, I think) but I'm not sure it's installed at TxD because it does require some X libs unfortunately.

Your best bet is probably to manipulate the files via ImageMagik's commandline tools.


~Jacob

Offline

 

#14 2005-11-21 22:41:44

Jan
Joyeur Emeritus
Registered: 2004-06-01
Posts: 3081
Website  Expertise

Re: Lighttpd says Insufficient memory (case 4)

I see the problem as a very simple one. IMO, things like image processesing should be done with local resources. Shared hosting resources are not dedicated shell resources and should not be treated as such.


Ah, you seek meaning? Then listen to the music, not the song.

Offline

 

#15 2005-11-21 23:38:03

rainbowsheep
Member
Registered: 2005-01-15
Posts: 584
Expertise

Re: Lighttpd says Insufficient memory (case 4)

So we can't have a website that lets a user uploads a image and create a thumbnail out of it?

Offline

 

#16 2005-11-22 00:44:38

Jan
Joyeur Emeritus
Registered: 2004-06-01
Posts: 3081
Website  Expertise

Re: Lighttpd says Insufficient memory (case 4)

Not if it requires hundred(s) megabytes of RAM and most of a CPU, no. I am not unsympathetic, but expectations have to meet reality somewhere. It also happens that some of these image manipulation programs are notorious for causing CPU panics.


Ah, you seek meaning? Then listen to the music, not the song.

Offline

 

#17 2005-11-22 13:08:58

julik
Member
From: Utrecht, Netherlands
Registered: 2005-03-12
Posts: 224
Website  Expertise

Re: Lighttpd says Insufficient memory (case 4)

Jan wrote:

I see the problem as a very simple one. IMO, things like image processesing should be done with local resources.


Baking cached thumbnails from admin uploads is an essential feature requirement of 9 out of 10 CMS orders a developer might recieve. People need this and there is nothing abnormal about resource use. It has never been a problem with PHP (i have been doing this on 4 hosts for 3 years).

Offline

 

#18 2005-11-22 17:11:50

rainbowsheep
Member
Registered: 2005-01-15
Posts: 584
Expertise

Re: Lighttpd says Insufficient memory (case 4)

Well, the obvious thing to do here is notify the RMagick developers, which I've done. Perhaps it's a configuration issue.

Offline

 

#19 2005-11-22 22:45:54

jqshenker
Member
From: Palo Alto, CA
Registered: 2005-09-06
Posts: 721
Website  Expertise

Re: Lighttpd says Insufficient memory (case 4)

rainbowsheep wrote:

Well, the obvious thing to do here is notify the RMagick developers, which I've done. Perhaps it's a configuration issue.


I doubt it. It's just RMagick gobbles up memory needlessly (it has an awesome API, though!). I do hope they fix it, because it's a joy to use.


~Jacob

Offline

 

#20 2005-11-22 23:04:01

rmagick
New member
Registered: 2005-11-22
Posts: 2
Expertise

Re: Lighttpd says Insufficient memory (case 4)

I don't normally visit this forum but Joe mentioned this thread to me.

Background: ImageMagick requires a little over 4 bytes/pixel to represent an image if it (ImageMagick) has been configured with QuantumDepth=8, or 8 bytes/pixel if it has been configured with QuantumDepth=16. So an image from my 4megapixel camera needs 16 or 32Mb.

Two things:

1. Is ImageMagick built with QuantumDepth=16 or QuantumDepth=8? If 16, and you don't need 16-bit pixels, then ImageMagick is using twice as much memory as necessary and almost twice as much CPU. Unless you need 16-bit pixels, configure ImageMagick using --with-quantum-depth=8. (--with-quantum-depth=16 is the default.)

2. See my note "Help, my script runs out of memory!" at http://rubyforge.org/forum/forum.php?th … um_id=1618

RMagick is a very thin layer over ImageMagick and as such should NOT be using very much memory itself. If you think differently, please email me at rmagick AT rubyforge DOT com and I'll be glad to investigatge.

Offline

 

#21 2005-11-22 23:19:33

rainbowsheep
Member
Registered: 2005-01-15
Posts: 584
Expertise

Re: Lighttpd says Insufficient memory (case 4)

rmagick wrote:

I don't normally visit this forum but Joe mentioned this thread to me.

Background: ImageMagick requires a little over 4 bytes/pixel to represent an image if it (ImageMagick) has been configured with QuantumDepth=8, or 8 bytes/pixel if it has been configured with QuantumDepth=16. So an image from my 4megapixel camera needs 16 or 32Mb.

Two things:

1. Is ImageMagick built with QuantumDepth=16 or QuantumDepth=8? If 16, and you don't need 16-bit pixels, then ImageMagick is using twice as much memory as necessary and almost twice as much CPU. Unless you need 16-bit pixels, configure ImageMagick using --with-quantum-depth=8. (--with-quantum-depth=16 is the default.)

2. See my note "Help, my script runs out of memory!" at http://rubyforge.org/forum/forum.php?th … um_id=1618

RMagick is a very thin layer over ImageMagick and as such should NOT be using very much memory itself. If you think differently, please email me at rmagick AT rubyforge DOT com and I'll be glad to investigatge.


Perhaps the FreeBSD port for ImageMagick is using --with-quantum-depth=a_billion? :-)

Offline

 

#22 2005-11-23 00:28:48

jqshenker
Member
From: Palo Alto, CA
Registered: 2005-09-06
Posts: 721
Website  Expertise

Re: Lighttpd says Insufficient memory (case 4)

rainbowsheep wrote:

Perhaps the FreeBSD port for ImageMagick is using --with-quantum-depth=a_billion? :-)


Quite possibly, actually... it would be nice if you could select between bitdepths when manipulating an image, though.

Have you tried doing whatever operation with the command line ImageMagick utils? When I have RMagick memory problems, the commandline usually still works... which is very strange given (as rmagick said) that it is a thin wrapper.... very weird indeed.

Hope you do figure it out though, as I'm sure many would love to see this solved one and for all.


~Jacob

Offline

 

#23 2005-11-23 00:33:17

cch
Member
Registered: 2005-03-21
Posts: 675
Website  Expertise

Re: Lighttpd says Insufficient memory (case 4)

btw, does calling in-place resize! consume less memory than calling resize or does it still bulids two images at a point?

Offline

 

#24 2005-11-24 02:57:04

rmagick
New member
Registered: 2005-11-22
Posts: 2
Expertise

Re: Lighttpd says Insufficient memory (case 4)

cch,

The resize method always creates a 2nd image. The difference is that resize keeps the original image but resize! frees it.

Offline

 

#25 2005-11-24 17:42:35

cch
Member
Registered: 2005-03-21
Posts: 675
Website  Expertise

Re: Lighttpd says Insufficient memory (case 4)

Does this:

Code:

irb(main):001:0> require 'RMagick'
=> true
irb(main):002:0> Magick::QuantumDepth
=> 16


means ImageMagick was compiled with --with-quantum-depth=16 or do I misunderstand the meaning of that constant?

If so, I feel it's a more than reasonable compromise to have it compiled with 8, if it means we can deal with larger images. how about yous?

Offline

 

#26 2005-11-24 17:59:12

julik
Member
From: Utrecht, Netherlands
Registered: 2005-03-12
Posts: 224
Website  Expertise

Re: Lighttpd says Insufficient memory (case 4)

Reasonable I think. Can you make a couple of samples of scaling with 16bit and 8bit? In PHP at least scaling with standard function sgave terrible results, you always had to use imagecreatetruecolor.

Offline

 

#27 2005-12-04 19:09:17

geography
New member
From: NYC
Registered: 2005-03-17
Posts: 13
Website  Expertise

Re: Lighttpd says Insufficient memory (case 4)

So I wrote an super small wrapper for imageMagick that works well on textdrive.
http://journal.gleepglop.com/articles/2 … e-ruby-way

It basically wraps the command line with a clean interface. If you've been having trouble with ImageMagick it may be of some help.

Offline

 

#28 2006-03-23 17:53:10

rbrigleb
Member
From: Portland, OR
Registered: 2005-04-02
Posts: 194
Website  Expertise

Re: Lighttpd says Insufficient memory (case 4)

I'm having RMagick errors with images over 500k, just as described above. I'll be trying MiniMagick but I'm wondering if that has solved the problem for folks or if other solutions have come up for this issue. Thanks!

Offline

 

#29 2006-09-27 10:33:14

moedusa
New member
Registered: 2006-01-28
Posts: 1
Expertise

Re: Lighttpd says Insufficient memory (case 4)

$ mogrify -list Resource
File Area Memory Map Disk
------------------------------------------------

176 2e+02mb 5e+02mb 1e+03mb 4.00000eb

i.e. ImageMagick on cardero has 500mb memory limit. Just fyi

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson