美文网首页
python--并发测试脚本

python--并发测试脚本

作者: w_dll | 来源:发表于2020-07-22 22:32 被阅读0次

    写的玩的,压力测试 , 跑并发,拿自己服务器跑,10000并发会崩溃;

    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    
    import requests
    import json
    import threading
    import time
    
    
    class myThread (threading.Thread):
        def __init__(self, name):
            threading.Thread.__init__(self)
            self.name = name
        def run(self):
            this_str="start :"+self.name
            print (this_str)
            headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36',
            'Content-Type': 'application/json; charset=UTF-8',
            }
            url = 'http://www.test.com'
            try:
                r = requests.post(url, headers)
            except Exception as e:
                print(e)
            this_str="end :"+self.name
            print (this_str)
     
     
     
    try:
        i = 0
        # 开启线程数目
        tasks_number = 3000
        print('启动')
        time1 = time.clock()
        while i < tasks_number:
            t_name = i+1
            t = myThread(str(t_name))
            t.start()
            i +=1
        time2 = time.clock()
        times = time2 - time1
        print(times/tasks_number)
    except Exception as e:
        print(e)
    

    相关文章

      网友评论

          本文标题:python--并发测试脚本

          本文链接:https://www.haomeiwen.com/subject/oljxlktx.html