Hiya,
I found this code snippet(reference http://www.goldb.org) and wish to do more
with it than just send out a Http Get request.I would like to introduce more
traffic -say by downloading files,crawling through all the links,logging in etc
etc,and wish to see how the web server reacts.I'm trying to stress the server
to its limits....appreciate if anyone could provide me code/ideas to inject
into this.
the website -http://ftp.ruby-lang.org/pub/ruby/binaries/mswin32/ selected as
example has many downloads.i tried from urllib import urlretrieve
urlretrieve('http://ftp.ruby-lang.org/pub/ruby/binaries/mswin32/ruby-1.6.4-i586-mswin32.zip','ruby-1.6.4-i586-mswin32.zip'),but
didnt work.....
[QUOTE]import time
import os
import sys, urllib, re
import httplib
#from urllib import urlretrieve
import urllib2
from threading import Thread
class LoadManager:
def __init__(self):
self.thread_refs = []
self.msg = ('localhost') # default
def stop(self):
for thread in self.thread_refs:
thread.stop()
def start(self, threads=1, interval=0, rampup=1):
for i in range(threads):
spacing = (i * (float(rampup) / float(threads)))
time.sleep(spacing)
agent = LoadAgent(interval, self.msg)
agent.setDaemon(True)
agent.start()
# print 'started thread # ' + str(i + 1)
self.thread_refs.append(agent)
class LoadAgent(Thread):
def __init__(self, interval, msg):
Thread.__init__(self)
self.running = True
self.interval = interval
self.msg = msg
def stop(self):
self.running = False
def run(self):
while self.running:
start_time = time.time()
if self.send(self.msg):
end_time = time.time()
raw_latency = end_time - start_time
expire_time = (self.interval - raw_latency)
latency = ('%.3f' % raw_latency)
print latency
else:
raw_latency = 0
expire_time = (self.interval - raw_latency)
if expire_time > 0:
time.sleep(expire_time)
def send(self, msg):
try:
req = urllib2.Request(msg)
response = urllib2.urlopen(req)
the_page = response.read()
return True
except:
print 'failed request'
return False
def main():
# sample usage
manager = LoadManager()
manager.msg = ('http://ftp.ruby-lang.org/pub/ruby/binaries/mswin32')
manager.start(threads=5, interval=2, rampup=2)
if __name__ == '__main__':
main()[/QUOTE]
--
http://mail.python.org/mailman/listinfo/python-list