当前位置:网站首页>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

边栏推荐
- [leetcode ladder] linked list · 021 merge two ordered linked lists
- 若依如何解决导出使用下载插件出现异常?
- YUV420 yuv420sp image format "recommended collection"
- Why do independent sellers like to do e-mail marketing? The original conversion rate can be improved so much!
- Ansible+cronab batch deployment patrol
- [hand torn STL] unordered_ set、unordered_ Map (encapsulated with hash table)
- C语言:随机生成数+冒泡排序
- 【饭谈】细说:下克上,向上管理,向上画饼。
- redis主从架构锁失效问题(主从)
- [51nod1676 undirected graph isomorphism] undirected graph hash [easy to understand]
猜你喜欢

Idea resolves the prompt of profile properties disappear

Pyg tutorial (8): calculate a more efficient sparse matrix form

JMeter websocket接口测试

ORIGYN基金会正式启动$OGY Staking,引领新一轮生态利好
![[leetcode ladder] linked list · 021 merge two ordered linked lists](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[leetcode ladder] linked list · 021 merge two ordered linked lists
![[hand torn STL] unordered_ set、unordered_ Map (encapsulated with hash table)](/img/33/08f7b72ce99e07821a1f4b6e594e13.png)
[hand torn STL] unordered_ set、unordered_ Map (encapsulated with hash table)

2 lines of code to generate a solid desktop background

Wet- a good choice for people with English difficulties - console translation

Bitcoin.com:usdd represents a truly decentralized stable currency

How to implement distributed locks with redis?
随机推荐
Web3 entrepreneurship has all the elements of explosive growth of innovation
Redis内存淘汰机制?
Redisv6.0为何引入多线程?
[interview: concurrent Article 23: multithreading: Join] re understanding of join
I/o case practice
信息安全建设原则指导
[dinner talk] those things that seem to be for the sake of the company but are actually incomprehensible (2: soft quality "eye edge" during interview)
[fan Tan] in detail: lower control, upward management, upward drawing cake.
6-18漏洞利用-后门连接
The second short contact of gamecloud 1608
ansible+Crontab批部署巡检
Oxford University: many common insomnia drugs lack long-term safety data
[Fantan] how to design a test platform?
[interview: concurrent Part 24: multithreading: comprehensive exercise] sequence control
[51nod1676 undirected graph isomorphism] undirected graph hash [easy to understand]
立创EDA——器件的创建01-电阻(二)
[MAIXPY]kpu: load error:2005, ERR_READ_FILE: read file failed问题解决
手机端微信发朋友圈功能测试点总结
Share | intelligent fire emergency management platform solution (PDF attached)
卸载npm和安装npm_使用`npm uninstall`卸载npm软件包「建议收藏」