Python sample code for post-deployment concurrency testing in flask

Source: Internet
Author: User
After deployment look at the flask supported concurrency, to a 300 concurrency look, on the code

Import threading, time, Requestsurl = "" total = 0suc = 0fail = 0exception = 0maxtime=0mintime=100gt3=0lt3=0class requestth Read (threading. Thread):d EF __init__ (Self, thread_name): Threading.  Thread.__init__ (self) self.test_count = 0def Run (self): Self.test_performace () def test_performace (self):                  Global Totalglobal Sucglobal failglobal exceptionglobal gt3global lt3try:st = Time.time ()                    conn = requests.get (URL) res = Conn.status_codeif res== 200:total+=1suc+=1else: Total+=1fail+=1time_span = Time.time ()-st print ('%s:%f\n '% (self.name,time_span)) self.ma                    Xtime (Time_span) self.mintime (Time_span) if Time_span>3:gt3+=1else: Lt3+=1except Exception as E:print (e) total+=1exception+=1def maxtime (self,ts): Global MAXTIMEPR int (TS) if Ts>maxtime:maxtime=tsdef mintime (self,ts): Global Mintimeif Ts<mintime:mintime=tsprint (' =========== request start =========== ') start_time = Time.time () Thread_count = 100i = 0 while I <= thread_count:t = Requestthread ("Thread:" + str (i)) T.start () i + = 1 t=0w Hile total<thread_count|t>20:print ("Total:%d, number of successes:%d, failure:%d, exception:%d\n"% (total,suc,fail,exception)) print (URL) t+= 1time.sleep (1) print (' ===========task end=========== ') print ("Total:%d, success:%d, failed:%d, exception:%d"% (total,suc,fail,exception) Print (' Response max time: ', maxtime) print (' Response min. ', mintime) print (' response greater than 3 seconds:%d,%:%0.2f '% (gt3,float (GT3)/total)) print (' less than 3 seconds :%d,%:%0.2f '% (lt3,float (LT3)/total))

Look at the Baidu request response

Well, what about mine?

It is OK to support the concurrency, but not very accurate, you can refer to. The interface can also be used to

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.