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工具.他的工作原理为 ...
随机推荐
- Log4net使用探究
第一步: 通过Nuget package 搜索Apache Log4net安装 第二步: 在项目Global.asax文件中添加读取 配置文件 第三步: 编写Loghelper 文件 1 public ...
- About TopoJSON
An extension of GeoJSON that encodes topology! TopoJSON https://github.com/topojson/topojson The To ...
- k8s部署-kubeadm
环境配置 内核配置 基本组件安装 高可用组件安装 kubeadm集群初始化
- react native 模拟机调试,debug菜单在哪
- mybatis 数据搜索后参数显示乱码无法搜到
今天写作业的时候遇到的小问题 问题说明:搜索订单名中含有"香皂"的订单,显示订单的一系列属性.在搜索后,调试框中显示的东西很奇怪,也没有查找到答案: 觉得是编码问题,所以调试了编码 ...
- .Net最小工作线程对应用程序性能的影响
这要从Asp.Net建立连接的机制说起,Asp.Net建立连接依赖于.Net线程池,线程池的大小决定了应用程序最多可以同时执行的请求数量.maxWorkerThreads最大工作线程,决定单个处理器最 ...
- 记:java.lang.IllegalArgumentException: DAY_OF_MONTH 报错
查询的时候报错: 月份中的天数错误 原因: date日期列中有数据错误 修改数据库中错误的数据就可以了.
- NGINX websocket 配制
http { map $http_upgrade $connection_upgrade { default upgrade; '' close; } upstre ...
- websphere+IHS+plugin集群搭建
配置:wa1+was2 was1:Dmgr app01 oracle ihs was2:Dmgr app02 原理:通过Dmgr管理下面两个agent,再通过agent去间接控制运行在节点上的ser ...
- oracle ebs 加锁
DECLARE -- lock l_lockname VARCHAR2(100); l_lockhandle VARCHAR2(200); l_lock_output NUMBER; l_locked ...