locust 压测笔记

最近有个底层依赖要优化,免不了做下压测。

Jmeter 使用成本偏高,要配置一系列展现组件,但是一旦会用的话就很快了,需要注意的是并发数不要设置太大,否则机器网卡可能会被打满。因为本次压测场景,需要有动态 metaValue 作为 POST 参数进行测试,因此 jmeter 这种纯静态参数就不太能满足预期,因此调研后打算采用 locust 来进行压测。

好处是可以动态修改 POST 参数,来更好的模拟出用户层请求。

1 安装 locust

pip install locust

2 编写压测代码

# coding:utf8
import os
import time
import json
import random
from locust import HttpUser, task, between, events
 
metamap &#
[2019-11-21 09:20:20,796] 小米笔记本/INFO/locust.main: Starting web monitor at *:8089 [2019-11-21 09:20:20,796] 小米笔记本/INFO/locust.main: Starting Locust 0.13.2 [2019-11-21 09:20:20,806] 小米笔记本/ERROR/stderr: Traceback (most recent call last): [2019-11-21 09:20:20,806] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,806] 小米笔记本/ERROR/stderr: File "c:\python\lib\site-packages\gevent\threadpool.py", line 281, in _worker value = func(*args, **kwargs) [2019-11-21 09:20:20,807] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,807] 小米笔记本/ERROR/stderr: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 2: invalid continuation byte [2019-11-21 09:20:20,807] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,807] 小米笔记本/ERROR/stderr: 2019-11-21T01:20:20Z [2019-11-21 09:20:20,808] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,808] 小米笔记本/ERROR/stderr: (<ThreadPool at 0x3ae3550 0/1/10 hub=<Hub at 0x41a7bd8 thread_ident=0x26720>>, <built-in func tion gethostbyaddr>) failed with UnicodeDecodeError [2019-11-21 09:20:20,812] 小米笔记本/ERROR/stderr: Traceback (most recent call last): [2019-11-21 09:20:20,812] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,812] 小米笔记本/ERROR/stderr: File "src/gevent/greenlet.py", line 818, in gevent._greenlet.Greenlet.run [2019-11-21 09:20:20,812] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,812] 小米笔记本/ERROR/stderr: File "c:\python\lib\site-packages\locust\web.py", line 201, in start pywsgi.WSGIServer((options.web_host, options.port), [2019-11-21 09:20:20,812] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,813] 小米笔记本/ERROR/stderr: File "c:\python\lib\site-packages\gevent\baseserver.py", line 385, in serve_forever self.start() [2019-11-21 09:20:20,813] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,813] 小米笔记本/ERROR/stderr: File "c:\python\lib\site-packages\gevent\baseserver.py", line 323, in start self.init_socket() [2019-11-21 09:20:20,813] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,814] 小米笔记本/ERROR/stderr: File "c:\python\lib\site-packages\gevent\pywsgi.py", line 1479, in init_socket self.update_environ() [2019-11-21 09:20:20,814] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,815] 小米笔记本/ERROR/stderr: File "c:\python\lib\site-packages\gevent\pywsgi.py", line 1491, in update_environ name = socket.getfqdn(address[0]) [2019-11-21 09:20:20,815] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,815] 小米笔记本/ERROR/stderr: File "c:\python\lib\site-packages\gevent\_socketcommon.py", line 275, in getfqdn hostname, aliases, _ = gethostbyaddr(name) [2019-11-21 09:20:20,815] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,816] 小米笔记本/ERROR/stderr: File "c:\python\lib\site-packages\gevent\_socketcommon.py", line 247, in gethostbyaddr return get_hub().resolver.gethostbyaddr(ip_address) [2019-11-21 09:20:20,816] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,816] 小米笔记本/ERROR/stderr: File "c:\python\lib\site-packages\gevent\resolver\thread.py", line 70, in gethostbyaddr return self.pool.apply(_socket.gethostbyaddr, args, kwargs) [2019-11-21 09:20:20,816] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,817] 小米笔记本/ERROR/stderr: File "c:\python\lib\site-packages\gevent\pool.py", line 159, in apply return self.spawn(func, *args, **kwds).get() [2019-11-21 09:20:20,817] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,817] 小米笔记本/ERROR/stderr: File "src/gevent/event.py", line 268, in gevent._event.AsyncResult.get [2019-11-21 09:20:20,817] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,818] 小米笔记本/ERROR/stderr: File "src/gevent/event.py", line 296, in gevent._event.AsyncResult.get [2019-11-21 09:20:20,818] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,818] 小米笔记本/ERROR/stderr: File "src/gevent/event.py", line 286, in gevent._event.AsyncResult.get [2019-11-21 09:20:20,818] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,818] 小米笔记本/ERROR/stderr: File "src/gevent/event.py", line 266, in gevent._event.AsyncResult._raise_exception [2019-11-21 09:20:20,819] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,819] 小米笔记本/ERROR/stderr: File "c:\python\lib\site-packages\gevent\_compat.py", line 54, in reraise raise value.with_traceback(tb) [2019-11-21 09:20:20,819] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,819] 小米笔记本/ERROR/stderr: File "c:\python\lib\site-packages\gevent\threadpool.py", line 281, in _worker value = func(*args, **kwargs) [2019-11-21 09:20:20,819] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,819] 小米笔记本/ERROR/stderr: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 2: invalid continuation byte [2019-11-21 09:20:20,820] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,820] 小米笔记本/ERROR/stderr: 2019-11-21T01:20:20Z [2019-11-21 09:20:20,820] 小米笔记本/ERROR/stderr: [2019-11-21 09:20:20,821] 小米笔记本/ERROR/stderr: <Greenlet at 0x5143798: start([<class 'locustfile.WebsiteUser'>], Namespace(csvfilebase=None, exit_code_on_error=1, )> failed with UnicodeDecodeError [2019-11-21 09:20:20,821] 小米笔记本/INFO/locust.main: Shutting down (exit code 0), bye. [2019-11-21 09:20:20,821] 小米笔记本/INFO/locust.main: Cleaning up runner... [2019-11-21 09:20:20,821] 小米笔记本/INFO/locust.main: Running teardowns... Name # reqs # fails Avg Min Max | Median req/s failures/s -------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------- Aggregated 0 0(0.00%) 0 0 0 | 0 0.00 0.00 Percentage of the requests completed within given times Name # reqs 50% 66% 75% 80% 90% 95% 98% 99% 99.9% 99.99% 1 00% ------------------------------------------------------------------------------------------------------------------------------------------------ ------ ------------------------------------------------------------------------------------------------------------------------------------------------ ------
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页
实付 9.90元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值