Server Load Testing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arunprakash647
    New Member
    • Jan 2010
    • 1

    Server Load Testing

    hi,
    i need to write a perl client script to create 5000 socket connections at the same time.
    Code:
    use IO::Socket;
    use diagnostics;
    use POSIX qw(strftime); 
    my $i;
    my $connections = 5000;
    
    foreach my $i (1...$connections)
    	{
    		repeat();
    	}
    	
    sub repeat
    {
    	my $remote_host = "192.168.1.57";
    	my $remote_port = "1201";
    	my $count=0;
    	my $handle= IO::Socket::INET->new(   PeerAddr   =>   $remote_host, 
    									   PeerPort   =>   $remote_port, 
    									   Proto      =>   "tcp",
    										Type       =>   SOCK_STREAM
    								   ) 
    	|| die "Couldn't connect to $remote_host:$remote_port: \n"; 
    	
    	print STDERR "[Connected to $remote_host:$remote_port]\n";
    
    
    		DATA: {while(<$handle=1>)
    				{
    					for($count=0;$count<5;$count++)
    					{
    						my $send_data = strftime("::DATA::3847,%d.%m.%Y,%H:%M:%S,13.0149405,77.7736041,0,933.4,04A8,31,0 \n", gmtime);
    						$handle-> send($send_data);
    						$count=0;
    						sleep(5);
    					}
    				}
    				redo DATA;
    		}
    }
    the above script creates only one socket connection at a time........
    what should be changed to create 5000 socket connections at the same time.
    Last edited by numberwhun; Jan 28 '10, 05:49 PM. Reason: Please use code tags!!!
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    Create 5000 pearl threads.
    see:
    Get a payday loan via Payday UK. Paid out the same day - Loans from £50 to £5,000 - Good & Bad Credit - Secure UK Lenders. INSTANT DECISION.


    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.

    Comment

    Working...