Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Perl cleanup takes a long time

by varian (Chaplain)
on Jun 14, 2007 at 08:09 UTC ( [id://621179]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl cleanup takes a long time
in thread Perl cleanup takes a long time

Perrin brings up a very good point.

I quickly ran a test that creates 3 hashes of the type and depth that you mentioned. Here's the ps command output:

PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 22842 pts/1 R+ 0:00 0 10 6941 1680 0.1 perl xxx.pl create all the hashes PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 22842 pts/1 S+ 0:23 2 10 932137 883884 85.5 perl xxx.pl clean out hashes PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND 22842 pts/1 R+ 0:30 31 10 932137 885632 85.6 perl xxx.pl we're done

Memory requirements of your program are likely to be at least 933 MBytes this is without DBI etc.!! Since you mentioned that your computer has 1GByte internal memory on board the sheer size of the hashes definitely will require the operating system to swap memory pages.
The Perl garbage collection is not the cause of this problem, even while it does require some time. The operating system takes time to memory swap things in good shape again.
So you may want to add a bit more internal memory to your system to run an application like this one ;-)

Test-program source:

#!/usr/bin/perl use strict;use warnings; sub showtime { print `ps -p $$ v`; } showtime; print "create all the hashes\n"; my %h1; foreach my $one (0..64000) { $h1{$one}={}; foreach my $two (0..2) { $h1{$one}{$two}='foo'; } } my %h2; foreach my $one (0..2200000) { $h2{$one}={}; foreach my $two (0..3) { $h2{$one}{$two}='foo'; } } my %h3; foreach my $one (0..1) { $h3{$one}={}; foreach my $two (0..1) { $h3{$one}{$two}={}; foreach my $three (0..1) { $h3{$one}{$two}{$three}={}; foreach my $four (0..9) { $h3{$one}{$two}{$three}{$four}={}; foreach my $five (0..14) { $h3{$one}{$two}{$three}{$four}{$five}={}; foreach my $six (0..39) { $h3{$one}{$two}{$three}{$four}{$five}{$six}='bar'; } } } } } } showtime; print "clean out hashes\n"; %h1= (); %h2= (); %h3= (); showtime; print "we're done\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://621179]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-25 16:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found