First, run JMeter
(1) Go to the official website to download JMeter (version 3.3) and unzip. Click Bin/jmeter.bat to start JMeter
(2) Create a new thread group.
(3) New WebSocket Sample in thread Group
Ii. Introduction of WebSocket Sampler
1, WebServer
(1) address or name of the destination server sent by server name or Ip:websocket
(2) port number the Port Number:websocker server listens on. (typically an HTTP 80 port, which can be obtained via Wireshark packets)
2. Timeout:
(1) connection– The maximum time, in milliseconds, that JMeter waits for a connection to complete after sending a connection request.
(2) Response-The maximum wait time for the response message.
3. WebSocket Request
(1) implementation– only supports RFC6455 (V13), the latest version of the WebSocket protocol standard.
(2) protocol– has WS and WSS, the WS prefix is the distinguished identity of the WebSocket connection, and the WSS prefix is the distinguished identity of the WebSocket secure connection. Fill in according to your actual situation
(3) Streaming connection– Select this TCP session to maintain, if the hook on the identity of the connection will always exist, if not checked, then the first response after the link will be closed.
(4) Request data: Fill in the requests to be sent, to communicate with the development of good, this is what format message.
4.WebSocket Response
(1) Response pattern– Sampler will wait for the message containing the identity and continue to communicate (or until timeout, the connection is closed)
(2) Close Connection pattern– If the message returned by the server contains such a character, it ends the session.
(3) Message backlog– defines the maximum length that the server returns message retention.
third, the test
According to the online example, you can use http://www.websocket.org/echo.html this site to do some experiments, the website will receive the data (your request data) in the server response is returned as is.
Fill in the host information provided by the website can communicate with the website, here is my experiment, to understand JMeter WebSocket Sampler
1. Impact of streaming options
(1) do not tick streaming
The test plan is set up as follows:
Do not tick streaming connection results are as follows:
You can see that the ground control to Major Tom is returned, and the experiment was successful, from the result tree's sampler result execution Flow shows the relationship between the test results and our settings above: It took 5000 milliseconds to wait for the server to connect, 20000 milliseconds to wait for the server's message, and after receiving the first message, the WebSocket session was closed.
(2) Hook up streaming connection
Can see at the end of the test, the hook on the streaming that small hook, the end of the test streaming connection is still open.
(3) Send two messages
Sending only one message may not see the difference, copying WebSocket sampler and sending two messages. This allows you to see that the second message is sent when the connection is opened directly with the first message, and the server's response is categorized into the response window of the session.
(4), reference reference Document Set up a test (add a loop controller, set the number of cycles to 3)
The results are as follows:
The sampler in the loop are checked for streaming, and the last sampler does not tick this option, as can be seen in the results: the sampler in the loop controller uses a connection, The sampler outside the loop will open a new connection, and you can conclude that, in fact, when streaming connection is checked, not only will the connection be retained after the end of the session, but the selected sampler will be used directly in the available connection. The sampler without a checkmark will reopen a new connection even if there is an available connection. Therefore, if you are sending multiple messages in one session, tick this streaming
Connection
2. How to end a conversation artificially
This will use the response pattern and close pattern mentioned earlier, giving three requests without setting the response pattern and close pattern results to facilitate comparison
Then set the response pattern and close pattern in the first sampler as follows (because only one connection is established, the pattern setting information in the first sampler is read only)
In this way, when the second request responds with a response that does not conform to father, and the close pattern is met, the connection is disconnected, and the third websocket tick streaming use the previous connection, but in fact the connection is not connected to the remote terminal when it will be error. (The response response cannot be set to NULL in this case, and if the returned content is detected in accordance with response pattern, it will no longer be judged to conform to the close pattern.)
3. Message Backlog Settings
The above experiment uses the default 3, so if the three sockets in the experiment are all communicating in one session, clicking the third one can see the last three servers responding. When this option is set to 1 o'clock, only the most recent response message is visible.
JMeter for WebSocket interface testing