#!/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 }; # ... } ); }