background
Recently, there is a need to test the SLB layer 4 load balancing performance, that is, to test the maximum number of TCP connections and connection speed. In this test, we chose to use Jmeter.
Single machine commissioning
Write the TCP server
#! /usr/bin/python3
# -*-coding:utf-8 -*-
from socket import *
import time
COD = 'utf-8'
HOST = '0.0.0.0' # host IP
PORT = 9999 # port
BUFSIZ = 1024
ADDR = (HOST, PORT)
SIZE = 10
tcpS = socket(AF_INET, SOCK_STREAM) # Create socket object
tcpS.setsockopt(SOL_SOCKET,SO_REUSEADDR,1) # Add socket configuration, reuse IP and port
tcpS.bind(ADDR) # Binding IP port number
tcpS.listen(SIZE) Set maximum number of links
while True:
print("Server started, listen for client links.")
conn, addr = tcpS.accept()
print("Linked client", addr)
while True:
try:
data = conn.recv(BUFSIZ) # Read sent messages from linked customers
except Exception:
print("Disconnected client", addr)
break
print("What the client sends :",data.decode(COD))
if not data:
break
msg = time.strftime("%Y-%m-%d %X") # Get a structured event stamp
msg1 = '[%s]:%s' % (msg, data.decode(COD))
#conn.send(msg1.encode(COD)) # Send message to linked client
conn.send('666}'.encode(COD))
conn.close() Close the client link
tcpS.close()
Copy the code
Write Jmeter scripts
1. Create a thread group
2. Thread group configuration
As above, means initiate10
Wan long link, in1000
Complete in seconds, loop once.
Add TCP Sampler
4, configuration, TCP Sampler
You can query the specific parameter meanings online. For details, seeEOL
Usually corresponds to the last character returned by the serverbyte
Said. The last character returned by the server in this test is"}"
, therefore,EOL
为 125
.
5. Add result listeners
Start the server and initiate the test
distributed
Since we are going to test millions of links this time, we need to prepare several Linux machines in advance for testing.
Install JDK on test machine
1, 2, upload download JDK offline package https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/8/jdk/x64/linux/ offline package on Linux machine and extract the PWD/root/tar ZXVF. - 3. Run the CD /usr/mkdir Java CD java/mv /root/jdk8u292-b10/.cd command to open jdk8u-jdk_x64_linux_hotspot_8u292b10.tar. gz command Jdk8u292-b10 / PWD /usr/java/jdk8u292-b10 4. Configure the profile vi /etc/profile and add export to the profile JMETER_HOME = / root/apache jmeter - 5.4.1 export JAVA_HOME = / usr/Java/jdk8u292 - b10 export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JMETER_HOME/lib/ext/ApacheJMeter_core.jar:$JMETER_HOME/lib/jorph an.jar:$CLASSPATH export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOMR/bin::$JMETER_HOME/bin:$PATH:$HOME/binCopy the code
Install Jmeter on the test machine
1. Copy the downloaded apache-jmeters-5.4.1. zip file to the Linux machine. 2 3. Configure the profile (already configured in the JDK) using the vi /etc/profile command. Add the following content to the profile: export JMETER_HOME=/root/apache-jmeter-5.4.1 export JAVA_HOME=/usr/java/jdk8u292-b10 export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JMETER_HOME/lib/ext/ApacheJMeter_core.jar:$JMETER_HOME/lib/jorph an.jar:$CLASSPATH export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOMR/bin::$JMETER_HOME/bin:$PATH:$HOME/binCopy the code
Check JDK and Jmeter
[root@test-2 ~]# Java -version openJDK version "1.8.0_292" OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_292-b10) OpenJDK 64-bit Server VM (AdoptOpenJDK)(build 25.292-b10, mixed mode) [root@test-2 ~]# jmeter --version _ ____ _ ____ _ _ _____ _ __ __ _____ _____ _____ ____ / \ | _ \ / \ / There comes ___ | | | | | | | \ there comes there comes / | | _ _ | | _ \ / _ \ | | _) / _ \ | | | | _ | | _ _ - | | | | \ / | | _ | | | | _ | | | | / ___ \ | _) __ / ___ \ | ___ _ - | | | ___ | | _ | | | | | | ___ | | | | ___ | _ < / / _ \ _ \ _ | there comes / _ \ _ \ | _ | | _ | | \ _____ _____ / | _ | | _ | _____ | | _ | | | _____ _ | \ _ \ 5.4.1 Copyright (c) 1999-2021 The Apache Software Foundation/root @ test - 2 ~ #Copy the code
This was the case for both JDK and Jmeter installations on the 21 test machines. Next, configure Jmeter on the test machine
Jmeter Slave configuration
Change server_port=7890 in the %JMETER_HOME%/bin/jmeter.properties file. This port number can be customized. 2. Generate a JKS file. On the master, run %JMETER_HOME%/bin/create-rmi-keystore.sh to generate rmi_keystore. JKS, and copy the JKS file to %JMETER_HOME%/bin/ of 20 slaves.Copy the code
Jmeter Master configuration
Modify %JMETER_HOME%/bin/jmeter.properties file and add remote_host= slave1_IP :7890, slave2_IP :7890, slave20_IP :7890 Configure the IP addresses and ports of all 20 slavesCopy the code
Perform the test
Jmeter -jthreadnum = 100-jtime = 200-n -t /root/tcp. jmx-r -l /root/log. JTL # Parameter Meaning -n noGUI -t jmeter script -r remote mode -l logsCopy the code
The console prints some logs during the test, and you can add a listener to the Jmeter GUI and read the results from the JTL file.
The server checks the number of connections
netstat -ant |grep 9999
Copy the code