JMeter implementation of interface and performance testing methods for WebSocket protocols

Source: Internet
Author: User

WebSocket protocol is a new protocol for HTML5. It implements browser-to-server full-duplex communication (Full-duplex).

Browsers and servers only need to do a handshake, and then a fast channel is formed between the browser and the server. The data can be transmitted to each other directly between the two. In this WebSocket agreement, there are two major benefits to our Instant service: 1. Headers that communicate with each other are very small-about 2 Bytes2. Server push below is client browser request and server response Browser RequestGet/demo http/1.1host: Your URL. comconnection:upgradesec-websocket-key2:12998 5 Y3 1. P00upgrade:websocketsec-websocket-key1:4 @1 46546xw%0l 1 5origin:http://your URL. com^n:ds[4u Server Responsehttp/1.1 101WebSocket Protocol handshakeupgrade:websocketconnection:upgradesec-websocket-origin:http:// Your URL. comsec-websocket-location:ws://your URL. Com/demosec-websocket-protocol:sample8jks ' y:g*co,wxa-  The above is a websocket not a detailed explanation and definition, let's see how to use JMeter to implement WebSocket interface testing and performance testing:  first, We need to prepare a support plugin for the JMeter websocket protocol: Jmeterwebsocketsampler-1.0.2-snapshot.jar This plugin relies on several jar packages 1, Jetty-http-9.1.2.v20140210.jar2, Jetty-io-9.1.2.v20140210.jar3, JETTY-UTIL-9.1.2.V20140210.JAR4, WEBSOCKET-API-9.1.1.V20140108.JAR5, WEBSOCKET-CLIENT-9.1.1.V20140108.JAR6, Websocket-common-9.1.1.v20140108.jar We have these jar packages ready, we'll copy them to the \lib\ext\ directory in the JMeter directory.   Second, start JMeter, right-click Test Plan, add->threads (users), thread group, such as:  again, select the right mouse button to select the thread group that you added in the previous step, and then add->sampler- >websocket Sampler, such as:  websocket after the creation of the test plan tree, such as: In the diagram, also created, view the results tree, generate summary Results shared table View results, this three can be right mouse button Select thread Group, add, Listener, primarily to see the results of jmeter execution websocket.   Finally, we need to configure WebSocket address, port, request and parameters, such as: 1, Server Name or Ip:websocket server address, 2, Port Number:websocket service access ports;   3, Protocol"WS/WSS": according to their own actual situation fill in; 4, request data: Need to send requests, according to the actual situation, my is to send a JSON string, the request data is done parameterized processing, you can directly fill in the string: {"OpenID": " O-8pqwy4nb5k_n2nn-ydzj3mlj8u "," Servcode ":" 900001 "}, performed, results in the result tree view.   To this, we have completed the JMeter websocket access settings, then, we have to do interface and performance testing must be parameterized, otherwise, is not a request repeated execution, how to parameterize it. First, we need to create a text file that requires parameterized fields to be separated by commas (or, of course, with other separators), such as: A, A, a, two field content, especially if the string itself has double quotation marks, here also add. Save the created text file and change it to a. bat end file.   Second, right-click Select Thread Group, add and configure components, select: CSV Data Set Config, add a parameterized file (JMeter has several parameterization, here with CSV example), such as: in Configure the CSV Data Source Group: 1, Filename: The full path of the. bat file requested in the previous step, 2, File encoding: The encoding format of the files, according to the actual situation; 3, Variable Names (comma-delimited): Field name , multiple comma-separated 4, Delimiter (use ' \ t ' for tab): Define delimiters, such as commas, directly fill in the comma symbol 5, allow quoted data? : The option to "true" when the processing of full-width characters is garbled 6, Recycle on EOF: Whether to iterate, CSV Data Set config read one line at a time, split into a number of variables to a thread, if the number of threads more than the number of record lines of text, Then you can choose to read the 7 again from the beginning, Stop thread on EOF? : When recycle on EOF is false, when the file is read to the end, the process is stopped, and when recycle on EOF is true, the item is not meant to be set according to the actual situation. After all the settings are complete, save. It is important to note that if the configuration is not correct, you can postpone parameterization, directly in the WebSocket page fill in Request data, run, view the results, if successful return, at the beginning of the parameterization.  Line JMeter test Plan, in the results tree can see the results of the send and the server returned, such as:  is the execution of the results of the viewing tree, you can see in the right window the sampler results, request, response data, where the request is the client sent to the server request, The response data is the result returned by the server after receiving the request, and you can choose a different view of the results, JSON, HTML, XPath, and so on.   At this point, our jmeter on the WebSocket set up, can be based on their own needs to add other tasks to complete the interface and performance testing, of course, in this article, I did not write a checkpoint and other results to judge, you can according to their own needs to do the checkpoint settings.

JMeter implementing interface and performance testing methods for the WebSocket protocol

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.