当前位置:网站首页>Use JMeter to test services based on websocket protocol
Use JMeter to test services based on websocket protocol
2022-07-19 02:36:00 【Insomnia book】
Use JMeter The test is based on WebSocket Agreed services
One 、WebSocket What is it? ?
Example :WebSocket It is a two-way network communication protocol , And HTTP Different , It uses ws:// or wss:// start . It's a stateful protocol , This means that the connection between the client and the server will remain active , Until the connection is closed by either the client or the server , The connection will terminate at both ends .
Two 、 Why WebSocket
For the first time contact WebSocket People who , They all ask the same questions : We already have HTTP agreement , Why another agreement is needed ? What benefits can it bring ?
The answer is simple , because HTTP There is a flaw in the agreement : Communication can only be initiated by the client .
for instance , We want to know the weather today , Only the client can make a request to the server , The server returns the query result .HTTP The protocol can't make the server actively push information to the client .
This one-way request feature , Doomed if the server has continuous state changes , It is very difficult for the client to know . We can only use " polling ", Every once in a while , Just send out an inquiry , Find out if the server has any new information . Polling is inefficient , It's a huge waste of resources . therefore , Engineers have been thinking , Is there a better way ,WebSocket That's how it was invented .
WebSocket The most important feature of the game is , The server can actively push information to the client , The client can also send information to the server , It's really a two-way equal dialogue , This is a type of server push technology .
3、 ... and 、WebSocket Sampler Simple use
1. install WebSocket Plug ins and dependency packages
Method 1:
open JMeter After the plug-in manager , Click on Available Plugins Options page , Type in the search box WebSocket, Then choose install WebSocket Sampler by Maciej Zaleski plug-in unit 

Method 2: Copy downloaded jar Package to jmeter Of /lib/ext Under the table of contents , And restart jmeter
JMeterWebSocketSamplers-1.2.8.jar
jmeter-websocket-samplers-source
2. Add sampler
WebSocket Sampler How to add components : Choose “ Thread group ” Right click —> add to —> Sampler —> WebSocket Sampler
Add a sampler according to the needs of the scene , Can be added websocket There are seven kinds of samplers :
1)WebSocket Close —— close ws Connect
2)WebSocket Open Connection —— open ws Connect
3)WebSocket Ping/Pong —— ping/pong heartbeat , Check whether the connection still exists
4)WebSocket Sampler
5)WebSocket Single Read Sampler —— Only receive responses ( Message push )
6)WebSocket Single Write Sampler —— Send only requests
7)WebSocket request-response Sampler —— Send request and receive response
The interface is shown in the figure below :
3.WebSocket Sampler Detailed explanation of sampler interface

Description of the options in the interface :
name :WebSocket Sampler The custom name of the component , It's best to see the name and know the meaning .
notes : That is to add some remarks , For the WebSocket Sampler A brief description of the component , For later review .
(1)WebServer
Server Name or IP: The destination server that sent the request IP Address or domain name .
Port Number: The port number after the server address , If yes, fill in , No need to fill in .
(2)Timeout (milliseconds)
Connection: Maximum timeout for link establishment , Unit millisecond . If the link is not established after the timeout is set , be sampler Failure .
Response : The maximum waiting time for a response message , Unit millisecond . After reaching the set time WebSocket Link off .
(3)WebSocket Request
Implementation: Only support RFC6455(v13) ,WebSocket The latest version of the protocol standard .
Protocol: Yes ws And wss Points .ws The prefix is WebSocket Identification of the connection ,wss The prefix is WebSocket Identification of secure connections . Fill in according to the actual situation of the interface you need to access .
Content encoding: Content encoding . It is recommended to write in Chinese UTF-8.
Connection Id: Connect ID.
Path: The path to the access interface .
Ignore SSL certificate errors: Ignore SSL Certificate error .
Streaming connection: choice TCP session Do you want to keep , If you tick the logo, the connection will always exist , If it doesn't tick , Then the link will be closed after the first response .
(4) Send the parameters with the request
Can be filled in key-value Parameters of form .( It doesn't seem to work very well , The request parameters are filled in below Request data In the! )
Request data: Fill in the parameters sent with the request , And HTTP The sampler is similar to , Configure the interface according to the description document of the tested interface .
(5)Web Socket Response: Interface response related settings
Response pattern: The sampler will wait for the message containing the ID and continue to communicate ( Or until timeout, The connection is closed )
Close connection pattern: If the message returned by the server contains filled characters , Just end the conversation .
Proxy Server (currently not supported by Jetty): Edit proxy server information ( Currently does not support Jetty)
Server Name or IP: The server IP Address or domain name .
Port Number: Port number .
Username: user name .
Password: password .
Message Backlog: Define the maximum length of messages returned by the server .
4.WebSocket Sampler Interface example
(1) Edit the information in the sampler 
(2) add to —> Monitor —> Look at the fruit tree 
(3) Run view results
Four 、 Set the sampler sequence mode
Set the sequence of sampler execution , It's usually :
1) Use WebSocket Open Connection, establish ws Connect ;
2) Use WebSocket Single Write Sampler, Request subscription related data ;
3) Use WebSocket Single Read Sampler, Receive message push ;
4) Use WebSocket Ping/Pong, Determine long connection ;
5) Use WebSocket Close, close ws Connect . notes :WebSocket request-response Sampler Both request and response functions , Choose according to your needs .
1.WebSocket Open Connection
Set up ws Related connection information :
2.WebSocket Single Write Sampler
Use an existing connection , Send subscription request :
3.WebSocket Single Read Sampler
Use an existing connection , Receive message push :
4.WebSocket Ping/Pong
The heartbeat detection :
5.WebSocket Close
close ws Connect :
6. function , View the result tree

summary
above , Just the whole content I share with you this time , If you think it's good , Please leave a like ! Of course, I'm looking forward to your reward
If you have any ideas , Welcome to contact me ~
边栏推荐
猜你喜欢

How to configure multiple SSH keys for novices (easy to understand hand-in-hand teaching)

InnoDB, MySQL structure, and the difference between the three kinds of deletion

攻防世界----easytornado笔记

Detailed explanation of caduceus project of metauniverse public chain (I): project concept and technical framework of caduceus metaverse protocol

jmeter连接数据库的方法

Cocoon breaking and rebirth of 3D NFT: caduceus decentralized edge rendering technology

全链路压测

Method of JMeter connecting to database

General knowledge of network (detailed)

bugku----正则匹配,cookies
随机推荐
SSTI模板注入
Next array - circular section
剑指 Offer 53 - I. 在排序数组中查找数字 I
[tools] Application of SQLite local database in unity3d
postman的json脚本转jmeter的jmx脚本
2022 latest software testing tools
子网划分(详)
Detailed explanation of metauniverse public chain caduceus: a creative platform specially built for metauniverse application
流量回放工具gor使用经验
树状数组与ST表
[antv G2] how to solve the memory leak caused by G2
VLAN和TRUNK口配置
The solution to the bounce and offset of unity3d game characters when jumping to the ground
仅以此篇纪念负数取模
BeanShell script gets the current time
Array transformer blocking idea
Performance test implementation specification Guide
bugku----正则匹配,cookies
Shortest circuit / secondary short circuit /k short circuit
next数组-循环节