in reply to Re^2: 2 Questions on Images and Mod_perl mem usage
in thread 2 Questions on Images and Mod_perl mem usage

Before taking time reading Image::Magick take a look at Imager first... ;-)

Wow, our corporate webserver has 512 Mb running mod_perl + Mason.

The example you put, you don't need to create this vars... but anyway, I understand what you mean, but you must see your code, and think about what optimisation you can do. I like to use global variables only where is necessary or is a really benefit.

There are modules where you can see where is consuming more time, etc., take a look for Devel::.

  • Comment on Re^3: 2 Questions on Images and Mod_perl mem usage

Replies are listed 'Best First'.
Re^4: 2 Questions on Images and Mod_perl mem usage
by Anonymous Monk on Jul 02, 2005 at 00:53 UTC
    Well I am just not sure if my webserver is holding variable space for variables in subs that aren't being used.

    The script is 10k+ lines so posting it isn't going to work, but 90% of the time the script is hit it never touchs 75% of the script. But I have subs that read a lot of redudant information from data files, different subs will read the same data file, so they will create local variables to hold that information. If I created these redudant variables as globals, I wouldn't be reserving space for the same set of variables in different subs?

    I am not sure how it works, why I am asking. Does apache only use variable space when variables are in use or does it reserve space for every possible variable in my script?
      To answer your root question, no globals won't gain you anything. Perl's memory usage is sort of a high water marker. It asks for memory from the OS when it needs some, then reuses what it got. In your little subroutine example, perl will allocate space for the lexical, free it when it went out of scope, use the same memory for the next lexical, and so on. 8.5mb for a perl process doesn't seem all that high, but perhaps you're doing something like loading a large file in to memory that you could avoid.

      Yes, you can make globals things global, so you don't do things you don't need to do in the subs, or reserve memory . For example, you don't read in every function the config file, normally you load/read the configuration once on begin, and store it in a global var and all read from it

      Mm, don't know the complexity of the solution, but normally one tends to do packages and so, that you don't have one large script, instead something modular...

      I think you are using DB, right?

      The thing is that once the interpretar has reserve X size of system mem, it don't give it back to the system, instead it's available for the interpreter... as far as I know.

      Is the application a script or is it a handler? Have you thought about using something like http://maypole.perl.org or http://catalyst.perl.org?