This article introduces what manometry is, explains its special terms and teaches us how to calculate manometry index. This paper introduces the common pressure measuring tools on the market (AB, LOCUST, Jmeter, Go implemented pressure measuring tools, cloud pressure measuring tools), compares these pressure measuring tools, teaches you how to choose a suitable pressure measuring tool, this paper also has two practical pressure measuring projects:

  • Single machine on HTTP short connection QPS 1W+ pressure test actual combat

  • Single machine 100W long connection pressure test actual combat

directory

  • 1. Project Description

    • 1.1 the go – stress – testing

    • 1.2 Project Experience

  • 2, pressure measurement

    • 2.3.1 Description of pressure measurement Types

    • 2.3.2 Interpretation of pressure measurement words

    • 2.3.3 Explanation of machine performance Indicators

    • 2.3.4 Description of Access Indicators

    • 2.1 What is manometry

    • 2.2 Why pressure measurement

    • 2.3 Interpretation of pressure measurement words

    • 3.4 How to Calculate pressure Measurement Indicators

  • 3. Common pressure measuring tools

    • 3.4.1 Introduction to cloud pressure measurement

    • 3.4.2 Aliyun performance test PTS

    • 3.4.3 Tencent Cloud pressure measurement master LM

    • 3.1 ab

    • 3.2 locust

    • 3.3 Jmeter

    • 3.4 cloud pressure measurement

  • 4, Go stress-testing go language to achieve pressure testing tools

    • 4.1 introduction

    • 4.2 usage

    • 4.3 implementation

    • 4.4 Go-stress-testing For Golang Web

  • 5. Comparison of pressure measuring tools

    • 5.1 compare

    • 5.2 How do I Select a Pressure Measuring Tool

  • 6, a single machine 100W connection pressure test actual combat

    • 6.1 illustrates

    • 6.2 Kernel Optimization

    • 6.3 Client Configuration

    • 6.4 to prepare

    • 6.5 Pressure test data

  • 7,

  • 8. References

1. Project Description

1.1 the go – stress – testing

Go implements a pressure measuring tool that is simulated by a coroutine per user to maximize CPU resources

1.2 Project Experience

  • Commands that can be executed on different MAC/Linux/Windows platforms

Parameter Description:

-c Indicates the number of concurrent requests

-n Number of concurrent requests. Total number of requests = Number of concurrent requests x Number of concurrent requests

-u Specifies the address for pressure measurement


     

    # clone project

    git clone https://github.com/link1st/go-stress-testing.git

    Enter the project directory

    cd go-stress-testing

    # run

    go run main.go -c 1 -n 100 -u https://www.baidu.com/

Copy the code
  • Display of pressure measurement results

After execution, the terminal will output the results every second, and output the results of the executed pressure test after completion of the pressure test

Pressure test results display:


     

    ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─

    Duration │ Concurrent │ Successes │ Failures │ QPS │ Maximum Duration │ Minimum duration │ Average duration │ Error code

    ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─

    1│ 1│ 8│ 0│ 8.09│ 133.16│ 110.98│ 123.56│200:8

    2│ 1│ 15│ 0│ 8.02│ 138.74│ 110.98│ 124.61│200:15

    3s│ 1│ 23│ 0│ 7.80│ 220.43│ 110.98│ 128.18│200:23

    4s│ 1│ 31│ 0│ 7.83│ 220.43│ 110.23│ 127.67│200:31

    5s│ 1│ 39│ 0│ 7.81│ 220.43│ 110.23│ 128.03│200:39

    6s│ 1│ 46│ 0│ 7.72│ 220.43│ 110.23│ 129.59│ 2003:46

    7S │ 1│ 54│ 0│ 7.79│ 220.43│ 110.23│ 128.42│200:54

    8s│ 1│ 62│ 0│ 7.81│ 220.43│ 110.23│ 128.09│200:62

    9S │ 1│ 70│ 0│ 7.79│ 220.43│ 110.23│ 128.33│200:70

    10s│ 1│ 78│ 0│ 7.82│ 220.43│ 106.47│ 127.85│200:78

    11s│ 1│ 84│ 0│ 7.64│ 371.02│ 106.47│ 130.96│200:84

    12S │ 1│ 91│ 0│ 7.63│ 371.02│ 106.47│ 131.02│200:91

    13S │ 1│ 99│ 0│ 7.66│ 371.02│ 106.47│ 130.54│200:99

    13S │ 1│ 100│ 0│ 7.66│ 371.02│ 106.47│ 130.52│200:100

    * * * * * * * * * * * * * * * * * * * * * * * * * the stat * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    Number of coroutines processed: 1

    Total number of requests: 100 Total request time: 13.055 seconds successNum: 100 failureNum: 0

    * * * * * * * * * * * * * * * * * * * * * * * * * the end * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Copy the code

Parameter Description:

Time: program running time. The program outputs pressure measurement results every second

Concurrency: the number of concurrency, the number of coroutines started

Successes: Indicates the number of successful requests during the pressure test

Failed number: indicates the number of failed requests in the pressure test

QPS: QPS of current pressure measurement (number of requests processed per second)

Maximum time: Indicates the maximum response time of a single request in the pressure test

Shortest time: The shortest response time for a single request in the pressure test

Average time: Average response time of a single request in a pressure test

Error code: code returned by the interface during pressure testing: set of returned times

2, pressure measurement

2.1 What is manometry

Pressure testing, or pressure testing, is a test method to establish the stability of a system. It is usually carried out outside the normal operating range of the system to investigate its functional limits and hidden dangers.

It mainly tests the bearing capacity of the server, including user bearing capacity (how many users play at the same time basically does not affect the quality), flow bearing, etc.

2.2 Why pressure measurement

  • The purpose of manometric testing is to measure machine performance (QPS per machine) through manometric testing (simulating the behavior of real users) to calculate how many machines the system would need to support a given number of users (100W)

  • Press-test is an estimation (rehearsal in advance) of the number of users that may be reached in the future before the launch. After press-test, the user experience is ensured by optimizing the performance of the program or preparing sufficient machines.

2.3 Interpretation of pressure measurement words

2.3.1 Description of pressure measurement Types

Pressure test type explain
Stress Testing Also known as strength test, it tests the maximum stress resistance of a system. Under the condition of heavy load (big data, high concurrency), it tests the maximum pressure that the system can bear and predicts the bottleneck of the system
Concurrency Testing Test the performance of the system by simulating many users accessing the system at the same time or operating a function of the system, and find problems (concurrent read and write, thread control, resource scrambling).
Durability (Configuration Testing) By running the system for a long time under heavy load, test the system and machine for a long time, and find problems (memory leakage, database connection pool not released, resource not recovered)

2.3.2 Interpretation of pressure measurement words

Pressure CeMing word explain
Concurrent (Concurrency) The ability of a processor to handle multiple tasks simultaneously (logically)
Parallel (Parallel) Multiple processors or multi-core processors that handle multiple different tasks at the same time (physically simultaneously)
QPS(number of queries Per Second) Number of requests handled by the server per second (REq/SEC requests/total requests in a period of time/request time)
The transaction (the Transactions) Is a collection of one or more requests from the user
TPS(Number of transactions Per Second) Number of transactions handled by the server per second (a transaction may include multiple requests)
Request Success Number The number of successful requests in a pressure test
Request Failures Number The number of requests that failed during a pressure test
Error Rate The ratio of the number of successful requests to the number of failed requests in a pressure test
Maximum Response Time The maximum amount of time a system takes to respond to a request or instruction in a transaction
Minimum Mininum Response Time The minimum amount of time a system takes to respond to a request or instruction in a transaction
Average Response Time The average time taken by the system to respond to a request or instruction during a transaction

2.3.3 Explanation of machine performance Indicators

The machine performance explain
CPU Usage The CPU usage is classified into user, system, and idle states. The CPU usage refers to the ratio of the CPU execution time of non-idle processes to the total CPU execution time
Memory Usage Memory usage refers to the amount of memory spent by this process.
IO(Disk input/ output) Read/write packet rate of the disk
Network Load Inbound and outbound bandwidth and packet quantity of the nic

2.3.4 Description of Access Indicators

access explain
PV(Page View) A PV is recorded for each website page opened by a user. When a user opens the same page for several times, the PV value accumulates for several times
UV(Unique Visitor) Natural persons who access and flow websites through the Internet. If the same visitor visits the site more than once within a day, only one unique visitor will be counted

2.4 How to calculate pressure measurement indicators

  • We need a purposeful load test. What is the target we need to achieve for this load test (e.g. 100QPS per machine? The website can accommodate 100W people online at the same time)

  • The calculation can be carried out by the following calculation method:

  • The principle of pressure measurement: 80% of the daily traffic is concentrated in 20% of the time, which is called peak time

  • Formula: (Total PV 80%)/(seconds per day 20%) = Requests per second at peak time (QPS)

  • Machines: Peak time requests per second (QPS)/QPS per machine = number of machines required

  • Assume: the number of users (100W) on the site per day, and the number of visitors per day is about 3000W PV. How many QPS does this machine need?

)/(86400 * 30000000 * 0.8 (0.2) 1389 (QPS) material

  • Suppose: The QPS of a single machine is 69. How many machines are needed to support it?

1389/69 material 20

3. Common pressure measuring tools

3.1 ab

  • Introduction to the

ApacheBench is a Web stress test tool (AB for short) of the Apache server. Ab is also a command line tool, which has low requirements on the host that initiates the load. According to the ab command, you can create many concurrent access threads to simulate multiple visitors accessing a URL address at the same time, so it can be used to test the load pressure of the target server. In general, THE AB tool is small and simple, fast to learn, and can provide the required basic performance indicators, but without graphical results, cannot be monitored.

Ab is a lightweight pressure measuring tool, the results are not particularly accurate, can be used as a reference.

  • The installation


     

    Install on Linux

    sudo yum -y install httpd

Copy the code
  • usage


     

    Usage: ab [options] [http[s]://]hostname[:port]/path

    Usage: ab [option] address

    Options:

    Options are:

    -n requests # Number of requests executed.

    -c concurrency # Number of concurrency requests.

    -s timeout # Specifies the timeout period for each request. The default is 30 seconds.

    -k # Enable the HTTP KeepAlive function, that is, execute multiple requests in one HTTP session. By default, KeepAlive is disabled.

Copy the code
  • Pressure test command


     

    # Use ab pressure test tool to request baidu link 100 times with 1 concurrency

    ab -n 100 -c 1 https://www.baidu.com/

Copy the code

Pressure test results


     

    ~ >ab -n 100 -c 1 https://www.baidu.com/

    This is ApacheBench, Version 2.3 <$Revision: 1430300 $>

    Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

    Licensed to The Apache Software Foundation, http://www.apache.org/

    Benchmarking www.baidu.com (be patient)..... done

    Server Software: BWS / 1.1

    Server Hostname: www.baidu.com

    Server Port: 443

    SSL/TLS Protocol: TLSv1.2, ECDHE - RSA - either AES128 - GCM - SHA256, 2048128

    Document Path: /

    Document Length: 227 bytes

    Concurrency Level: 1

    Time taken for tests: 9.430 seconds

    Complete requests: 100

    Failed requests: 0

    Write errors: 0

    Total transferred: 89300 bytes

    HTML transferred: 22700 bytes

    Requests per second: 10.60 [#/ SEC] (mean)

    Time per request: 94.301 [ms] (mean)

    Time per request: 94.301 [ms] (mean, across all concurrent requests)

    Transfer rate: 9.25 [Kbytes/ SEC] Received

    Connection Times (ms)

    min mean[+/-sd] median max

    Connect: 54 70 16.5 69 180

    Processing: 18 24 12.0 23 140

    Waiting: 18 24 12.0 23 139

    Total: 72 94 20.5 93 203

    Percentage of the requests served within a certain time (ms)

    50% by 93

    66% by 99

    75% by 101

    80% by 102

    90% by 108

    95% by 122

    98% by 196

    99% by 203

    100% 203 (longest request)

Copy the code
  • Test metrics of primary concern

  • ConcurrencyLevel Number of concurrent requests

  • Timetakenfortests Total test time

  • Completerequests Number of completed requests

  • Number of Failedrequests

  • Requestsper Second Throughput refers to the number of requests processed per unit of time for a concurrent user. Equivalent to QPS, in fact, can be regarded as the same statistical method, but the name is different.

  • Timeper Request Average request waiting time

  • Timeper Request Server processing time

3.2 Locust

  • Introduction to the

Is a very easy to use, distributed, Python developed stress testing tool. A graphical interface is available to export pressure measurement data.

  • The installation


     

    Pip3 Install locust

    pip3 install locust

    Check whether the installation is successful

    locust -h

    Run Locust across multiple processes/machine libraries

    pip3 install pyzmq

    # webSocket pressure library

    pip3 install websocket-client

Copy the code
  • usage

Write the pressure test script test.py


     

    from locust import HttpLocust, TaskSet, task

    Define user behavior

    class UserBehavior(TaskSet):

    @task

    def baidu_index(self):

    self.client.get("/")

    class WebsiteUser(HttpLocust):

    Task_set = UserBehavior # points to a defined UserBehavior class

    Min_wait = 3000 # Lower bound on user wait time between transactions (in milliseconds)

    Max_wait = 6000 # Upper bound on user wait time between transactions (in milliseconds)

Copy the code
  • The voltage measurement


     

    locust -f test.py --host=https://www.baidu.com

Copy the code

Visit http://localhost:8089 to go to the pressure test home page

Number of Users to simulate the Number of users

Hatch Rate (Users SPAWNED /second) Increase the number of users per second

Click “Start Swarming “to enter the pressure survey page

The address, current status, RPS, failure rate, and start or restart buttons are displayed in the upper right corner of the page

Performance test parameters

  • Type Request Type, for example, GET/POST

  • Name Request path

  • Request Indicates the number of current requests

  • Fails Specifies the number of current requests that fail

  • Median Median value, in milliseconds, Median value of the request response time

  • Average The Average response time of a request, in milliseconds

  • Min Minimum server response time for a request, in milliseconds

  • Max Maximum server response time for a request, in milliseconds

  • Averagesize Size of a single request, in bytes

  • CurrentRPS stands for throughput (short for Requests Per Second), which is the number of Requests processed Per unit of time for a given number of concurrent users. Equivalent to QPS, in fact, can be regarded as the same statistical method, but the name is different.

3.3 Jmeter

  • Introduction to the

Apache JMeter is a Java-based stress testing tool developed by the Apache organization. Used to stress test software, it was originally designed for Web application testing, but has since expanded to other testing areas. JMeter can perform functional/regression tests on applications, verifying that your program returns the results you expect by creating scripts with assertions.

  • The installation

Visit https://jmeter-plugins.org/install/Install/ to download decompression can be used in the future

  • usage

JMeter is too powerful to be used here. You can refer to the relevant documentation to use JMeter (there are recommended tutorial documents in the references section).

3.4 cloud pressure measurement

3.4.1 Introduction to cloud pressure measurement

As the name implies, the pressure test script is deployed in the cloud to conduct all-round pressure test on our application through the cloud. We only need to configure the parameters of pressure test without preparing a physical machine. The cloud will automatically assign us the cloud host that needs pressure test to perform pressure test on the target under pressure test.

Advantages of cloud pressure measurement:

  1. Easily implement distributed deployment

  2. It can simulate the access of massive users

  3. Traffic can be initiated from all over the country to more truly reflect the user experience

  4. Comprehensive monitoring of pressure measurement index

  5. Well documented

Of course, the cloud pressure measurement is a commercial product, in the use of nature still need to charge, and the price is relatively expensive ~

3.4.2 Aliyun performance test PTS

PTS (Performance Testing Service) is a cloud-based Testing tool for all technical personnel. Unlike the complexity of traditional tools, PTS provides performance testing, API debugging, and monitoring capabilities with internet-based interaction. Self-developed and adaptive open source functions can easily simulate scenarios of users accessing businesses of any size, and tasks can be initiated at any time, eliminating the tedious construction and maintenance costs. It is also closely combined with monitoring, flow control and other sibling products to provide one-stop high availability, efficient inspection and management of business performance.

Ali Cloud also supports penetration testing, which simulates hackers to conduct comprehensive and in-depth security tests on business systems.

3.4.3 Tencent Cloud pressure measurement master LM

By creating virtual robots to simulate multi-user concurrent scenarios, provide a complete set of server pressure measurement solutions

4, Go stress-testing go language to achieve pressure testing tools

4.1 introduction

  • Go-stress-testing is a simple pressure testing tool implemented by GO language. It is open source and supports secondary development. It can pressure HTTP and webSocket requests and use coroutine to simulate a single user to make more efficient use of CPU resources.

  • Project address https://github.com/link1st/go-stress-testing

4.2 usage

  • Supported parameters:


     

    Usage of ./go_stress_testing_mac:

    -c uint

    Number of concurrent requests (Default 1)

    -d string

    Debug mode (default "false")

    -n uint

    Total requests (Default 1)

    -p string

    Curl file path

    -u string

    Request the address

    -v string

    HTTP :statusCode, JSON webSocket: JSON (default "statusCode")

Copy the code
  • -n is the number of requests made by a single user, and the total number of requests = -c* -n. We’re talking about simulating user behavior here, so this is the number of requests per user

  • Example:


     

    # check usage

    go run main.go

    # Use request Baidu page

    go run main.go -c 1 -n 100 -u https://www.baidu.com/

    Use debug mode to request baidu page

    go run main.go -c 1 -n 1 -d true -u https://www.baidu.com/

    Curl curl curl curl curl curl curl curl

    go run main.go -c 1 -n 1 -p curl/baidu.curl.txt

    # pressure webSocket connection

    Go -c 10 -n 10 -u ws://127.0.0.1:8089/acc

Copy the code
  • Use curl file to perform pressure measurement

Curl is a file transfer tool for Linux. Curl is a powerful HTTP command line tool.

Using the curl file, you can test non-GET requests and set parameters such as method, cookies, header, and body for HTTP requests

Create a curl file in Chrome, open developer mode (F12), and run the following command on the terminal to generate curl

TXT file in curl/baidu.curl. TXT file in curl/baidu.curl. TXT file in curl/baidu.curl


     

    Curl curl curl curl curl curl curl curl

    go run main.go -c 1 -n 1 -p curl/baidu.curl.txt

Copy the code

4.3 implementation

  • Specific requirements can be viewed project source

  • Project directory structure


     

    | ____main. Go / / the main function, access to the command line parameters

    | ____server / / handler directory

    | | ____dispose. Go / / start the pressure test, registered validators, start statistics function, start coroutines for pressure measurement

    | | ____statistics / / directory

    | | | ____statistics. Go/statistics/receiving pressure test results and process

    | | ____golink / / connect directory

    | | | ____http_link. Go / / HTTP connection is established

    | | | ____websocket_link. Go / / webSocket connection is established

    | | ____client/client/request data directory

    | | | ____http_client. Go / / HTTP client

    | | | ____websocket_client. Go / / webSocket client

    | | ____verify / / the return data validation directory

    | | | ____http_verify. Go / / HTTP return data validation

    | | | ____websokcet_verify. Go / / webSocket data returned check

    | ____heper / / generic function directory

    | | ____heper. Go / / generic function

    | ____model/model/directory

    | | ____request_model. Go / / request data model

    | | ____curl_model. Go / / curl file parsing

    | ____vendor / / project depend on the directory

Copy the code

4.4 Go-stress-testing For Golang Web

Here go-stress-testing is used to pressure the GO server (deployed on the same machine), and the pressure test results are counted

  • Requested server configuration

CPU: 4-core (Intel Xeon(Cascade Lake) Platinum 8269 2.5 GHz/3.2 GHz)

Memory: 16 GB Hard disk: 20 GB SSD System: CentOS 7.6

Go version: go1.12.9 Linux/amd64

  • go server


     

    package main

    import (

    "log"

    "net/http"

    )

    const (

    httpPort = "8088"

    )

    func main() {

    runtime.GOMAXPROCS(runtime.NumCPU() - 1)

    hello := func(w http.ResponseWriter, req *http.Request) {

    data := "Hello, World!"

    w.Header().Add("Server", "golang")

    w.Write([]byte(data))

    return

    }

    http.HandleFunc("/", hello)

    err := http.ListenAndServe(":"+httpPort, nil)

    if err ! = nil {

    log.Fatal("ListenAndServe: ", err)

    }

    }

Copy the code
  • Gostresstesting pressure test command


     

    /go_stress_testing_linux -c 100-n 10000-u http://127.0.0.1:8088/

Copy the code
  • Pressure test results

concurrency gostresstesting QPS
1 6394.86
4 16909.36
10 18456.81
20 19490.50
30 19947.47
50 19922.56
80 19155.33
100 18336.46
200 16813.86

From the pressure test results: the effect is good, the pressure test QPS is close to 2W

5. Comparison of pressure measuring tools

5.1 compare

ab locust Jmeter go-stress-testing Pressure test of cloud
Implementation language C Python Java Golang
UI There is no There are There are There is no There is no
advantage Simple to use, easy to use Support distributed and pressure test data export Rich plug-in, support to generate HTML reports Open source project, simple to use, no dependency, support webSocket pressure test More real simulation users, support higher pressure measurement strength

5.2 How do I Select a Pressure Measuring Tool

There is no best in the world, only the most suitable, thousands of tools, choose a suitable for you is the most important

There are a variety of scenarios to consider when choosing a tool:

  • Define your purpose, what needs to be done, what is the goal of the pressure test?

  • Are you familiar with the tool, and how much are you willing to pay to know it?

  • Are you testing it or just trying to understand how it works?

  • Does the tool support the scenarios you need to pressure

6, a single machine 100W connection pressure test actual combat

6.1 illustrates

I wrote an article on websocket based distributed chat (IM) system with 1 million connections per machine. Here we want to implement a pressure test with 100W connections per machine

Goal:

  • A single machine can maintain 100W long connections

  • The CPU, memory, network, and I/O status are normal

Description:

Gowebsocket Distributed Chat (IM) system:

  • Before, after the user connected, there was a full broadcast, which needs to close the user connection, exit and other events

  • Server preparation:

Since I do not have my own server, I need to buy a cloud server temporarily

Pressure test server:

16 machines (explain why 16 machines are needed later)

CPU: 2 cores Memory: 8 GB Hard disk: 20 GB SSD System: CentOS 7.6

Pressure test service:

1

CPU: 4-core Memory: 32 GB Hard disk: 20 GB SSD System: CentOS 7.6

6.2 Kernel Optimization

  • Modifies the maximum number of open files in a program

The compressed server needs to maintain a 100W long connection. The client and server communicate through sockets, and each connection needs to establish a socket. To maintain 100W long connection, a single program needs to open 100W file handles


     

    Check the system default value

    ulimit -n

    # set the maximum number of open files

    ulimit -n 1040000

Copy the code

Here set to more than 100W, the program in addition to 100W connection and other resource connections (database, resources, etc.), set to 104W

CentOS 7.6 The preceding Settings do not take effect. You need to manually modify the configuration file

vim/etc/security/limits.conf

You need to set the hard limit and soft limit, root, and all users to 1040000

Core limits the size of the kernel file, which is set to unlimited


     

    Add parameters

    root soft nofile 1040000

    root hard nofile 1040000

    root soft nofile 1040000

    root hard nproc 1040000

    root soft core unlimited

    root hard core unlimited

    * soft nofile 1040000

    * hard nofile 1040000

    * soft nofile 1040000

    * hard nproc 1040000

    * soft core unlimited

    * hard core unlimited

Copy the code

Note:

/proc/sys/fs/file-max Specifies the number of system-level file handles that can be opened. The value cannot be less than the limits value

If the value of file-max is less than the limits value, you cannot log in after the system restarts


     

    # file-max set value reference

    cat /proc/sys/fs/file-max

    12553500

Copy the code

After the modification, restart the server and run the ulimit-n command to check whether the configuration takes effect

6.3 Client Configuration

Since Linux ports range from 0 to 65535(2^16-1) this is OS independent, whether Linux is 32-bit or 64-bit

This number is due to TCP, the TCP header indicates that the port is only 16 bits, so the maximum is only 65535(if you have several more virtual IP addresses per machine you can break this limit)

The ports below 1024 are reserved by the system, so they can be used from 1024 to 65535

If 100W long connection is required, each machine has 655-1024 ports, 100W/(655-1024) ≈ 15.5, so 16 servers are needed here

  • Vim /etc/sysctl. conf is added at the end of the file


     

    net.ipv4.ip_local_port_range = 1024 65000

    net.ipv4.tcp_mem = 786432 2097152 3145728

    net.ipv4.tcp_rmem = 4096 4096 16777216

    net.ipv4.tcp_wmem = 4096 4096 16777216

Copy the code

Configuration Description:

  • Ip_local_port_range Indicates the local port number that can be used by TCP or UDP. The value ranges from 1024 to 65000

  • Tcp_mem determines how the TCP stack should reflect memory usage, and each value is in pages of memory (typically 4KB). The first value is the lower limit of memory usage; The second value is the upper limit at which memory pressure mode starts to apply pressure to the buffer; The third value is the upper limit of memory usage. At this level, packets can be discarded to reduce memory usage. You can increase these values for larger BDP (note that they are in pages of memory, not bytes)

  • Tcp_rmem defines the memory used by sockets for automatic tuning. The first value is the minimum number of bytes allocated to the socket receive buffer. The second value is the default value (overridden by rMEM default) to which the buffer can grow without heavy system load; The third value is the maximum number of bytes in the receive buffer space (which is overridden by rmemmax).

  • Tcp_wmem defines the memory used by sockets for automatic tuning. The first value is the minimum number of bytes allocated to the socket send buffer; The second value is the default value (overridden by wMEm default) to which the buffer can grow without heavy system load; The third value is the maximum number of bytes in the send buffer space (which is overridden by wmemmax).

6.4 to prepare

  1. Start the Server service on the Server under pressure (gowebSocket)

  2. View the Intranet port of the server to be measured

  3. I have logged in 16 pressure measurement servers. Here, I have made a mirror image of the system to be optimized in advance, so that I can directly use the mirror image when applying for the machine (parameters have been adjusted).

  1. The voltage measurement


     

    . / go_stress_testing_linux - 62500 - n - 1 c u ws: / / 192.168.0.74:443 / acc

Copy the code

62500*16=100W can just meet our requirements

After the connection is established, -n1 sends a ping message to the server. After receiving the response, the connection is maintained

  1. Through the HTTP interface of goWebSocket server, the number of connections and the number of coroutines started by the project can be queried in real time

  2. Check the system status during the pressure test


     

    # Linux command

    Ps # Check process memory and CPU usage

    Iostat # Check system I/O status

    Nload # Check network traffic

    /proc/pid/status # Check the process status

Copy the code

6.5 Pressure test data

  • After the pressure test, check the connection count to 100W, and then hold it for 10 minutes to observe whether the system is normal

  • The system runs normally, and the CPU, memory, I/O, and page are normal

  • Data after manometry

GoWebSocket connection count: 100W clientsLen connection count: 100W GoroutineGoroutine number: 2000008

Check whether the number of connections meets the requirements from the pressure test service. The number of concurrent connections after the pressure test is 62500, which is the number of connections of each client. The total number of connections: 62500*16=100W.

  • This section describes how to record the memory usage of 1W to 100W connections

The number of connections memory
10000 281M
100000 2.7 g
200000 5.4 g
500000 13.1 g
1000000 25.8 g

View memory details when 100W connection:


     

    cat /proc/pid/status

    VmSize: 27133804 kB

Copy the code

27133804/1000000≈27.1 100W connection, occupying 25.8g memory, rough calculation, a connection occupied 27.1Kb memory, because each user of goWebSocket project connected to two coroutines to process user read and write events, so the memory occupation is slightly more

If you need to reduce memory usage, please refer to the solution given by @roy11568780

Traditional Golang uses a goroutine loop called read for each socket. In a real million link scenario this is a huge waste of resources, and the principles of optimization are not new. Golang can also use epoll, take the FD to epoll, detect the event and read it in the coroutine pool, depending on the situation, it should be enough to read and write the coroutine goroutine pool 10-20 respectively

At this point, the pressure measurement has been completed, a single machine can support 100W connection has met ~

7,

Here the pressure test was finally completed, the pressure test cost a huge sum of 16 yuan.

A single machine can support 100W connection in actual measurement, but the actual business is complicated, so continuous optimization is needed

Through the implementation of the introduction of what is the pressure test, under what circumstances need pressure test, if you feel that the existing pressure test tools are not applicable, you can implement or transform into their own tools.

8. References

Performance testing tool

Explain common terms for performance testing

Performance test terms explained

How are PV, TPS and QPS calculated?

Super practical pressure test tool – AB tool

Locust is introduced

Getting started with Jmeter Performance Testing

Websocket-based single machine support millions of connections distributed chat (IM) system

Github search :link1st to view go-stress-testing

https://github.com/link1st/go-stress-testing