0

So i hosted a website for the purpose of doing security-tests on it, so i created a script in perl that would generate up to 60-72 Mbps (info) being sent. I noticed that if i run the script multiple times simultaneously i would generate up to 150 Mbps.

How is it possible to be able to achieve the 150 Mbps without the need of running the script multiple times?

Thank You!

4

3 回答 3

2

You want to open multiple TCP connections.

You will either need to use an evented loop to handle the back-and-forth of keeping all the pipes full, or need to use threads/processes. As someone commented above, you can use 'fork' to make multiple copies of your script, each one can make one TCP connection and easily keep the connection full. That's probably the simple solution.

If you want to keep your program as a single process, it's a bit more work, but still possible.

If you are opening a LOT of connections, you'll want to read this: http://www.kegel.com/c10k.html

You might also consider using a faster language like C or Go, since using perl does involve some overhead. (I'd do a test first, maybe the overhead is negligible. Test by using a tool like curl to send a big file to see if it gets higher bandwidth than your perl program.)

于 2013-05-18T20:32:35.993 回答
0

As comments have said, fork() would do it.

Your current script:

#!/usr/bin/perl

generate_some_load();

Adding fork:

#!/usr/bin/perl

fork();   # now there are two processes running

generate_some_load();

Or if you want to start a bunch of them

#!/usr/bin/perl

my $num_to_start = 10;

while($num_to_start-- > 0 && fork() != 0) { 

}

generate_some_load();
于 2013-05-19T04:54:53.383 回答
0

I see you want to achieve higher Mbps with every window, occurs to me you might be running the script in the "foreground" and need to open a new window to start anothher. One thing you might want to do is start your scripts in the background.

Instead of

% your_script.pl

If you run with & you won't have to start more windows:

% your_script.pl &
% your_script.pl &
% your_script.pl &
...

And sometimes you have to do a little bit of redirection to /dev/null, like this:

% your_script.pl > /dev/null 2>&1 &
于 2013-05-19T04:59:25.150 回答