gorillaman has asked for the wisdom of the Perl Monks concerning the following question:

I am wondering if there is a way to simulate 10 users accessing a perl script at the same time?

I have a program that runs at a benchmarked average of .002, its fast for what it does. But... Its only me accessing that cgi. What happens if the site has more than one user accessing it?

Is there a way to test this? I searched the web, but havent really found a reliable way of testing. Thanks!

Replies are listed 'Best First'.
Re: Simulating heavy traffic
by perrin (Chancellor) on Jul 22, 2004 at 04:49 UTC
    Many tools for this are discussed here.
Re: Simulating heavy traffic
by Zaxo (Archbishop) on Jul 22, 2004 at 04:49 UTC

    fork,

    my %kid; for (1..10) { my $pid = fork; warn("Can't fork $_"), next if not defined $pid; $kid{$pid} = undef, next if $pid; undef %kid; exec qw/perl myscript.pl/; } delete $kid{+wait} while %kid;

    After Compline,
    Zaxo

Re: Simulating heavy traffic
by sgifford (Prior) on Jul 22, 2004 at 04:49 UTC
    I do this by starting up a program to do a hundred script runs or so, and then run 10 of them at the same time. My test script is called multihsh, and I use a shell script like this:
    # Now do some queries for i in 1 2 3 4 5 6 7 8 9 10 do multihsh -p "_db=$CLASSNAME;_template=$TPLNAME" hsh 08stats.in >/dev +/null & done for i in 1 2 3 4 5 6 7 8 9 10 do wait ec=$? if [ $ec -ne 0 ] then echo "A script exited with status $ec" fi done
Re: Simulating heavy traffic
by tachyon (Chancellor) on Jul 22, 2004 at 07:06 UTC
    ab is part or the Apache distro and works pretty well. Just point it at your CGI and let rip.

    cheers

    tachyon

Re: Simulating heavy traffic
by saintmike (Vicar) on Jul 22, 2004 at 08:18 UTC
Re: Simulating heavy traffic
by BrowserUk (Patriarch) on Jul 22, 2004 at 10:20 UTC

    Here you go a complete stress test suite in 10 26 lines of perl :)

    #! perl -slw use strict; use threads; use LWP::Simple; use Time::HiRes qw[sleep]; $!=1; print "Usage $0 [-T=10] [-R=1.0] [-MAX=30] url" unless $ARGV[ 0 ]; ## Number of threads (simultaneuos callers) our $T ||= 10; ## Fire rate in decimal seconds (0.1 once per 1/10 sec/thread) our $R ||= 1.0; ## Seconds to sustain the burst. our $MAX ||= 30; async { getprint( $ARGV[ 0 ] ) while sleep( rand( $R ) ); } for 1 .. $T; sleep $MAX;

    WARNING: Be careful who you aim it at!


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon