Enlightened Monks,
I am writing a Bioinformatics grid service in perl where I use various computers to process parts of a BLAST (bioinformatics algorithm file). My program creates a thread to send work to a node and as the node ends his work, so should the thread. Since the program will be dealing with many nodes, thus creating and destroying many threads, memory is a big deal. I have noticed that each time a create and destroy a thread, my precious megabytes seem to leak! Below may be found a simpler version where the leak occurs. Please help me find the light.
Thanks,
Paulo Carvalho
#!/usr/bin/perl-w
#Libs
use strict; use threads; use threads::shared;
my %thr; #Threads controling each node
my %thr_up; share (%thr_up); #if thread finished job $thr_up shuould
+be = 0
SMALL:for (1 .. 1000) {
#Find a waiting thread
unless ($thr_up{"FREE_HOST"}) {
$thr_up{"FREE_HOST"} = 1; #thread working flag
$thr{"FREE_HOST"} = threads->create("blast_thread");
sleep(1);
my @list = threads->list();
$list[scalar(@list-1)]->join () if (scalar(@list) > 2);
foreach my $l (@list) {print "$l\n";}
}
#Just for my surprise:
print $thr{FREE_HOST}->tid, ",$thr{FREE_HOST} \n" if ($thr{FREE_HO
+ST}->tid);
}
sub blast_thread {
$thr_up{FREE_HOST} = 0;
print "Server UP\n";
return;
}
############################
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.