An application I am writing uses a lot of memory and there seem to be a serious memory leakage I try to track down.
As I am far from being a memory expert I wonder if even I am looking at the right numbers and if the baseline information is correct?
I am using the following script to check its own memory usage:
#!/usr/bin/perl
use strict;
use warnings;
print_size('empty');
foreach my $module (
'Data::Dumper',
'Scalar::Util',
'Getopt::Long',
'Net::XMPP',
'JSON::XS',
'LWP::UserAgent',
'POE qw(Component::Server::TCP)',
'Moose',
) {
eval "use $module";
die $@ if $@;
print_size("after $module");
}
sub print_size {
my ($msg) = @_;
my @lines = qx{/bin/ps -e -o pid,ppid,vsize,rss,command | grep ^$$
+};
chomp @lines;
foreach my $line (@lines) {
my ($pid, $ppid, $vsize, $rss) = split /\s+/, $line;
print "VM: $vsize RSS: $rss - $msg\n";
}
return;
}
and when running on SuSE with perl 5.10.0
I get the following data:
VM: 15972 RSS: 2324 - empty
VM: 18740 RSS: 3256 - after Data::Dumper
VM: 20968 RSS: 3388 - after Scalar::Util
VM: 21760 RSS: 4240 - after Getopt::Long
VM: 51348 RSS: 15408 - after Net::XMPP
VM: 53648 RSS: 15588 - after JSON::XS
VM: 57980 RSS: 17704 - after LWP::UserAgent
VM: 65852 RSS: 21572 - after POE qw(Component::Server::TCP)
VM: 88616 RSS: 31924 - after Moose
So if I understand correctly my script starts - after loading all the necessary modules - with 88 Mb memory used?
Do I see correctly that loading
Moose take 20Mb without even creating classes and objects?
Net::XMPP is even bigger as it takes 30Mb ?
Is the way I am measuring correct?
As I'll need to run several instances of this process at the same time will they share some memory or will this number just be multiplied by the number of processes I have?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.