File: xr-http-test

package info (click to toggle)
crossroads 2.65-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,664 kB
  • ctags: 355
  • sloc: cpp: 4,212; perl: 1,658; xml: 269; makefile: 186; sh: 46
file content (36 lines) | stat: -rwxr-xr-x 706 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/perl

use strict;
use LWP::UserAgent;
use Time::HiRes qw(sleep gettimeofday tv_interval);

$|++;

die <<"ENDUSAGE" if ($#ARGV != 2);

Usage: $0 URL THREADS DURATION
Will start THREADS to get URL. The entire test will run for DURATION
seconds.

ENDUSAGE

my ($url, $threads, $duration) = @ARGV;
for my $i (1..$threads) {
    next if (fork());

    my $t_start = [gettimeofday()];
    my $runs = 0;
    while (tv_interval($t_start) < $duration) {
        $runs++;
        my $t_run = [gettimeofday()];
	my $ua = LWP::UserAgent->new();
	$ua->timeout(5);
	my $resp = $ua->get($url);
        print(tv_interval($t_run), "\n")
	  if ($resp->is_success());
    }
    exit(0);
}

while(wait() != -1) {
}