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工具.他的工作原理为 ...
随机推荐
- vux方法
vuex 的备注 // vuex的公用数据放置处 state: { count: 0, }, // (方法) 在里面可以去修改state里面的数据(在这里面不能写异步操作) mutations: { ...
- Springboot多数据源使用示例
1.配置文件 spring.datasource.url=jdbc:mysql://198.168.1.1:3306/user?useUnicode=true&characterEncodin ...
- Python基础前言
计算机内部存储数据的原理 """计算机内部只认识01二进制"""是因为计算机是基于电工作的,而电是有高低电频之分00000001 000 ...
- c--> #define 定义宏
#define 定义宏 宏(Macro)是预处理命令的一种,它允许用一个标识符来表示一个字符串 1.有关定义宏的代码末尾不需要添加":"(分号) 2.定义宏define在计算的式子 ...
- WPF 实现雪花效果
雪花控件类: class MM:Control { DispatcherTimer dispatcherTimer = new DispatcherTimer(); public MM() { dis ...
- pythonanywhere 部署 webpy
======================= start ===================== 1. 在pythonanywhere中Add a new web app. 2. 新开一个Bas ...
- 前端js校验小数点
let result = (value.toString()).indexOf("."); if (result != -1 && value.toString() ...
- Linux-samba共享
CentOS8 中 Samba环境搭建(满足Linux和Windows系统之间文件共享传输) Samba服务器通信协议(Server Messages Block)就是是为了解决局域网内的文件或打印机 ...
- jsp <img src="“> src 相对路径的问题
图片所在路径 jsp所在路径 调用处 相对路径 以调用处JSP位置为参考 每一个../代表上一级 4个 正好找到到webRoot 目录拼接后 webRoot /kernel/_static/img/ ...
- 各种工具点评以供选择使用 + 开发工具秘籍(git, webpack。。。。)
git最佳实践: https://gist.github.com/fandean/ca29cd2f326f66c659951d7ab356cefb ========================== ...