Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

I ran out of memory

by ido50 (Scribe)
on Aug 26, 2004 at 16:49 UTC ( [id://386076]=perlquestion: print w/replies, xml ) Need Help??

ido50 has asked for the wisdom of the Perl Monks concerning the following question:

Hi there!
I've recently started using my own CMS (Perl/CGI) on my website. Everything was working fine until today, when after performing a simple and common task, the program failed with an "Internel Server Error" message. From the error log I managed to find out that the error is an "Out of memory!" error. The program stopped working ever since.
Any suggestions on how I can fix/prevent this?

Thanks
Ido.

-------------------------
Live fat, die young

Replies are listed 'Best First'.
Re: I ran out of memory
by waswas-fng (Curate) on Aug 26, 2004 at 16:52 UTC
    This usually can mean your app's data has grown over time and is now taking more memory than you have in real and swap. The other thing that can be happening is maybe there is another app of the server that has now grown to a large size and is taking most of the system memory. try using tools like top, ps, free or whatever is available on the operating system you are running on to see where the hog is.


    -Waswas
      Okay so first of all, the website is stored on a server that I don't own, so I can't run such commands.
      The data the program uses is stored in a DBM database, and it's only the beginning so it's quite small really.

      I've used the following memory test script I got from a certain website. It tries to use about 8MB of memory. It fails to do so:

      #!/usr/bin/perl $| = 1; print "Content-type: text/html\n\n"; print "Memory/Resource Test<BR>\n"; print "Number is the amount of memory used<BR>\n"; print "If you don't see 'Completed Test!' at the bottom, the test fail +ed<P><HR>\n"; for ($i = 10000; $i <= 8000000; $i += 100000) { $x = " " x $i; print "-"; print "| $i ; Time (secs): ", (time - $^T), "<BR>\n" if $i % 1 +000000 == 0; } print "Completed Test!\n"; exit(0);
      So I guess my host limits the ammount of memory my CGI programs can use...

      -------------------------
      Live fat, die young
        You can probably request a higher limit for an additional fee. Talk to your hosting provider for more info.

        ------
        We are the carpenters and bricklayers of the Information Age.

        Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

        I shouldn't have to say this, but any code, unless otherwise stated, is untested

Re: I ran out of memory
by davido (Cardinal) on Aug 26, 2004 at 16:59 UTC
      Well, I am using DB_File so it's not a flat-file, but still not a very efficient database. What bothers me is that, even if the database isn't that good, it currently stores only a few entries, so I really can't see why the program fails. I am using DBM databases for quite a while and never had this problem...

      -------------------------
      Live fat, die young
        Okay so I've done a little test and deleted all the dbm database files created by the program. I executed the program again, and this time it worked (To the fair amount of complaining that it didn't find the database files).

        So I guess we are looking on a database problem here. One question: My host has the DBI module installed, but only a few DBD modules. Let's say I simply upload a module like DBD::SQLite to a certain directory, use lib on that directory and try to use the module I've just uploaded. Will it work? Or would it require a "traditional" installation?

        -------------------------
        Live fat, die young
Re: I ran out of memory
by ikegami (Patriarch) on Aug 26, 2004 at 16:53 UTC
    What does the code do? Can we see it?
      Well, the code is fairly large (~300KB). Basically it's a content management system I've been working on for the past 6 months.
      Actually, the project has just been approved by SourceForge (It's called SheepWool)... I was ready to release it as an alpha version, but now that problem got me........


      -------------------------
      Live fat, die young
Re: I ran out of memory
by Anonymous Monk on Aug 27, 2004 at 09:57 UTC
    Out of memory means that the combined memory usage of all the processes on the system (or in some group with separate limits) have reached the limits, and that your process did a request that would push the total usage over the limit - and hence the request got denied. Your process decided to throw up its hands in the air and give up (die). This is what a lot of processes do. Without knowing anything about your program, it's impossible to determine whether your program is using more memory than it should, or that it's just an innocent victim of another process hunger for resources.

    Perhaps you need to buy more memory. Perhaps you need to redesign your program. Perhaps you need a different database. Perhaps you need to purge old data. Perhaps you need to kill another process. Perhaps you have a virus. Who could tell?

      Under *nix you can also limit the amount of memory a process can use (see ulimit). I have used this in the past to limit the amount of memory a poorly behaved program can take up. Perhaps your hosting provider has a limit set on your processes.

      --MidLifeXis

Re: I ran out of memory
by bronto (Priest) on Aug 27, 2004 at 08:08 UTC

    You forgot to tell us which webserver you are using and if you are using mod_perl.

    Unless you did something really wrong, CGIs shouldn't be a problem, since they die and free the memory they were using after execution

    If you are using Apache and mod_perl you should try Apache::SizeLimit to shoot apache instances that grew too big. If not... good luck ;-) the question is unanswerable without the code

    Ciao!
    --bronto


    The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
    --John M. Dlugosz

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://386076]
Approved by gellyfish
Front-paged by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-24 21:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found