By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,852 Members | 2,220 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,852 IT Pros & Developers. It's quick & easy.

Server Load Testing

P: 1
hi,
i need to write a perl client script to create 5000 socket connections at the same time.
Expand|Select|Wrap|Line Numbers
  1. use IO::Socket;
  2. use diagnostics;
  3. use POSIX qw(strftime); 
  4. my $i;
  5. my $connections = 5000;
  6.  
  7. foreach my $i (1...$connections)
  8.     {
  9.         repeat();
  10.     }
  11.  
  12. sub repeat
  13. {
  14.     my $remote_host = "192.168.1.57";
  15.     my $remote_port = "1201";
  16.     my $count=0;
  17.     my $handle= IO::Socket::INET->new(   PeerAddr   =>   $remote_host, 
  18.                                        PeerPort   =>   $remote_port, 
  19.                                        Proto      =>   "tcp",
  20.                                         Type       =>   SOCK_STREAM
  21.                                    ) 
  22.     || die "Couldn't connect to $remote_host:$remote_port: \n"; 
  23.  
  24.     print STDERR "[Connected to $remote_host:$remote_port]\n";
  25.  
  26.  
  27.         DATA: {while(<$handle=1>)
  28.                 {
  29.                     for($count=0;$count<5;$count++)
  30.                     {
  31.                         my $send_data = strftime("::DATA::3847,%d.%m.%Y,%H:%M:%S,13.0149405,77.7736041,0,933.4,04A8,31,0 \n", gmtime);
  32.                         $handle-> send($send_data);
  33.                         $count=0;
  34.                         sleep(5);
  35.                     }
  36.                 }
  37.                 redo DATA;
  38.         }
  39. }
  40.  
the above script creates only one socket connection at a time........
what should be changed to create 5000 socket connections at the same time.
Jan 28 '10 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 785
Create 5000 pearl threads.
see:
http://www.xav.com/perl/lib/Pod/perlthrtut.html

each of these threads can start a single time your "sub repeat" function to create a socket connection. But because the thread creation itself also takes time, I would create all 5000 threads first and let them all sleep before they process this function until a special time is reached. For example if you start creating your threads at 10:00 o'clock and you know that the last thread will be created and up and running before maximum 10:03, then I would program all the threads to sleep and wake up at exactly 10:03 and execute your socket-creation function.
Jan 29 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.