flask 部署後併發測試

部署後看下flask支持的併發,來個300併發看看,上代碼flask

import threading, time, requests
url = "http://www.baidu.com"
total = 0
suc = 0
fail = 0
exception = 0
maxtime=0
mintime=100
gt3=0
lt3=0
class RequestThread(threading.Thread):
    def __init__(self, thread_name):  
        threading.Thread.__init__(self)  
        self.test_count = 0
    def run(self):
        self.test_performace()
    def test_performace(self):  
            global total
            global suc
            global fail
            global exception
            global gt3
            global lt3
            try:  
                st = time.time()  
                conn = requests.get(url)
                res = conn.status_code
                if res== 200:
                    total+=1
                    suc+=1
                else:
                    total+=1
                    fail+=1
                time_span = time.time()-st  
                print ('%s:%f\n'%(self.name,time_span)  )
                self.maxtime(time_span)  
                self.mintime(time_span)  
                if time_span>3:
                    gt3+=1
                else:
                    lt3+=1
            except Exception as e:  
                print (e  )
                total+=1
                exception+=1
    def maxtime(self,ts):  
            global maxtime
            print (ts)
            if ts>maxtime:
                maxtime=ts
    def mintime(self,ts):  
            global mintime
            if ts<mintime:
                mintime=ts
print ('===========請求開始==========='  )
start_time = time.time()
thread_count = 100
i = 0  
while i <= thread_count:  
    t = RequestThread("線程:" + str(i))
    t.start()  
    i += 1  
t=0
while total<thread_count|t>20:
        print ("總數:%d,成功數:%d,失敗:%d,異常:%d\n"%(total,suc,fail,exception)  )
        print (url)
        t+=1
        time.sleep(1)
print ('===========task end===========')
print ("總數:%d,成功:%d,失敗:%d,異常:%d"%(total,suc,fail,exception))
print ('響應最大時間:',maxtime)
print ('響應最小時間',mintime)
print ('大於3秒的響應:%d,佔比:%0.2f'%(gt3,float(gt3)/total))
print ('小於3秒:%d,佔比:%0.2f'%(lt3,float(lt3)/total))

看下百度請求響應併發

那麼個人呢url

還算能夠吧 支持的併發,不過不太準,能夠參考。接口也能夠用這個搞spa

相關文章
相關標籤/搜索