Hi All,
I am able to create simaltaneous threads and access a subroutine(which
performs firing of reqeusts). with the created threads.
Some time I get the following error *"Free to wrong pool 225f40 not 13ddbd50
at C:/Perl/lib/constant.pm line -1." .*Whats the reason for the error?
**
Please check the below code and tell me if there is efficient way of
managing the created threads.
Basically i want the following:
Releasing the thread once it has completed the task and release the
memory associated with it.
I want to pass thread_id to subroutine(the value of $thr->tid);
Please suggest me the more efficient and organised way of managing the
threads in the following program
#######SNIP
use strict;
use warnings;
use LWP;
use LWP::Simple;
use Threads;
sub HTTP_Req
{
my($tid,$host,$port,$uri)=...@_;
open my $FH, '>>', "samp2.csv" or die "$!";
my $req = new HTTP::Request 'POST';
my $url='http:' . '//' . $host . ':' . $port . $uri;
my $ua = new LWP::UserAgent;
$req->url($url);
$req->header(Host => $host);
$req->user_agent($ua->agent);
$req->content_type('text/html');
my ($st_secs,$st_mins,$st_hours)=localtime(time);
my ($seconds, $fraction) = gettimeofday();
my $st_ms = $fraction + $seconds * 1000;
my $res = $ua->request($req);
($seconds, $fraction) = gettimeofday();
my $end_ms = $fraction + $seconds * 1000;
my $resp_time=$end_ms-$st_ms;
my ($end_secs,$end_mins,$end_hours)=localtime(time);
my $resp_code=$res->code;
if ($res->is_success)
{
print $FH
"$tid,$st_hours:$st_mins:$st_secs,$end_hours:$end_mins:$end_secs,$resp_time,$resp_code,SUCCESS\n";
}
else
{
print $FH
"$tid,$st_hours:$st_mins:$st_secs,$end_hours:$end_mins:$end_secs,$resp_time,$resp_code,FAIL\n";
}
close $FH;
}
my @threads;
my $host='test.domain.com';
my $port='80';
my $uri='/';
my $threads=100;
open my $FH, '>', "samp2.csv" or die "$!";
print $FH "tid,start_time,end_time,Response Time,ResponseCode,Result\n";
close $FH;
for (1 .. 100)
{
my $thr = threads->create(\&HTTP_Req, $_,$host,$port,$uri);
$thr->detach;
push @threads, $thr;
}
$_->join foreach @threads;