Home > other >  Trouble for a code bosses introduce me the meaning of this piece of code company need, just contact
Trouble for a code bosses introduce me the meaning of this piece of code company need, just contact

Time:12-04

#!/user/bin/env python
# coding=utf-8
The import requests
Import a datetime
The import time
The import threading

The class url_request () :
Times=[]
Error=[]
Def the req (self, AppID, url) :
Myreq=url_request ()
Headers={' the user-agent ':' Mozilla/5.0 (Linux; The Android 2; En - us; The Nexus 4 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19}
'Content={' AppID: AppID, 'CurrentURL: url}
R=requests. Post (" http://xx.xxx.com/WeiXinJSAccessToken/json/WeChatJSTicket ", headers=headers, data=https://bbs.csdn.net/topics/payload)
ResponseTime=float (r.e lapsed. Microseconds)/1000 # for response time, unit of ms
Myreq. Times. Append (ResponseTime) # to write response time into the array
If r.s tatus_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 # set the number of concurrent threads
ThinkTime=0.5 # set the think time
For I in range (1, nub + 1) :
T=threading. Thread (target=myreq. The req, args=(' 12 ', 'http://m.ctrip.com/webapp/cpage/#mypoints'))
Threads. Append (t)
For t in threads:
Time. Sleep (ThinkTime)
# print "thread % s" % t # print thread
T.s etDaemon (True)
T.s tart ()
T.j oin ()
The endtime=datetime. Datetime. Now ()
"Print" request end time % s % endtime
Time. Sleep (3)
AverageTime="{: 3 f}". The format (float (sum (myreq. Times))/float (len (myreq. Times))) #, calculating the average of the array to 3 decimal places
Ms "print" Average Response Time % s % AverageTime # print Average Response Time
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) calculating the general thinking time + request time
"Print" Concurrent processing % s % nub # print concurrency
Print "the use of total time % s s" % (totaltime - float (nub * ThinkTime)) # print in total consumption time
Print "fail" request % s % myreq. The error. The count (" 0 ") # print error requests
Copy the code
Copy the code
Request the start time in the 2015-02-10 s 18:24:14. 316000
Request end time of the 2015-02-10 18:24:39. 769000
Average Response Time of 46.700 ms
Concurrent processing 50
The use of total time of 25.453 s
Fail request 1

CodePudding user response:

Is a simple multithreaded

CodePudding user response:

I know my side to modify the data into the interface of our company don't know how to modify bother bosses give advice or comments

CodePudding user response:

refer to the second floor ilixiaohuii response:
I know my side to change the inside of the data into the interface of our company don't know how to modify bother bosses teach

This as the case may be, if you want a simple point, adjust the url, header, payload parameters are about the same,
  • Related