Last active
December 19, 2015 09:59
-
-
Save clly/5937537 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import argparse, urllib2, threading | |
| parser = argparse.ArgumentParser(description="Threaded Web Stress Tester") | |
| parser.add_argument('-c', '--count', | |
| action="store", | |
| dest="count", | |
| default=1000, | |
| type=int, | |
| help="Number of times to request the webpage" | |
| ) | |
| parser.add_argument('-t', '--threads', | |
| action="store", | |
| dest="tcount", | |
| default=1, | |
| type=int, | |
| help="Number of threads to user." | |
| ) | |
| parser.add_argument('webpage', | |
| action="store", | |
| help="Web page to stress test", | |
| ) | |
| parser.add_argument('-s', '--sleep', | |
| action="store", | |
| dest="sleep", | |
| default=0, | |
| type=int, | |
| help="Seconds to sleep between requests", | |
| ) | |
| hits = 0 | |
| def hit_server(webpage): | |
| resp = urllib2.urlopen(webpage) | |
| html = resp.read() | |
| class query_thread(threading.Thread): | |
| def __init__(self, webpage, count): | |
| threading.Thread.__init__(self) | |
| self.webpage = webpage | |
| self.count = count | |
| def run(self): | |
| global hits | |
| while(hits <= self.count): | |
| hits += 1 | |
| hit_server(args.webserver) | |
| if(args.sleep): | |
| sleep(args.sleep) | |
| if __name__ == '__main__': | |
| args = parser.parse_args() | |
| for x in xrange(args.tcount): | |
| query_thread(args.webpage, args.count).start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment