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工具.他的工作原理为 ...
随机推荐
- web基础(3):CSS样式
chapter4 CSS样式 html是网页的内容和结构:CSS是网页的样式.内容和样式相分离,便于修改样式. CSS cascading style sheets 层叠样式表.一个内容上面可以添加多 ...
- nginx热更新流程记录
已经做过不止一次的nginx热更新了,之前都是按照别人的路子照葫芦画瓢,现在根据我在的项目单独写一个nginx热更新流程备份自用. nginx热升级流程上传新tar到/home/cp命令复制到/usr ...
- 通过ESP8266WiFi模块调用“心知天气”接口 获取天气信息
在分析代码之前,首先介绍 ArduinoJson 库的安装及"心知天气"的ID申请 一.安装 ArduinoJson 库 进入 Arduino 开发环境后,选择菜单栏-->工 ...
- 至少有K个重复字符的最长子串
传送门 /** * 分治 */ class Solution { // dp[i]:表示以i为结尾满足条件的子串的长度 public int longestSubstring(String s, in ...
- 安防视频监控系统前端摄像机——DSP与SOC摄像机
一.DSP摄像机 DSP(Digital Signal Processing)即数字信号处理,它是利用数字计算机或专用数字信号处理设备,以数值计算的方法对信号进行采集.变换.综合.估值.识别等加工处理 ...
- docker停止所有窗容器
docker中 启动所有的容器命令docker start $(docker ps -a | awk '{ print $1}' | tail -n +2) docker中 关闭所有的容器命令dock ...
- html入門 如何 區別行級元素 和 塊級元素
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- 在LUbuntu上搭建Neovim+Markdown环境
前言 想搭建自己的电子笔记系统.一开始用VMware+Ubuntu,后来想,如果这个虚拟机文件比较小,就可以用克隆到U盘里,随身带了. 于是转Lubuntu. 总体步骤 安装系统 安装neovim 安 ...
- Worksheet使用方法
1 下载印象笔记: iPhone/iPad在App Store搜索"印象笔记"后下载 安卓在应用市场或在印象笔记官网yinxiang.com下载,图标同上 电脑可至印象笔记官网y ...
- HarmonyOS基础
目录 自适应布局 自适应拉伸布局 自适应缩放 自适应延伸 组件多态 ArkUI开发框架 基础组件 Text组件和Span组件 参考 参考:harmonyos3: 鸿蒙ArkUI eTS教程配套源码 参 ...