Changeset 178d578 in lab.git for misc


Ignore:
Timestamp:
Mar 6, 2014 6:19:23 PM (11 years ago)
Author:
Ken-ichi Mito <mitty@…>
Branches:
master
Children:
3813e29
Parents:
45d3453
Message:

new option --duration

  • set loop duration time (second)
    • with --duration, --loops is ignored
File:
1 edited

Legend:

Unmodified
Added
Removed
  • misc/httpbench.pl

    r45d3453 r178d578  
    1717    'c|concurrency=i'   => \ my $concurrency, 
    1818    'n|loops=i'         => \ my $loops, 
     19    'd|duration=i'      => \ my $duration, 
    1920    'w|wait=f'          => \ my $wait, 
    2021) or usage(); 
     
    2425$concurrency ||= 1; 
    2526$loops ||= 1; 
     27$duration ||= 0; 
    2628$wait ||= 0; 
    2729 
     
    3032 
    3133my $num = scalar @urls; 
    32 warn "$num urls with $concurrency clients, $loops loops\n"; 
    33 warn "Total: ", $num * $concurrency * $loops, " requests\n"; 
     34my $l = ($duration) ? "$duration seconds loops" : "$loops loops"; 
     35warn "$num urls with $concurrency clients, $l\n"; 
     36warn "Total: ", $num * $concurrency * $loops, " requests\n" if (! $duration); 
    3437warn "wait for $wait second between requests\n" if ($wait); 
    3538 
     
    5861        # child 
    5962        my $transfer = 0; 
    60         for (my $i = 0; $i < $loops; $i++) { 
     63        my $i = 0; 
     64        while (1) { 
     65            if ($duration) { 
     66                last if (time() - $startsec > $duration); 
     67            } 
     68            else { 
     69                last if ($i >= $loops); 
     70            } 
     71             
    6172            print STDERR "processing $i/$loops loop\r"; 
    6273            foreach my $url (@urls) { 
     
    7081                sleep($wait); 
    7182            } 
     83             
     84            $i++; 
    7285        } 
    7386        $pm->finish(0, \$transfer); 
Note: See TracChangeset for help on using the changeset viewer.