jmeter test TCP server / simulate sending TCP request to set hexadecimal send (transfer)

Reprinted and retained: http://blog.sina.com.cn/s/blog_46d0362d0102v8ii.html

Performance testing needs to simulate a variety of scenarios, often subject to resource constraints, and there is no way to create scenarios that are close to the actual deployment environment. Therefore, it is necessary to simulate the approximate environment with the help of some features provided by software and hardware. JMeter mentioned in this article is an open source simulation test solution that can continuously provide stress test sources through multi-threaded concurrency.

 

1. Download and install

Just find the download package from the apache website and unzip it to the local file directory.

http://jmeter.apache.org/download_jmeter.cgi

 

2. Start

There is a bin directory in the decompression directory, there are many batch files and script files, and the window system can run jmeter.bat. What needs to be paid attention to is the jmeter.properties file in the bin directory, which is a configuration file related to running. In particular, several configurations in the TCP Sampler configuration part will be related to the following content

 

3. Build a type test

Only the simple tcp test establishment steps are described here, because there are many test types currently supported and cannot be stated one by one. For functional details, please refer to the JMeter documentation

1) Create a test thread group


2) Set thread group parameters as needed


3) Establish TCP sampling


3) Configure TCP sampling parameters


Basically a simple test plan is done, hit run sample and the text will be sent.


4. Advanced function configuration

1) Configuration result view listener

Sometimes it is necessary to view the execution results of the thread group, which can be viewed by setting the sampling results

 

 

The thread group configured above should be executed 6 times, that is, 6 messages are sent. It can be seen through the monitor that there are indeed 6 sampling results, indicating that the execution is successful.

 

 

2) Configuration variables

Sometimes it is necessary to add some changed content to the message, which can be achieved by adding variable settings in the text


For example, if a variable name bank is added, its value is 1111, which can be quoted by adding ${bank} to the previously sent message, such as




After execution, you can see 1111 in the message in the monitor

 

3) Configure the TCP binary message

In most cases, the messages may not be in plain text, and are often unreadable binary, so in this case, you need to configure binary messages. Currently JMeter supports HEX form, which is hexadecimal message input configuration

Reference:  https://wiki.apache.org/jmeter/UserManual/Reference/TcpSampler

Currently supports three formats 1.TCPClientImpl (default) 2.BinaryTCPClientImpl 3.LengthPrefixedBinaryTCPClientImpl

 

To use binary mode, you need to do the following things:

a. Translate ordinary text messages into HEX format, you can find a text editor to do this. Such as notepad++, open a text file

Ctrl+A selects all content, pastes it to a new file, and replaces all spaces

3c3f786d6c2076657273696f6e3d22312e302220656e636f64696e673d225554462d3822207374616e64616c6f6e653d22796573223f3e3c544c533e3c707273636f64653e6c6f67696e3c2f707273636f64653e3c69643e313233343536373c2f69643e3c746f6b656e3e75736a64666a6b736137356b733833326f6b7564736a643934383737616b6a6475613c2f746f6b656e3e3c2f544c533e

 

 


If the header needs to be added to the message, additional calculation is required. For example, add a command id and message length. For example, the text length in the above text is displayed as 155 on the editor status bar, assuming the command id is 1.

System.out.println("155 hex " + Integer.toHexString(155));  --- 9b
System.out.println("1 hex " + Integer.toHexString(1));  ---1

If the command id is 4 bytes then the hex string is 00 00 00 01

If length is also 4 bytes then the hexadecimal string is 00 00 00 9b

Remove the spaces and add it to the previous message to make the following new message

000000010000009b3c3f786d6c2076657273696f6e3d22312e302220656e636f64696e673d225554462d3822207374616e64616c6f6e653d22796573223f3e3c544c533e3c707273636f64653e6c6f67696e3c2f707273636f64653e3c69643e313233343536373c2f69643e3c746f6b656e3e75736a64666a6b736137356b733833326f6b7564736a643934383737616b6a6475613c2f746f6b656e3e3c2f544c533e

 

Then put the new message into the send string input box.

 

b. Modify the JMeter startup configuration, which is the specified BinaryTCPClientImpl adaptation mentioned above

Find the following section in the jmeter.properties file and modify it

#---------------------------------------------------------------------------
# TCP Sampler configuration
#---------------------------------------------------------------------------

# The default handler class
#tcp.handler=TCPClientImpl
tcp.handler=BinaryTCPClientImpl

 

Re-execute the TCP test, you can see that the server receives the message normally, as shown in the figure

 

jmeter tests the TCP server and uses the TCP sampler to simulate sending TCP requests.

TCP Sampler: Opens a TCP/IP connection to the specified server, then sends the specified text and waits for a response.

jmeter simulates the method of sending a TCP request:

1. Create a new thread group, and then create a new TCP sampler in the thread group

jmeter-tcp

Fill in the server address, port and "text to send" in the TCP sampler, and other options are optional as needed:

re_use connection means to send the connection request repeatedly

close connection close the connection

If the TCP request requires a username/password, it can be filled in the login configuration

2. Create a "View Result Tree" monitor to view the sent request and response results. If you need to send a hexadecimal message, this place will fail.

How jmeter sends hexadecimal TCP packets:

Many TCP server packets are hexadecimal, and most of them cannot be converted into text for transmission, while jmeter sends text by default.

Modify tcp.handler=BinaryTCPClientImpl in jmeter.properties, start jmeter to resend, and capture packets to view both hexadecimal tcp packets.

Another method: You can create a new - non-test component - Property Display in the workbench, and modify jmeter.properties in the Property Display, which is only valid for the current process.

Please indicate the source when reprinting: 6san.com  
Original address:  http://www.6san.com/716/

 

Jmeter TCP sampler configuration and sending diagram

 

Recently, when testing TCP sending requests through Jmeter, I encountered related problems, which are now recorded.

Looking at the management documentation, there are three ways to enable TCP sending:

  • TCPClientImpl: text data, the default is this
  • BinaryTCPClientImpl: transmit hexadecimal data, specify the end of the packet. This hex file will be converted through the Jmeter GUI
  • LengthPrefixedBinaryTCPClientImpl: The first 2 bytes in the data packet are the data length. It can be set in tcp.binarylength.prefix.length in the bin/jmeter.properties configuration file.

 

In the actual process of capturing packets, TCP data packets are often not plain text, but are often binary files and the like, so here we directly use hexadecimal to transmit data.

Before starting jmeter, it needs to be set in the startup file, as follows:

#---------------------------------------------------------------------------
# TCP Sampler configuration
#---------------------------------------------------------------------------

# The default handler class
#tcp.handler=TCPClientImpl
tcp.handler=BinaryTCPClientImpl
#
# eolByte = byte value for end of line
# set this to a value outside the range -128 to +127 to skip eol checking
#tcp.eolByte=1000

 

The key is here, how do I get this hexadecimal data? Here, wireshark can be used to solve this problem very well. The operation is as follows:

The following picture is the captured package, how to capture the package will not be introduced here:

Step 2: Right click on Data--->Copy-->Bytes-->HEX Stream, as shown below:

After completion, paste directly into the text box of Jemeter in Ctrl+V

The sending is successful, and the result tree is exactly what we want:

 

Reference documentation: http://jmeter.apache.org/usermanual/component_reference.html#TCP_Sampler

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324956799&siteId=291194637