1

I have a server from which I can access a webpage. I want to test the server reaction when several users(say 60000 users) access the same webpage simultanously. Im looking for a script to do this,a perl script will be better,

Here is the code I tried with

#!c:\\perl\\bin
use strict;
use WWW::Mechanize;
my $url = "http://www.cpan.org";
my $searchstring = "WWW::Mechanize";
my $mech = WWW::Mechanize->new();
while (i == 60000)
{
$mech->get($url);
i++;
}

But this scripts access the url 1 at a time, But I need simultanous access.

pmod
  • 10,450
  • 1
  • 37
  • 50
mac
  • 863
  • 3
  • 21
  • 42

4 Answers4

6

You can use ab. Use its concurrency (-c) and number of requests (-n) options.

Alan Haggai Alavi
  • 72,802
  • 19
  • 102
  • 127
4

Your code, as shown above, doesn't even compile. It would be far easier for people to help you if you gave us the exact code that you're using, rather than typing to retype it and adding typos.

To get your code to compile, I had to declare $i and add the $ before the two uses of i in your programme. I ended up with this:

#!/usr/bin/perl

use strict;
use WWW::Mechanize;
my $url = "http://www.cpan.org";
my $searchstring = "WWW::Mechanize";
my $mech = WWW::Mechanize->new();
my $i;
while ($i == 60000) {
  $mech->get($url);
  $i++;
}

You say that the loop only gets executed once. That's not true. The loop doesn't get executed at all. The condition on the loop is $i == 60000. The first time this condition is checked, $i is undefined so the condition is false and the loop is skipped.

I think you probably wanted $i <= 60000 instead.

But as Alan points out, you'd be far better off using an existing tool like ab.

Alan Haggai Alavi
  • 72,802
  • 19
  • 102
  • 127
Dave Cross
  • 68,119
  • 3
  • 51
  • 97
2

You can either use Perl itself to launch your script 6000 times in parallel or write one (or maybe more than one) .BAT files or similar Windows scripting to launch the perl script.

Be careful to clearly understand how to execute stuff in detached mode under Windows.

(Of course you have to remove the while loop in your original script).

Community
  • 1
  • 1
p.marino
  • 6,244
  • 3
  • 25
  • 36
  • Any idea how to lanuch a script 6000 times using perl ? – mac Oct 05 '11 at 07:32
  • Have you read the links I added to my answer? Especially the "How do I start a process in the background?" question? Basically you write a simple Perl script with your 6000-times loop, and inside the loop you use something like http://www.xav.com/perl/site/lib/Win32/Process.html to start various instances of the original script. Each one will run as a separate process, giving you parallelism. – p.marino Oct 05 '11 at 08:47
  • 2
    The previous documentation link is out of date by many years. Better: http://p3rl.org/Win32::Process – daxim Oct 05 '11 at 12:04
1

ab has already been mentioned, but that only tests against the root page (/) of the site. We found siege more useful in replicating real load, since we were able to test against a long list of URLs (10,000 or so) taken from our live access log...

plusplus
  • 1,992
  • 15
  • 22