Load Testing a Web server

Python script used to send requests to a web server.  You can specify the number of requests in the function testIt, changing the upper limit in the range from 5 to the desired number.  Each request is sent every .1 sec.

import urllib

import os

import datetime

import time

def fileremove(f):

if os.path.exists(f):

os.remove(f)

def stressTest(link,i):

f=open(r’c:\tmp\Response.txt’,’a’)

mypath = link

mylines = urllib.urlopen(mypath).readlines()

time= datetime.datetime.now()

f.write(str(i)+’,’+str(time.second)+’,’+mylines[1])

f.write(‘\n’)

print i, str(time.second)+’ ‘+mylines[1]

f.close()

def testIt():

f=r’/Users/YourName/Desktop/Response.txt’

fileremove(f)

for i in range(1,5):

stressTest(“http://mail.google.com/”,i)

if __name__ == “__main__”:

testIt()

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: