• flask 部署后并发测试


    部署后看下flask支持的并发,来个300并发看看,上代码

    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
    '%(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
    "%(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))

    看下百度请求响应

    那么我的呢

    还算可以吧 支持的并发,不过不太准,可以参考。接口也可以用这个搞

  • 相关阅读:
    【leetcode】236. 二叉树的最近公共祖先
    【leetcode】230. 二叉搜索树中第K小的元素
    【leetcode】309. 最佳买卖股票时机含冷冻期
    【leetcode】306. 累加数
    【leetcode】304. 二维区域和检索
    spring-framework源码编译及导入
    Java8-函数式接口理解及测试
    Mac编译RocketMQ 4.1.0
    首记
    JS表单验证
  • 原文地址:https://www.cnblogs.com/leiziv5/p/7183806.html
Copyright © 2020-2023  润新知