Could you please help me to develop this, I have tried the Thread::Queue. It takes too much time to retrieved the result from a source and I have to search more than 50 sources at a time. There could be more than 10 instances that would be running concurrently.
How can main thread can read them off and display>
following is the code I am using
sub run_search { my ($self, $searches, $search_string, $site, $max_hits, $from_year +, $to_year) = @_; my $Qwork = new Thread::Queue; my $Qresults = new Thread::Queue; my $THREADS = scalar(keys %$searches); my @return; foreach my $obj (values %$searches) { eval { $obj->from_year($from_year); $obj->to_year($to_year); $obj->parse_search(); }; if ($@) { print STDERR "problem2 $@\n"; } $Qwork->enqueue($obj); } $Qwork->enqueue( (undef) x $THREADS ); my @pool = map{ threads->create( \&parallel_search, $Qwork, $Qresults, $max_hi +ts, $self->nuc_code) }1 .. $THREADS; for(1..$THREADS){ while( my $result = $Qresults->dequeue ){ push(@return, $result); } } ## Clean up the threads $_->join for @pool; return(\@return); } # # # the parallel server # # sub parallel_search { my ($Qwork, $Qresults, $max_hits, $nuc_code) = @_; my $tid = threads->tid; my %result; while(my $work = $Qwork->dequeue) { 'require ' . ref($work) . ';'; $work->max_hits($max_hits); $result{$work->resource_id} = $work->get_search_results($work- +>resource_id, $nuc_code); $Qresults->enqueue( \%result ); } $Qresults->enqueue( undef ); }

In reply to Re^2: Parallel Search using Thread::Pool by shanu_040
in thread Parallel Search using Thread::Pool by shanu_040

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.