Last active
December 29, 2015 15:19
-
-
Save kuanyingchou/7689457 to your computer and use it in GitHub Desktop.
This file contains 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
import requests | |
import time | |
import threading | |
payload = { | |
'u_name': 'ken', | |
'email': 'kuanying@tradeserv.com', | |
'mobile': '0999000000', | |
'num1': '9999', | |
'o_num':'9999' | |
} | |
count = 0 | |
lock = threading.Lock(); | |
start = time.time() | |
def order(delay): | |
global payload, count, lock, start | |
while True: | |
r = requests.post( | |
r'http://www.kizipad.com/pre-buy_ok.php', | |
data = payload) | |
elapsed = time.time() - start | |
with lock: | |
count += 1 | |
print('rps: %.4f\ttotal: %d requests' % | |
(float(count)/elapsed, count)) | |
time.sleep(delay) | |
# print('bye'); | |
for i in range(10): | |
t = threading.Thread(target=order, args=(0.001,)) | |
t.start() | |
# results: | |
# 17:51:02 ken@ken-mba:test_website$ python ./pre-order.py | |
# rps: 0.0000 total: 0 requests | |
# rps: 0.4975 total: 1 requests | |
# rps: 0.9921 total: 2 requests | |
# rps: 1.4809 total: 3 requests | |
# rps: 1.9723 total: 4 requests | |
# rps: 2.4565 total: 5 requests | |
# rps: 2.8763 total: 6 requests | |
# rps: 3.2856 total: 7 requests | |
# rps: 3.7461 total: 8 requests | |
# rps: 3.8566 total: 9 requests | |
# rps: 4.2805 total: 10 requests |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment