locust socektio协议压测
# -*-coding:UTF-8 -*-
from locust import HttpLocust, TaskSet, task, TaskSequence, Locust, events
import time, socketio, random class SocketClient(object): def __init__(self, host):
self.host = host
self.ws = socketio.Client()
self.connected = False def connect(self, burl):
start_time = time.time()
# 判断是否连接,连接就不执行
if not self.connected:
try:
self.conn = self.ws.connect(url=burl)
self.connected = True
except socketio.client.exceptions as e:
total_time = int((time.time() - start_time) * 1000) events.request_failure.fire(request_type="socket", name='建立连接', response_time=total_time, exception=e) else:
total_time = int((time.time() - start_time) * 1000)
events.request_success.fire(request_type="socket", name='建立连接', response_time=total_time,
response_length=0) return self.conn def emit(self, event, data, namespace):
start_time = time.time()
try:
self.ws.emit(event, data, namespace)
except Exception as e:
total_time = int((time.time() - start_time) * 1000) events.request_failure.fire(request_type="socket", name='加入/发送文本', response_time=total_time, exception=e) else:
total_time = int((time.time() - start_time) * 1000)
events.request_success.fire(request_type="socket", name='加入/发送文本', response_time=total_time,
response_length=0) def wait(self):
return self.ws.wait() class socketLocust(Locust):
def __init__(self, *args, **kwargs):
super(socketLocust, self).__init__(*args, **kwargs)
self.client = SocketClient(self.host) class SupperDianCan(TaskSet):
@task
def test(self):
self.url = "https://xxx.com:6302"
self.client.connect(self.url)
#
self.client.emit('join-room', {
"user_id": 123,
"team_id": 345
}, namespace='/mz-chat')
#
self.client.emit('new_message', {
"user_id": 123,
"team_id": 345,
"content": "我来了"}, namespace='/mz-chat')
# period = int(time.strftime("%S", time.localtime())) + 9
# while 1:
# nowtime = time.strftime("%S", time.localtime())
# self.s_sleep(5)
# self.client.emit('new_message', {
# "user_id": 123,
# "team_id": 345,
# "content": "data"}, namespace='/mz-chat')
# if int(nowtime) > period:
# break
# self.wait() class dc_socket(socketLocust):
task_set = SupperDianCan
min_wait = 1000
max_wait = 2000 if __name__ == "__main__":
import os os.system("locust -f locust1.py --no-web -c1 -r1 ")
locust socektio协议压测的更多相关文章
- wrk 及扩展支持 tcp 字节流协议压测
wrk 及扩展支持 tcp 字节流协议压测 高性能.方便使用的 HTTP(s) 的流量压测工具,结合了多个开源项目开发而成: redis 的 ae 事件框架 luajit openssl http-p ...
- jmeter实现SMTP邮件协议压测
实现目的 通过jmeter的SMTP取样器,调用SMTP协议,批量进行邮件的发送,已达到压测的目的. 脚本实现 User Defined Variables定义用户变量 编辑SMTP Sampler取 ...
- 使用jmeter进行websocket协议压测
第一步:添加websocket sampler组件 可以使用plugins manager进行添加,首先下载plugins manager组件: 下载路径: https://jmeter-plugi ...
- locust压测rpc协议
这里主要是google的grpc接口进行压测的一个栗子. Locust是以HTTP为主要目标构建的. 但是,通过编写钩子触发器request_success和 request_failure事件的自定 ...
- locust接口压测
前言: locust是完全基于python,是一个简单易用的分布式负载测试工具 Locust特性 使用Python编写模拟用户行为的代码,无需繁琐的配置 分布式可扩展,能够支持上百万用户 自带Web界 ...
- Python Locust对指定网站“一键压测”
[本文出自天外归云的博客园] 前篇 前篇:Python Locust性能测试框架实践 本篇 承上——归纳过程 在前篇的基础上,我们可以利用Locust性能测试框架编写python脚本对指定网站或者接口 ...
- 一键压测工具改造(locust)
本文内容来自“天外归云”大神,原文链接http://www.cnblogs.com/LanTianYou/p/5987741.html,目前只对启动脚本做了一些改造,应该说是,不适用powershel ...
- 黑羽压测 比 jmeter、locust、loadrunner 更简便,性能更强
视频讲解 点击下方链接,观看 讲解视频 https://www.bilibili.com/video/av60089015/ 动机 目前市场上对API接口做性能测试工具有 Jmeter.LoadRun ...
- wrk,ab,locust,Jmeter 压测结果比较
背景: 项目需要对一批接口进行压测,要求是接口的QPS(Quest Per Second每秒请求数)达到6万以上由于楼主一直使用的压力测试工具是jmeter,但是jmeter单台电脑无法达到6万的QP ...
- python压测工具Locust
python压测工具Locust Locust介绍 Locust作为基于Python语言的性能测试框架. 其优点在于他的并发量可以实现单机10倍于LoadRunner和Jmeter工具.他的工作原理为 ...
随机推荐
- linux下启动rabbitmq,redis,nginx
这只是其中一种启动方法,也是我自己安装好后试过多次可以用的, 1,启动rabbitmq rabbitmqctl start_app rabbitmq程序端口是5672,可视化界面入口端口是15672, ...
- nginx 同一个域名根据后缀不同访问不同的项目
server { listen 80; server_name bcgx.work; location / { index login.html login.htm index.php; root / ...
- 5. nginx跨域配置
1.跨域问题处理:在nginx相关接口上配置如下: 如接口有自己的请求头,则加上:如接口自带请求头pubacc-buid if ($request_method = "OPTIONS&quo ...
- 免费节假日 API
转载地址:http://timor.tech/api/holiday 获取指定日期的节假日信息 接口地址:http://timor.tech/api/holiday/info/$date@params ...
- LocalDateTime 使用记录
1.LocalDateTime 获取指定日期的月初和月末 LocalDateTime firstDayTime = LocalDate.now().withMonth(12).withDayOfMon ...
- 莫烦Python 4
莫烦Python 4 新建模板小书匠 RNN Classifier 循环神经网络 问题描述 使用RNN对MNIST里面的图片进行分类 关键 SimpleRNN()参数 batch_input_shap ...
- 用requests-html和SelectorGadget轻松精准抓取网页数据
我们在抓取网页数据时,最常採用Python的requests搭配BeautifulSoup的模式来完成.然而,requests-html整合了上述2个套件,又添加了新的功能,或许是抓取网页数据值得考虑 ...
- MySQL无法同时执行多条语句解决办法 Dbeaver
一.场景 说明:在数据库中同时执行多条语句,提示语法错误,如下图: 二.解决办法 第一步:在每条语句最后加上分号(;)表示本条语句结束: 第二步:在数据库连接串上设置 allowMultiQuerie ...
- debian11命令行安装字体
一.需要用到三条命令mkfontscale/mkfontdir/fc-cache这三条命令属于两个软件包mkfontscale/mkfontdir属于xfonts-utils包,fc-cache命令属 ...
- linux合并bilibili下载的blv视频
B站下载的学习视频,用python+sh合并处理,自己mark一下 手机bilibili下载了视频,想要搞到电脑上看,结果发现下载下来的都是文件夹里的一堆片段,仔细一看还是 .blv,脑那样啊! 在虚 ...