Re: A way to see how much 'memory' a program will take up in, say, mod_perl, so I can start to optimize it?
by MidLifeXis (Monsignor) on Feb 19, 2009 at 18:42 UTC
|
It sounds like you are asking to predict the memory that will be used by an application, right?
Is the application data driven? In other words, the data passed into an application can cause the size used to grow tremendously. As a simple example...
while (<>) {
push(@lines, $_);
}
| [reply] [d/l] |
|
|
You know, you are absolutely right - it does read in from a SQL database, which makes this much more complicated..
How would you suggest going about something like 'cutting down the amount of memory taken in mod_perl?'
| [reply] |
|
|
Profile, then find the worst offending areas, and target them. Perhaps a better data structure, or a different algorithm would change the usage.
Update: Perhaps one of the Devel::Size type modules might help with this.
Some algorithms have more memory overhead but run faster. Others run more slowly, but take less memory.
A contract I am doing right now has frozen data in a database (basically a key/value setup with a frozen representation of a HoHoHoH... structure as the value), Some of the values are causing the application to run out of memory when being processed. By making each level of the hash another column and letting the database do much of the heavy lifting, I am saving memory, hopefully saving time (not needing to thaw the large data structure), and making a much more scalable application.
In summary, the algorithm and data structure can make a tremendous difference.
| [reply] |
|
|
|
|
| [reply] |
|
|
|
|
|
|
| [reply] |
Re: A way to see how much 'memory' a program will take up in, say, mod_perl, so I can start to optimize it?
by sflitman (Hermit) on Feb 20, 2009 at 02:50 UTC
|
I may be missing something here, but couldn't you use the /proc filesystem? Read /proc/self/status or /proc/pid/status from a test harness and you can interrogate the line VmData and figure out how many pages it has used.
Also, you may like perldebguts, you can get a lot of memory info if Perl was built with its own malloc.
Also also, I remember from the way-back C days there was a call 'sbrk()' which told you in a relatively pan-system way where you were with memory allocation, it is how malloc works. In Perl you'd need an XS to get at it, but again CPAN may come to the rescue.
HTH,
SSF | [reply] |