2NetFly has asked for the wisdom of the Perl Monks concerning the following question:
Log example: 1;200; 4;200; 5;200; 10;200; 4;500; 13;200; 14;200; 10;200; 16;200; 18;200; 13;200; 26;200; 3;200; 28;200; 2;200; 7;200; 1;200; ... after 10 minutes 65;200; 65;200; Dump Dump 65;200; 42;200; Dump 42;200; Dump ^C Time:320 Done A thread exited while 101 threads were running. My code: #!/usr/bin/perl use strict; use threads; use threads::shared; use LWP::UserAgent; use HTTP::Request::Common; use Thread::Queue; $| = 1; my $thread_num : shared = 0; my $max_thread = 100; my $exit = 0; my $dump = 0; my $start_time = 0; my %tid : shared = (); my $result_q = Thread::Queue->new(); $SIG{INT} = sub { $exit++ }; $start_time = time(); threads->new(\&thread_do) for (1..$max_thread); while (!$exit) { for (my $i = 0; $i < $result_q->pending(); $i++) { print $result_q->dequeue(), "\n"; } if ($dump++ > 100000) { print "Dump\n"; dump_tid(\%tid); $dump = 0; } } print "\n\nTime:" . (time() - $start_time) . "\n"; print "Done\n"; sub thread_do { threads->self->detach(); my $tid = threads->self->tid(); while (1) { my $ua = LWP::UserAgent->new(timeout => 3); my $res = $ua->request(HEAD 'http://smth.com/'); $result_q->enqueue("$tid;" . $res->code() . ";"); lock %tid; $tid{$tid}++; } } sub dump_tid { my $tid = shift; open (DUMP, "> dump.txt"); print DUMP "$_ = $tid->{$_}\n" foreach keys %$tid; close DUMP; }
2004-12-29 Janitored by Arunbear - added readmore tags, as per Monastery guidelines
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with ithreads
by BrowserUk (Patriarch) on Dec 30, 2004 at 02:23 UTC | |
|
Re: Problem with ithreads
by 2NetFly (Initiate) on Dec 30, 2004 at 07:48 UTC | |
by BrowserUk (Patriarch) on Dec 30, 2004 at 08:38 UTC | |
by 2NetFly (Initiate) on Dec 30, 2004 at 10:15 UTC | |
by BrowserUk (Patriarch) on Dec 30, 2004 at 11:28 UTC | |
by 2NetFly (Initiate) on Dec 30, 2004 at 14:15 UTC | |
|
Re: Problem with ithreads
by BrowserUk (Patriarch) on Dec 30, 2004 at 17:41 UTC | |
by 2NetFly (Initiate) on Jan 01, 2005 at 18:57 UTC |