当前位置:网站首页>JMeter websocket interface test
JMeter websocket interface test
2022-07-25 21:58:00 【Xiaowu knock code】
Preface
In a website , A lot of data needs to be updated immediately , For example, user assets of futures trading . In the past , The implementation of this function generally uses http polling , That is, the client sends a query request to the server every other period of time with a scheduled task to obtain the latest value . The disadvantages of this method are obvious :
It may cause data update not in time , If the front-end polling frequency is 5s, Maybe the data is here 5s It has been updated many times .
It may cause additional pressure on the database , For example, a user asset does not change for a long time , But the client still needs to query regularly , Such meaningless queries account for a high proportion , Put unnecessary pressure on the server .
There are two interactions of request and response , Increased time consumption , and http The request may carry a large number of header Information , Increase the occupation of network bandwidth
HTML5 Start by offering one in a single TCP A protocol for full duplex communication on a connection -WebSocket, Well solved http Disadvantages of polling .
stay WebSocket API in , All browsers and servers need to do is shake hands , then , This creates a fast channel between the browser and the server . Data can be transmitted directly between the two .
in other words ,http Polling mechanism , The initiative is entirely on the client , and WebSocket In mechanism , The initiative can be handed over to the server , Data push can be more accurate , Including when to push ( Regular push or update push ), What data to push .
preparation
JMeter It can be carried out very conveniently WebSocket The interface test , However, the following dependencies need to be introduced :
jetty-http
jetty-io
jetty-util
websocket-api
websocket-client
websweocket-common
Dependent downloads :
https://pan.baidu.com/s/1PTOyTBzmOwLPNhxB-TxR7g , Extraction code :uq25
The following is based on JMeter5.1.1
Will be related to jar Put in bags JMeter Installation directory /lib/etc in , restart JMeter. In the sampler , You can see more than before websweocket Relevant sampler .
scripting
Before writing a script , First, we need to understand the logic of push service , Its logic is like this :
First , The client sends the request to the server , Establishing a connection
Once the connection is established , The client needs to send to the server regularly ping-pong news , Keep your heart beating
The client sends a request to actively disconnect , The server disconnects the connection
Establishing a connection , Use 【WebSocket request-response Sampler】, seeing the name of a thing one thinks of its function , This sampler can send requests and receive responses .
Explain the contents :
Connection: Yes use existing connection and setup new connection Two modes , The former uses existing connections , The last one websocket Request the established connection channel , After selection Server URL All grayed out, read-only, and inoperable . The latter refers to the new connection channel .
Server URL:ws The protocol and wss( Encrypted websocket) Optional ,sever name or IP( Server address )、Port( Port number )、Path( route )、Connection timeout( Connection timeout ) These meanings are also very clear .
Data: send data , You can choose Text( Text , Include JSON) and Binary( Binary system ) form , You can also check Read request data from file To get from the file data.
This request should be the same thread as the connection request , And run regularly , Therefore, the script structure is designed as follows :
Pay attention to two points :
1. Want to build 3000 If there's a connection , It must be 【 Number of threads 】 Set to 3000, The number of cycles is set to 1, Not the opposite , This is easily confused by many people .
2.【Ramp-up Time 】 This parameter is the start time of all threads , If you want to put more instantaneous pressure on the server , Just set the time shorter . Through the measured , If this time is too short , Finally, the number of successful connections will be significantly less than that set 【 Number of threads 】, So the setting is usually longer .
General websocket Push service , Will design a timed heartbeat detection mechanism , That is, the client sends a specific message to the server regularly , In this way, the server will maintain this connection , Otherwise , The client is determined to be inactive by the server and disconnected . therefore , In order to keep our script running , You need to add a heartbeat detection request .
Because the number of thread cycles is 1 Time ( Many times , A thread repeatedly establishes a connection ), So we have to put 【 The heartbeat detection 】 Put it into a cycle controller .
and 【 Fixed timer 】 The role of , It's control 【 The heartbeat detection 】 Frequency of transmission :
The heartbeat detection :
Pay special attention to two points :
1.Connection Items must be selected use existing connection, Indicates the connection established by this thread , Otherwise, the connection will be re created .
2.Request data It depends on the implementation of the server .
Finally, thank everyone who reads my article carefully , The following online link is also a very comprehensive one that I spent a few days sorting out , I hope it can also help you in need !

These materials , For those who want to change careers 【 software test 】 For our friends, it should be the most comprehensive and complete war preparation warehouse , This warehouse also accompanied me through the most difficult journey , I hope it can help you ! Everything should be done as soon as possible , Especially in the technology industry , We must improve our technical skills . I hope that's helpful ……
If you don't want to grow up alone , Unable to find the information of the system , The problem is not helped , If you insist on giving up after a few days , You can click the small card below to join our group , We can discuss and exchange , There will be various software testing materials and technical exchanges .
Typing is not easy , If this article is helpful to you , Click a like, collect a hide and pay attention , Give the author an encouragement . It's also convenient for you to find it quickly next time .
Self study recommendation B Stop video :
Zero basis transition software testing : Self taught software testing , Got the byte test post offer, Is the B The best video station !
Advanced automation testing : Huawei has landed , Salary increase 20K,2022 Most suitable for self-study python Automated test tutorial , Spend it yourself 16800 Bought , Free sharing

边栏推荐
- Animation curves are used every day. Can you make one by yourself? After reading this article, you will!
- [fan Tan] in detail: lower control, upward management, upward drawing cake.
- Basic knowledge in the project
- 卸载npm和安装npm_使用`npm uninstall`卸载npm软件包「建议收藏」
- Performance debugging -- chrome performance
- Special class design
- [fan Tan] those stories that seem to be thinking of the company but are actually very selfish (I: building wheels)
- 立创EDA——我为什么要学EDA
- 五种分配方式是否会产生内部碎片、外部碎片
- I/o case practice
猜你喜欢

分享|智慧消防应急管理平台解决方案(附PDF)

磁盘空间的三种分配方式

6-18漏洞利用-后门连接

Bitcoin.com:usdd represents a truly decentralized stable currency

6-17漏洞利用-反序列化远程命令执行漏洞

【leetcode天梯】链表 · 876 查找链表中间结点

在进行自动化测试,遇到验证码的问题,怎么办?

Babbitt | metauniverse daily must read: the popularity of virtual people has decreased, and some "debut is the peak", and the onlookers have dispersed

关于接口测试你想知道的都在这儿了

Shopify sellers: share some tips for social media marketing!
随机推荐
虚拟内存与磁盘
【Redis底层解析】链表类型
Dovecot set mailbox quota
Special class design
Performance debugging -- chrome performance
C语言:随机生成数+冒泡排序
Create files, file permissions, ownership, and sticky bits
3. Editors (vim)
[fan Tan] after the arrival of Web3.0, where should testers go? (ten predictions and suggestions)
[51Nod1676 无向图同构]无向图哈希[通俗易懂]
How will Web3 change the future of people?
【Redis底层解析】字符串类型
ansible+Crontab批部署巡检
[interview: concurrent Part 24: multithreading: comprehensive exercise] sequence control
ZigBee development board (nxpzigbee Development)
Bitcoin.com:USDD代表了真正去中心化稳定币
Ability to choose
The file cannot be saved (what if the folder is damaged and cannot be read)
Animation curves are used every day. Can you make one by yourself? After reading this article, you will!
选择的能力