Five important performance test indicators revealed! Concurrency, TPS, QPS, response time and resource utilization, understand performance bottlenecks, optimize system processing capabilities under high load

Table of contents

 Foreword:

1. Concurrency

2. TPS

3. PSC

4. Response time

5. Resource Utilization

Summarize


Foreword:

In high concurrency scenarios, we need to consider how to optimize our application to ensure that it can withstand a large number of requests and respond within a given time. For this problem, performance testing is a good solution. This article mainly introduces important indicators in performance testing: concurrency, TPS, QPS, response time and resource utilization, and provides code samples and detailed explanations to help readers better understand these important performance indicators.

1. Concurrency

Concurrency refers to how many users are accessing the application at the same time. When measuring application performance, we need to consider the impact of concurrency. When the number of concurrency increases, the server needs to process multiple requests at the same time, the load on the server will also increase, and the response time of the system may slow down. Therefore, we need to understand how the number of concurrency affects the performance of the application in order to optimize the performance of the system.

The following is a simple Python code for simulating multiple concurrent accesses:

import threading
import time
import requests

def visit(url):
    response = requests.get(url)
    print(response.status_code)

urls = ["http://example.com", "http://google.com", "http://bing.com"]
threads = []

for url in urls:
    process = threading.Thread(target=visit, args=(url,))
    process.start()
    threads.append(process)

for process in threads:
    process.join()

The code simulates multiple concurrent accesses by using Python's threading module. In this example, we use the requests library to make HTTP GET requests and get responses. By executing these requests concurrently in multiple threads, we can simulate multiple concurrent accesses. In practice, we usually use professional tools to simulate concurrent access, such as Apache JMeter, LoadRunner, etc.

2. TPS

TPS (Transactions per second) refers to the number of transactions that can be processed per second. In application performance testing, TPS is a very important indicator. For highly transactional applications, the TPS value is critical. By tracking the TPS value, we can understand how much load the server can handle.

The following is a simple Python code for calculating TPS:

start_time = time.time()

# your code here

end_time = time.time()
elapsed_time = end_time - start_time
tps = num_transactions / elapsed_time

print("TPS: ", tps)

In this code example, we use the time module to time the code execution time. When measuring TPS, we need to know the number of transactions processed by the application per second. Usually, this number is fixed, so we can calculate TPS based on the total number of transactions and code execution time.

3. PSC

QPS (Query per second) refers to the number of queries per second. In a high-performance application, QPS is often a very critical indicator. For an application that needs to frequently query the database or retrieve information, QPS can be used to help us understand the load that the server can bear.

The following is a simple Python code to calculate QPS:

start_time = time.time()

# your code here

end_time = time.time()
elapsed_time = end_time - start_time
qps = num_queries / elapsed_time

print("QPS: ", qps)

In this code example, we use the time module to time the code execution time. We need to know in advance the number of our queries to the database or other services, and then we can calculate the QPS based on the total number of queries and code execution time.

4. Response time

Response time is the time from when the browser sends a request to when it receives a response from the server. For application performance testing, response time is a key indicator. In application optimization, optimizing response time can reduce user waiting time and improve user satisfaction and experience. When the response time is too long, users may get bored or angry, or even abandon the application. Therefore, we need to measure and optimize the response time of our application.

Here is a simple Python code to measure response time:

start_time = time.time()

response = requests.get(url)

end_time = time.time()
elapsed_time = end_time - start_time

print("Response Time: ", elapsed_time)

In this code example, we use the requests library to initiate an HTTP GET request and use the time module to calculate the response time. The response time after a request is sent is the time it takes to complete the entire request.

5. Resource Utilization

Resource utilization refers to the efficiency of using various resources, including memory, CPU, bandwidth, etc. In high-load applications, resource utilization is an important indicator. Resource usage can affect application performance and stability.

Here is a simple Python code to measure CPU and memory utilization:

import psutil
import time

while True:
    cpu_percent = psutil.cpu_percent(interval=1)
    memory_percent = psutil.virtual_memory().percent

    print("CPU Usage: ", cpu_percent)
    print("Memory Usage: ", memory_percent)

    time.sleep(1)

In this sample code, we use Python's psutil library to measure CPU and memory utilization. We can put this code in an infinite loop and record the CPU and memory usage every second. This can help us detect abnormalities in resource utilization in a timely manner.

Summarize

In performance testing, we need to understand and master important performance indicators, such as concurrency, TPS, QPS, response time, and resource utilization. These indicators can help us understand the performance of the application and improve the performance of the application. At the same time, we also need to use professional tools to help us simulate concurrent requests and measure performance indicators. In this way, we can effectively test our application to ensure good performance and stability under high load.

 As someone who has been here, I also hope that you will avoid some detours. Here I will share with you some necessities on the way forward for performance testing. If you can use it, you can take it directly. I hope it can help you. (Performance test, big factory interview questions, resume template, etc.), I believe it will make you better progress!

Obtaining method: Just leave [Performance Test]: [Automated Test Communication]: 574737577 (note ccc) icon-default.png?t=N4P3http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=CSnXa0x6zTzjOb4Z0FLmUbeskkowthOr&authKey=zDe4tx7K%2BoWwzlLU05HRlHj0Nh2K03h agwzoY5zf51pvKdoBKLpaNpLxLmESQZN1&noverify= 0&group_code=574737577

 

 

Guess you like

Origin blog.csdn.net/DJ355/article/details/130986590