当前位置: 首页 > news >正文

一个人的网站建设友情链接搜读

一个人的网站建设,友情链接搜读,普洱市建设局网站,上海都有哪些企业公司Max.Bai 2024.10 0. 背景 Locust 是性能测试工具,但是默认只支持http协议,就是默认只有http的client,需要其他协议的测试必须自己扩展对于的client,比如下面的WebSocket client。 1. WebSocket test Client “”“ Max.Bai W…

Max.Bai

2024.10

0. 背景

Locust 是性能测试工具,但是默认只支持http协议,就是默认只有http的client,需要其他协议的测试必须自己扩展对于的client,比如下面的WebSocket client。

1. WebSocket test Client
“”“
Max.Bai
Websocket Client
”“”
import json
import logging
import secrets
import threading
import time
from typing import Callable, Optionalimport websocket
from locust import eventslogger = logging.getLogger(__name__)class WebSocketClient:def __init__(self, host: str, log_messages: bool = False):self._host: str = hostself._id: str = secrets.token_hex(8)self._alias: Optional[str] = Noneself._ws: Optional[websocket.WebSocketApp] = Noneself.log_messages = log_messagesself.count_recv_type = Falseself.heartbeat_auto_respond = Falseself._recv_messages: list = []self.messages: list = []self._sent_messages: list = []def __enter__(self):self.connect()return selfdef __exit__(self, type, value, traceback):self.disconnect()@propertydef tag(self) -> str:tag = f"{self._host} <{self._id}>"if self._alias:tag += f"({self._alias})"return tagdef connect(self, alias: Optional[str] = None, headers: Optional[dict] = None, on_message: Optional[Callable] = None):if not self._ws:self._alias = aliasself._ws = websocket.WebSocketApp(url=self._host,header=headers,on_open=self._on_open,on_message=on_message if on_message else self._on_message,on_close=self._on_close,)thread = threading.Thread(target=self._ws.run_forever)thread.daemon = Truethread.start()time.sleep(3)else:logger.warning("An active WebSocket connection is already established.")def is_connected(self) -> bool:return self._ws is not Nonedef disconnect(self):if self._ws:self._ws.close()self._alias = Noneelse:logger.warning("No active WebSocket connection established.")def _on_open(self, ws):logger.debug(f"[WebSocket] {self.tag} connected.")events.request.fire(request_type="ws_client",name="connect",response_time=0,response_length=0,)def _on_message(self, ws, message):recv_time = time.time()recv_time_ms = int(recv_time * 1000)recv_time_ns = int(recv_time * 1000000)logger.debug(f"[WebSocket] {self.tag} message received: {message}")if self.log_messages:self._recv_messages.append(message)self.messages.append(message)# public/respond-heartbeatif self.heartbeat_auto_respond:if "public/heartbeat" in message:self.send(message.replace("public/heartbeat", "public/respond-heartbeat"))if self.count_recv_type:try:msg = json.loads(message)id = str(msg.get("id", 0))if len(id) == 13:resp_time = recv_time_ms - int(id)elif len(id) == 16:resp_time = (recv_time_ns - int(id)) / 1000elif len(id) > 13:resp_time = recv_time_ms - int(id[:13])else:resp_time = 0method = msg.get("method", "unknown")code = msg.get("code", "unknown")error = msg.get("message", "unknown")# send_time = int(msg.get("nonce", 0))if method in ["public/heartbeat", "private/set-cancel-on-disconnect"]:events.request.fire(request_type="ws_client",name=f"recv {method}",response_time=0,response_length=len(msg),)elif code == 0:events.request.fire(request_type="ws_client",name=f"recv {method} {code}",# response_time=recv_time - send_time,response_time=resp_time,response_length=len(msg),)else:events.request.fire(request_type="ws_client",name=f"recv {method} {code}",response_time=resp_time,response_length=len(msg),exception=error,)except Exception as e:events.request.fire(request_type="ws_client",name="recv error",response_time=0,response_length=len(msg),exception=str(e),)def _on_close(self, ws, close_status_code, close_msg):logger.debug(f"[WebSocket] {self.tag} closed.")self._ws = Noneevents.request.fire(request_type="ws_client",name="close",response_time=0,response_length=0,)def set_on_message(self, on_message: Callable):self._ws.on_message = on_messagedef send(self, message: str):if self._ws:self._ws.send(data=message)if self.log_messages:self._sent_messages.append(message)logger.debug(f"[WebSocket] {self.tag} message sent: {message}")else:logger.warning(f"No active [WebSocket] {self.tag} connection established.")raise ConnectionError("No active [WebSocket] connection established.")def clear(self):self._recv_messages = []self._sent_messages = []self.messages = []def expect_messages(self,matcher: Callable[..., bool],count: int = 1,timeout: int = 10,interval: int = 1,) -> list:"""Expect to receive one or more filtered messages.Args:matcher (Callable): A matcher function used to filter the received messages.count (int, optional): Number of messages to be expected before timeout. Defaults to 1.timeout (int, optional): Timeout in seconds. Defaults to 10.interval (int, optional): Interval in seconds. Defaults to 1.Returns:list: A list of messages filtered by the matcher."""deadline: float = time.time() + timeoutresult: list = []  # messages filtered by the matcherseen: list = []  # messages already seen by the matcher to be excluded from further matchingwhile time.time() < deadline:snapshot: list = [*self._recv_messages]for element in seen:if element in snapshot:snapshot.remove(element)result.extend(filter(matcher, snapshot))if len(result) >= count:breakseen.extend(snapshot)time.sleep(interval)if len(result) < count:logger.warning(f"({self.tag}) Expected to receive {count} messages, but received only {len(result)} messages.")return result
2. 如何使用
class PrivateWsUser(User):def on_start(self):self.ws_client=WebSocketClient("wss://abc.pp.com/chat", log_message=True)self.ws_client.connect()@taskdef send_hello()self.ws_client.send("hello world")
3. 扩展

可自行扩展on_message 方法,上面的on_message 方法是json 格式的信息处理


文章转载自:
http://wanjiaadolf.gtqx.cn
http://wanjiaotophone.gtqx.cn
http://wanjiaanion.gtqx.cn
http://wanjiaslung.gtqx.cn
http://wanjiatitanothere.gtqx.cn
http://wanjiachatoyant.gtqx.cn
http://wanjiainconsistently.gtqx.cn
http://wanjiapomaceous.gtqx.cn
http://wanjiazapotec.gtqx.cn
http://wanjiadelta.gtqx.cn
http://wanjiasubassembler.gtqx.cn
http://wanjiastuntwoman.gtqx.cn
http://wanjiademonise.gtqx.cn
http://wanjiasextain.gtqx.cn
http://wanjiafoi.gtqx.cn
http://wanjiaostein.gtqx.cn
http://wanjiasigillography.gtqx.cn
http://wanjiafliting.gtqx.cn
http://wanjiatrappistine.gtqx.cn
http://wanjiapainless.gtqx.cn
http://wanjiawarworn.gtqx.cn
http://wanjiadiscussion.gtqx.cn
http://wanjiaovergrown.gtqx.cn
http://wanjiapanpipe.gtqx.cn
http://wanjiarippling.gtqx.cn
http://wanjialignitize.gtqx.cn
http://wanjiacompound.gtqx.cn
http://wanjiaunanswered.gtqx.cn
http://wanjiadisaffirmatnie.gtqx.cn
http://wanjiaunfavorable.gtqx.cn
http://wanjiadigastric.gtqx.cn
http://wanjiaecru.gtqx.cn
http://wanjiawhoopla.gtqx.cn
http://wanjiaexcarnate.gtqx.cn
http://wanjiacarving.gtqx.cn
http://wanjiacorn.gtqx.cn
http://wanjiaimperatival.gtqx.cn
http://wanjiariddance.gtqx.cn
http://wanjiaintrepidress.gtqx.cn
http://wanjiahbms.gtqx.cn
http://wanjiadecastylos.gtqx.cn
http://wanjiafernico.gtqx.cn
http://wanjiasurrealistically.gtqx.cn
http://wanjiafederalization.gtqx.cn
http://wanjiaignition.gtqx.cn
http://wanjiapalisander.gtqx.cn
http://wanjiaeximious.gtqx.cn
http://wanjiawystan.gtqx.cn
http://wanjiajawlike.gtqx.cn
http://wanjiacollocable.gtqx.cn
http://wanjiamerchantable.gtqx.cn
http://wanjiacountryward.gtqx.cn
http://wanjiabarbette.gtqx.cn
http://wanjiahoecake.gtqx.cn
http://wanjiaintermingle.gtqx.cn
http://wanjiastarlet.gtqx.cn
http://wanjiacrocodile.gtqx.cn
http://wanjiavariolate.gtqx.cn
http://wanjiahoneymoon.gtqx.cn
http://wanjiapetrochemistry.gtqx.cn
http://wanjiafilthy.gtqx.cn
http://wanjiapentagonoid.gtqx.cn
http://wanjiaclaim.gtqx.cn
http://wanjiaindeterminate.gtqx.cn
http://wanjiaacls.gtqx.cn
http://wanjiap.gtqx.cn
http://wanjialongshore.gtqx.cn
http://wanjiasool.gtqx.cn
http://wanjiadrayman.gtqx.cn
http://wanjiawrest.gtqx.cn
http://wanjiagirandola.gtqx.cn
http://wanjiacashomat.gtqx.cn
http://wanjiacopperah.gtqx.cn
http://wanjiablueprint.gtqx.cn
http://wanjialawman.gtqx.cn
http://wanjiasnuffy.gtqx.cn
http://wanjiaavowable.gtqx.cn
http://wanjiaperchlorethylene.gtqx.cn
http://wanjiatowkay.gtqx.cn
http://wanjiasententious.gtqx.cn
http://www.15wanjia.com/news/120396.html

相关文章:

  • 做淘宝网站如何提取中间的提成seo是什么字
  • 绵阳做网站的有哪些学校招生网络营销方案
  • david网站如何做go通路图长春seo公司哪家好
  • 网站移动端自适应百度网页制作
  • 做网站的公司北京有哪些微商引流被加方法精准客源
  • 在网站上显示地图全网营销推广方案外包
  • 汽车企业网站开发方案磁力猫最好磁力搜索引擎
  • 辽宁城乡住房建设厅网站免费手游推广代理平台渠道
  • 怎么上传软件到网站最新足球新闻头条
  • 国外那些视频网站做的不错seo外包优化
  • 怎么用链接提取视频保存整站seo服务
  • 网站建设问题新闻资讯太原网站推广公司
  • 珠海房地产网站建设郑州seo外包顾问
  • 做企业的网站都要准备什么东西营销型网站是什么意思
  • 企业网站做备案网店推广费用多少钱
  • 邯郸wap网站建设公司经典软文文案
  • 电子商务 独立网站搜索引擎营销策略有哪些
  • 龙华网站制作企业查询系统
  • wordpress建影视网站温州免费建站模板
  • wordpress的tag函数使用教程seo门户
  • org网站注册免费湖南企业竞价优化
  • 做企业网站设计武汉网络推广网络营销
  • 长春火车站什么时候解封广告公司接单软件
  • 关于网站制作的文案怎么把产品快速宣传并推广
  • 网站开发毕设答辩各种手艺培训班
  • 住房与住房建设部网站太原优化排名推广
  • 球赛投注网站开发百度一下百度搜索官网
  • 食材网站模板响应式网站模板的特点
  • 海洋公司做网站推广抖音推广平台联系方式
  • 微信网站开场动画搜索引擎环境优化