写点什么

Week07 作业

用户头像
熊威
关注
发布于: 2020 年 07 月 22 日



  • 用你熟悉的编程语言写一个 web 性能压测工具,输入参数:URL,请求总次数,并发数。输出参数:平均响应时间,95% 响应时间。用这个测试工具以 10 并发、100 次请求压测 www.baidu.com。



from concurrent.futures import ThreadPoolExecutor
import time
from queue import Queue
import HttpInterfaceTest
import uuid

test_queue = Queue(maxsize=100000)


def create_test(publickey, key, usernames, param, url, timeout=1000):
"""
生产者创建测试对象
:param publickey:
:param key:
:param usernames:
:param param:
:param url:
:param timeout:
:return:
"""
ti = HttpInterfaceTest(publickey=publickey,
key=key,
usernames=usernames,
param=param,
url=url,
timeout=timeout)
test_queue.put(ti)


def call_test(q):
"""
调取测试接口
:param q:
:return:
"""
while not q.empty():
ti = q.get()
ti.test_http('json')


def exec_pressuretest(index, pcount, ccount):
"""
压力测试 调取总次数 = index*pcount
:param index:
:param pcount:
:return:
"""
for i in range(0, index):
with ThreadPoolExecutor(pcount) as Producer:
for p in range(pcount):
base_url = 'http://www.baidu.com/'
#publickey = '123456789'
#key = 'A123B456C789D123'
#usernames = ['Jike', 'Jone', 'Ada']
param = uuid.uuid1()
Producer.submit(create_test, param, base_url)
print(str(p)+' -> '+str(param))
Producer.shutdown()

with ThreadPoolExecutor(ccount) as Consumer:
for c in range(ccount):
Consumer.submit(call_test, test_queue)
Consumer.shutdown()


if __name__ == '__main__':
exec_pressuretest(100, 500, 400)



用户头像

熊威

关注

还未添加个人签名 2019.06.12 加入

还未添加个人简介

评论

发布
暂无评论
Week07作业