The blogger optimized the interface framework yesterday and wanted to add some more features.
Think of the performance stress test on the interface
Tools that were used before the work, such as: LoadRunner, JMeter
Thinking about this, we're going to use Python to implement performance stress testing on interfaces.
The first thing to do is to use Python's threading module to implement this function.
Here is the code that you learn to explore:
1 #!/usr/bin/env python2 #-*-coding:utf_8-*-3 4 ImportThreading5 ImportRequests6 fromTimeImportCTime7 8 9 defAPI (URL, data):Ten Try: OneR =requests.post (URL, data) A Print "Interface Access return status code:", R.status_code - Print "interface Request time:", CTime () - Print "Interface Access return address:", R.url the exceptException.__bases__: - Print "Interface Access failed","interface Request time:", CTime () - -Case_1 = {'username':'Admin','Password':'123456'} -URL1 ='http://localhost:8081/swcw/back/sysLogin.action' + A atThreads = [] - forIinchRange (10): -T_i = Threading. Thread (target=API (URL1, case_1)) - threads.append (t_i) - - if __name__=='__main__': in forTinchThreads: - T.setdaemon (True) to T.start () + T.join () - the Print "All over %s"% CTime ()
This is a 10-process simultaneous login scenario
After that, you add some performance data to the class form.
Finally I recommend a multi-threaded blog easy to understand
The blogger himself also learned from the above
Http://www.cnblogs.com/fnng/p/3670789.html
Python Learning Notes (threading Multithreading)