McA has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
a process checking DNS names unexpectedly has eaten 12GB of memory, forced swapping and ringing almost all alarm bells of system monitoring.
So I was really surprised. DBI needed 1GB to get all results from the MySQL database into the process. That was expected for some millions of rows and ok. But afterwards I wanted to check the DNS name in a fetching loop. The used process memory grew and grew what I really didn't expect in this way.
Now I reduced the whole thing to the following snippet which is more or less literally taken from the man page of Net::DNS. Combined with the very usful package Test::LeakTrace I have the following:
#!/bin/env perl use strict; use warnings; use strict; use 5.010; use local::lib './lib'; use Net::DNS; use Test::LeakTrace; die("ERROR: Please provide Loop count > 0 as first argument") unless $ +ARGV[0]; leaktrace { for (1..$ARGV[0]) { my $res = Net::DNS::Resolver->new; my @mx = mx($res, "example.com"); } } ;
The result is that Test::LeakTrace reports MANY leaks. Following the documentation of Test::LeakTrace I gave Net::DNS a chance in a way that one-shot-costs are ok but iterating over meanwhile instantiated/cached code should not need additional memory. To prove this I have a for-loop around it which can be given on the command line. Together with the following little shell script:
for iterations in 1 2 3 4 5 6 7 8 9 10; do perl script.pl $iteration +s 2>&1 | wc -l; done
I get the following output:
1374 1492 1612 1736 1859 1982 2106 2229 2353 2477
You see that the leaked memory rises with the itaration count. This seems to me very bad.
Now to you monks: I would be intersted to see the result on different plattforms with different Perl versions. If you have time and pleasure to test it on your Perl I would be really interested in the results.
By the way: If someone knows a package for DNS lookups not easting the memory of my machine should tell it. :-) Does anybody know some documentation how to read the verbose output of Test::LeakTrace (which is not used in this script)?
Thank you in advance
Regards
McA
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hunting a memory eater
by tobyink (Canon) on Feb 27, 2014 at 14:20 UTC | |
by McA (Priest) on Feb 27, 2014 at 15:06 UTC | |
|
Re: Hunting a memory eater
by oiskuu (Hermit) on Feb 27, 2014 at 17:26 UTC | |
by McA (Priest) on Feb 27, 2014 at 18:13 UTC |