Skip to content

Instantly share code, notes, and snippets.

@sawamur
Created August 5, 2010 06:00
Show Gist options
  • Save sawamur/509312 to your computer and use it in GitHub Desktop.
Save sawamur/509312 to your computer and use it in GitHub Desktop.
#import memcache
import threading
import time
import sys
import urllib2
import random
url = "http://example.com/yourappplication"
total_num = 1000
#total_num = 800000
at_one_attack = 120
sleep_time = 0.8
start_time = time.time()
class Attack(threading.Thread):
def __init__(self,url):
self.url = url
threading.Thread.__init__(self)
def run(self):
r = urllib2.urlopen(self.url)
print r.code
ths = []
for i in range(0,total_num):
if i > 0 and (i % at_one_attack) == 0:
time.sleep(sleep_time)
t = Attack(url)
t.start()
ths.append(t)
for t in ths:
t.join()
total_time = time.time() - start_time
print
print "Time: ",total_time,"sec"
print "Reqs/sec: ",total_num / total_time
print "on each req:",total_time / total_num," sec"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment