I wrote a simple load tester to test my web app using AnyEvent::HTTP. For the most part it works fine, but if the site becomes non-responsive, eg. it holds open the request connections but doesn't return a response, the load tester goes into a busy wait using 100% cpu, until all the requests time out. I tried different AE loops, and disabled persistent connections, but nothing I tried resolves the issue. And since it's intermittent, I haven't been able to catch it with Devel::NYTProf either. I've included the basic skeleton of the script below. Any pointers to the cause would be much appreciated.
#!/usr/bin/env perl
use strict;
use warnings;
use AnyEvent::Loop; # use the perl loop, not EV
use AnyEvent::HTTP;
use AnyEvent::Util 'guard';
use BSD::Resource;
my $rps = 50;
my $timeout = 30;
my $duration = 300;
my $delay = 60 / $rps / 60;
setrlimit RLIMIT_OFILE, 2048, 2048;
$AnyEvent::HTTP::MAX_PER_HOST = 1024;
my $cv = AE::cv;
my $timer = AE::timer 0, $delay, \&do_request;
my $wait = AE::timer $duration, 0, sub { undef $timer };
my $halt = AE::timer $duration + $timeout, 0, sub { $cv->send };
$cv->recv;
sub do_request {
$cv->begin;
http_request(
GET => 'http://127.0.0.1/test',
timeout => $timeout,
# I also tried limiting the concurrent requests per connection
+ with
# the following:
# persistant => 0,
sub {
my $guard = guard { $cv->end };
# ...
}
);
}