Subject: | Memory leak |
There is a problem with memory leak in this script. Script requests
page with 1000 parallel streams maximum and repeats this operation. It
was tested for web server (the required page is loaded) and on the
closed port (operation finished on timeout). Ten megabytes of RAM
leaked during one hour.
use warnings;
use strict;
use HTTP::Request::Common qw(GET POST);
use POE;
use POE::Component::Client::HTTP;
use POE::Component::Client::Keepalive;
$|++;
#~~ constants
my $threads_count = 1000; #threads count
my $timeout = 2; #timeout for connect
my $req = GET "http://127.0.0.1/"; #request :)
my $complete = 0;
my $pool = POE::Component::Client::Keepalive->new
(
keep_alive => 0,
max_open => 10000,
max_per_host => 10000,
timeout => $timeout,
);
POE::Component::Client::HTTP->spawn
(
Alias => 'ua',
Timeout => $timeout,
ConnectionManager => $pool,
NoProxy => '',
FollowRedirects => 5
);
POE::Session->create
(
package_states => [ main => [ "_start", "got_response", "_stop" ] ]
);
sub got_response
{
$complete++;
print "Complete: $complete\n";
my $id = ARG0->[1]; #get request id
$poe_kernel->post( "ua" => "request", "got_response", $req , $id);
#add request
};
sub _start
{
for(0..$threads_count-1)
{
$poe_kernel->post( "ua" => "request", "got_response", $req,
$_); #add request
};
print "Started $threads_count threads\n";
};
sub _stop
{
print "Stoped at " . scalar(localtime()) . "\n";
};
$poe_kernel->run();