From d6dd05b2a2c27ab6a8a0c22fa13d95c7ad6d78d5 Mon Sep 17 00:00:00 2001 From: Ken-ichi Mito Date: Sat, 2 Nov 2013 23:58:01 +0900 Subject: [PATCH] fix: repeat loops in child processes * '$pm->finish and then $pm->start' loop costs more CPU time --- misc/httpbench.pl | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/misc/httpbench.pl b/misc/httpbench.pl index 028c6b6..fc5a218 100755 --- a/misc/httpbench.pl +++ b/misc/httpbench.pl @@ -34,16 +34,19 @@ warn "wait for $wait second between requests\n"; my $pm = Parallel::ForkManager->new($concurrency); -for (my $i = 0; $i < $loops; $i++) { - for (my $child = 0; $child < $concurrency; $child++) { - $pm->start and next; +for (my $child = 0; $child < $concurrency; $child++) { + if ($pm->start) { + warn "forks $child/$concurrency child ...\n"; + next; + } + for (my $i = 0; $i < $loops; $i++) { + print STDERR "processing $i/$loops loop\r"; foreach my $url (@urls) { get($url) or warn "fail: $url\n"; sleep($wait); } - $pm->finish; - } - print STDERR " ... ", $num * $concurrency * ($i + 1), " requesting\r"; + } + $pm->finish; } $pm->wait_all_children; -- 1.7.9.5