Robgunn has asked for the wisdom of the Perl Monks concerning the following question:
My problem is with memory usage: it continually gobbles RAM. Even if I comment outuse Text::Ngram qw( ngram_counts ); use ... use ... my $db = "/home/db/repository/megalith.db"; my $ngram_width = 5; my %protein_search_hash; unlink $db; tie %protein_search_hash, 'MLDBM', -Filename => $db, -Flags => DB_CREATE | DB_INIT_LO +CK or die "Cannot open database '$db: $!\n"; open FILE, "<test_data_2MB.txt" or die "Failed to load test_data: $!\n"; my $fasta_sequence = do { local $/; <FILE> }; close(FILE); # Precompile regex for speed my $regex = qr/>([\S]*)\s*.*\s([A-Za-z\s]+)/; my $regex_d = qr/^>[\S]*\s*.*\s[A-Za-z\s]+/; # PARSE $fasta_sequence and split header from the sequence while( $fasta_sequence =~ m/$regex/igm ) { my $sequence = $2; my $header = $1; $sequence =~ tr/[\r|\n]//d; # delete all line breaks # generate n-grams my $ngram_href= ngram_counts($sequence, $ngram_width); $protein_search_hash{$header} = $ngram_href; } ... ... ...
...it still eats the same amount of RAM each time. However, I have narrowed it down to$protein_search_hash{$header} = $ngram_href;
...as being the problem. I've tried undef and putting it in a subroutine but nothing stops the insatiable thirst for RAM. Currently, I'm limited to processing data files under 13MB (anything higher and I'm out of RAM and into swap). If I comment out the above line, RAM usage flatlines like I would expect. Why isn't '$ngram_href' being overwritten each iteration through and the old value being GC'd? Monks, what am I missing here? Any help would be much appreciated!my $ngram_href= ngram_counts($sequence, $ngram_width);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Memory Growth Problem
by almut (Canon) on Nov 08, 2008 at 04:16 UTC | |
|
Re: Memory Growth Problem
by jwkrahn (Abbot) on Nov 08, 2008 at 07:52 UTC | |
by Robgunn (Initiate) on Nov 08, 2008 at 21:49 UTC | |
|
Re: Memory Growth Problem
by kyle (Abbot) on Nov 08, 2008 at 04:10 UTC | |
|
Re: Memory Growth Problem
by graff (Chancellor) on Nov 10, 2008 at 01:28 UTC | |
|
Re: Memory Growth Problem
by Anonymous Monk on Nov 08, 2008 at 04:17 UTC |