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

Dear Monks,
I had a problem with the external host where my Perl/CGI is running. At some point there was not enough memory and my process probably took the rest and thus killed a box.
As a result my account was suspended. Any recommendation to takle this problem?
Does it make sense, for example, when a client sends me a request to check the box CPU usage in my Perl program and say, if idling is less than 30%, loop it with sleep untill it becoms bigger?
If it does make sense how to better do it, or any other advices..

Replies are listed 'Best First'.
Re: CPU usage on external UNIX host
by MidLifeXis (Monsignor) on Nov 17, 2009 at 22:08 UTC

    I would guess that there is something else going on here that caused your provider to suspend your account.

    What does your CGI do? Does it use fork, grab lots of memory, do other things that are "antisocial"? Is there any way you can post the code?

    --MidLifeXis

      I talked to them and got an email and it was actually memory usage. Sorry, not CPU.
      I do use much of memory, maybe 0.5G, not a big deal actually, but this was the first time I was in trouble. I do not use fork. So probably I need to verify available memory?
        If you have shell access to the server, running top, vmstat, sar, mpstat (if it's a multiple CPU system) and iostat are good indicators of system performance. Details are in the manpages.

        Specifically for your code, though, I'd highly suggest benchmarking your code with Devel::NYTProf, or at least Benchmark (comes with perl). That should help isolate where in your code memory is getting chewed up.

        I'd also suggest some putting some logging in your code, so you can go back and troubleshoot why the memory usage from your CGI was high, and ideally, to be able to recreate the problem on a test system.

        Without seeing any of your code, I can't give anything specific.

        -- Burvil

        ...you seem to be slightly confused as to what got you shut down..... are you sure it wasn't "excessive bandwidth usage"? .... it uses the same terminology (Megabytes, Gigabytes, etc) as memory......

        ......it could be your isp scamming for more money.... i had an isp, was very cheap...even recommended them here as an isp.....like only 2 bucks per month...... THEN suddenly they said i was exceeding my bandwidth limit..... and needed to contact their tech dept...... it was a bulsh*t ploy to get me to upgrade to more expensive service(more bandwidth)...... it's something to think about if your script used to work fine, and now suddenly your bandwidth exceeds limits :-)


        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku