<table cellspacing='0' cellpadding='0' border='0' ><tr><td valign='top' style='font: inherit;'><P>Hiya,</P>
<P>I found this code snippet(reference <A href="http://www.goldb.org">http://www.goldb.org</A>) 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.<BR>the website -http://ftp.ruby-lang.org/pub/ruby/binaries/mswin32/ selected as example has many downloads.i tried from urllib import urlretrieve<BR>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.....</P>
<P><BR>[QUOTE]import time<BR>import os<BR>import sys, urllib, re<BR>import httplib<BR>#from urllib import urlretrieve<BR>import urllib2<BR>from threading import Thread</P>
<P><BR>class LoadManager:<BR>    def __init__(self):<BR>        self.thread_refs = []<BR>        self.msg = ('localhost') # default<BR>    <BR>    def stop(self):<BR>        for thread in self.thread_refs:<BR>            thread.stop()<BR>            <BR>    def start(self, threads=1, interval=0, rampup=1):<BR>        for i in range(threads):<BR>            spacing = (i * (float(rampup) / float(threads)))<BR>            time.sleep(spacing)<BR>            agent = LoadAgent(interval,
 self.msg)<BR>            agent.setDaemon(True)<BR>            agent.start()<BR>            # print 'started thread # ' + str(i + 1)<BR>            self.thread_refs.append(agent)<BR>        </P>
<P>class LoadAgent(Thread):<BR>    def __init__(self, interval, msg):<BR>        Thread.__init__(self)<BR>        self.running = True<BR>        self.interval = interval<BR>        self.msg = msg<BR>        <BR>    def stop(self):<BR>        self.running = False<BR>        <BR>    def run(self):<BR>        while self.running:<BR>            start_time = time.time()<BR>            if self.send(self.msg):<BR>                end_time =
 time.time()<BR>                raw_latency = end_time - start_time<BR>                expire_time = (self.interval - raw_latency)<BR>                latency = ('%.3f' % raw_latency)<BR>                print latency<BR>            else:<BR>                raw_latency = 0<BR>                expire_time = (self.interval - raw_latency)<BR>            if expire_time >
 0:<BR>                time.sleep(expire_time)<BR>                <BR>    def send(self, msg):<BR>        <BR>        try:<BR>            <BR>            req = urllib2.Request(msg)<BR>            response = urllib2.urlopen(req)<BR>            the_page = response.read()<BR>            <BR>            return True</P>
<P>        except:<BR>            print 'failed request'<BR>            return False</P>
<P> </P>
<P>def main():<BR>    # sample usage<BR>    manager = LoadManager()<BR>    manager.msg = ('http://ftp.ruby-lang.org/pub/ruby/binaries/mswin32')<BR>    manager.start(threads=5, interval=2, rampup=2)</P>
<P><BR>if __name__ == '__main__':<BR>    main()[/QUOTE]</P></td></tr></table><br>