Reputation: 1199
I have a Perl script, fetch url like http://1.1.1.1/1.jpg
from MySQL using DBI, and download this jpg file using LWP::Simple. It's a infinite loop.
while (1) {
my $url=&fetch_url_from_mysql;
if ($url){
&download_jpg($url);
} else {
sleep 1;
}
}
Plain simple. I suppose the memory usage would be stay in certain amount. But after one month of continuous running of this script. The memory usage is 7.5G!
How can I profile it?
Upvotes: 1
Views: 2506
Reputation: 5069
For profiling, set an explitict exit. Create a counter, and exit from your program if your iteration is equal or bigger than this.
For profiling, use NYTprof:
perl -d:NYTProf script.pl nytprofhtml
But you are dealing with a memory leak here.
Read this to find a memory leak: How can I find memory leaks in long-running Perl program?
Most probably you have a variable that will never be freed. Perl frees memory if a variable goes out of scope, but one of your variables never goes out of scope.
Use $variable=undef to free up the memory.
If you port your whole script maybe we could find a leak in it.
regards,
Upvotes: 1