???Python???????????????
???????????? ???????[ 2015/2/26 15:06:43 ] ??????????????? ??????? ???
?? ?路??????ruquest?????????????????????
????????????????
#!/user/bin/env python
#coding=utf-8
import requests
import datetime
import time
import threading
class url_request():
times = []
error = []
def req(self??AppID??url):
myreq=url_request()
headers = {'User-Agent' : 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 4 Build/JOP40D) AppleWebKit/535.19 (KHTML?? like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19'}
payload = {'AppID':AppID??'CurrentURL':url}
r = requests.post("http://xx.xxx.com/WeiXinJSAccessToken/json/WeChatJSTicket"??headers=headers??data=payload)
ResponseTime=float(r.elapsed.microseconds)/1000 #???????????位ms
myreq.times.append(ResponseTime) #????????写??????
if r.status_code !=200 :
myreq.error.append("0")
if __name__=='__main__':
myreq=url_request()
threads = []
starttime = datetime.datetime.now()
print "request start time %s" %starttime
nub = 50#???貌????????
ThinkTime = 0.5#??????????
for i in range(1?? nub+1):
t = threading.Thread(target=myreq.req?? args=('12'??'http://m.ctrip.com/webapp/cpage/#mypoints'))
threads.append(t)
for t in threads:
time.sleep(ThinkTime)
#print "thread %s" %t #??????
t.setDaemon(True)
t.start()
t.join()
endtime = datetime.datetime.now()
print "request end time %s" %endtime
time.sleep(3)
AverageTime = "{:.3f}".format(float(sum(myreq.times))/float(len(myreq.times))) #???????????????????3位小??
print "Average Response Time %s ms" %AverageTime #????????????
usetime = str(endtime - starttime)
hour = usetime.split(':').pop(0)
minute = usetime.split(':').pop(1)
second = usetime.split(':').pop(2)
totaltime = float(hour)*60*60 + float(minute)*60 + float(second) #?????????????+???????
print "Concurrent processing %s" %nub #?????????
print "use total time %s s" %(totaltime-float(nub*ThinkTime)) #??????????????
print "fail request %s" %myreq.error.count("0") #?????????????
request start time 2015-02-10 18:24:14.316000
request end time 2015-02-10 18:24:39.769000
Average Response Time 46.700 ms
Concurrent processing 50
use total time 25.453 s
fail request 1
???????????????tps?????????????????????????????????????????????
??????
???路???
??????????????????
2023/3/23 14:23:39???写?貌??????????
2023/3/22 16:17:39????????????????????些??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???路???????路
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11