当前位置:网站首页>3. Pressure test
3. Pressure test
2022-07-24 23:48:00 【Clean night mortal dust】
Pressure test
Stress testing is one of many different types of load testing .
and The load test Mainly in terms of evaluating the performance of the system , The purpose of the stress test is under heavy load , To evaluate the availability and stability of the system .
What is stress testing ?
Stress testing is a load test used to determine system limits . The purpose of this test is to verify the stability and reliability of the system under extreme conditions .
Perform appropriate stress tests , You need a tool to push the system beyond its normal operation 、 Reach the limit and break the breakpoint .
You usually want to API Or website stress test to :
- Determine how your system behaves under extreme conditions .
- Determine the maximum capacity of the system in terms of users or throughput .
- Determine the breakpoint of the system and its failure mode .
- Determine whether your system will recover without human intervention after the stress test .
During the stress test , You will configure the test to include more concurrent users or generate higher throughput than the following :
- Your application will usually see .
- You think it can handle .
The important thing is to pay attention , Stress testing does not mean that you will immediately overburden the system —— This is a Peak test , It will be introduced as follows .
Stress testing should be configured in several progressive steps , Each step will increase the concurrent load of the system .
A typical example of the need for stress testing is “ Black Friday ” or “ Cyber Monday ”—— Two days a year , The traffic generated for many websites is several times that of normal traffic .
Stress testing can only have a few steps , It can be multiple steps , As the following example shows . No matter how many steps you include , Keep in mind that this type of test is to find out what happens when pushing the performance limits of the system — So don't worry about being too radical .
It is suggested that UAT Or run a pressure test in a temporary environment .
k6 Medium pressure test
You can configure it correctly in k6 Create stress tests easily in Option purpose . please remember , The purpose of this test is to gradually promote your API Beyond its breakthrough .
k6-stress.js
import http from 'k6/http';
import {
sleep } from 'k6';
export let options = {
stages: [
{
duration: '2m', target: 100 }, // Below normal load
{
duration: '5m', target: 100 },
{
duration: '2m', target: 200 }, // Normal load
{
duration: '5m', target: 200 },
{
duration: '2m', target: 300 }, // Near the breakthrough
{
duration: '5m', target: 300 },
{
duration: '2m', target: 400 }, // Break through the tipping point
{
duration: '5m', target: 400 },
{
duration: '10m', target: 0 }, // narrow . Recovery phase .
],
};
export default function () {
const BASE_URL = 'https://test-api.k6.io'; // Make sure this is not production
let responses = http.batch([
[
'GET',
`${
BASE_URL}/public/crocodiles/1/`,
null,
{
tags: {
name: 'PublicCrocs' } },
],
[
'GET',
`${
BASE_URL}/public/crocodiles/2/`,
null,
{
tags: {
name: 'PublicCrocs' } },
],
[
'GET',
`${
BASE_URL}/public/crocodiles/3/`,
null,
{
tags: {
name: 'PublicCrocs' } },
],
[
'GET',
`${
BASE_URL}/public/crocodiles/4/`,
null,
{
tags: {
name: 'PublicCrocs' } },
],
]);
sleep(1);
}
Pressure test VU The chart should be similar to the following :

This configuration every 2 Minute increase 100 Load of users , And maintain at this level 5 minute . We also included a recovery phase at the end , The system gradually reduces the load to 0.
If your infrastructure is configured for automatic expansion , This test will help you determine :
- How fast does the autoscale mechanism react to the increased load .
- Are there any failures during the expansion event .
The focus of the recovery phase is to determine once the load is reduced to normal , Whether the system can provide service for the request . If you are testing autoscale , You may also need to scale down , To determine whether the reduction is effective .
Peak test
Peak testing is a variant of stress testing , But it will not gradually increase the load , But in a very short time window, peak to extreme load . Although stress testing allows SUT( The system under test ) Gradually expand its infrastructure , But peak testing is not allowed .
What is peak test ?
Peak test is a kind of stress test , It will immediately flood the system with extreme load surges .
You want to perform a peak test to :
- Determine how your system will operate in the event of a sudden surge in traffic .
- Determine whether your system will recover after the traffic subsides .
Typical requirements for peak testing are , If you are in a large TV event ( Such as super bowl or pop singing contest ) Bought an ad on .
You want a large number of people to see your advertisement and visit your website immediately , If you don't test for this situation and optimize the performance in advance , This can lead to disastrous results .
Another typical example is “HackerNews The embrace of death ” - Someone is here. HackerNews or Reddit Link to your website on one of the popular Internet forums , This enables thousands of people to access your system at the same time .
The success or failure of the peak test depends on your expectations . Systems usually use 4 React in different ways :
- optimal : The system performance will not decline when the traffic surges . The response time during low and high traffic is similar .
- good : Returns information about all waits encountered by threads executing during an operation , But the system will not produce any errors . Handle all requests .
- Bad : The system made an error when the traffic surged , After the flow subsides, it returns to normal .
- bad : System crash , And it did not recover after the flow subsided .
k6 Peak test in
k6-spike.js
import http from 'k6/http';
import {
sleep } from 'k6';
export let options = {
stages: [
{
duration: '10s', target: 100 }, // Below normal load
{
duration: '1m', target: 100 },
{
duration: '10s', target: 1400 }, // Soar to 1400 Users
{
duration: '3m', target: 1400 }, // stay 1400 Stop 3 minute
{
duration: '10s', target: 100 }, // narrow . Recovery phase .
{
duration: '3m', target: 100 },
{
duration: '10s', target: 0 },
],
};
export default function () {
const BASE_URL = 'https://test-api.k6.io'; // Make sure this is not production
let responses = http.batch([
[
'GET',
`${
BASE_URL}/public/crocodiles/1/`,
null,
{
tags: {
name: 'PublicCrocs' } },
],
[
'GET',
`${
BASE_URL}/public/crocodiles/2/`,
null,
{
tags: {
name: 'PublicCrocs' } },
],
[
'GET',
`${
BASE_URL}/public/crocodiles/3/`,
null,
{
tags: {
name: 'PublicCrocs' } },
],
[
'GET',
`${
BASE_URL}/public/crocodiles/4/`,
null,
{
tags: {
name: 'PublicCrocs' } },
],
]);
sleep(1);
}
Peak test VU The chart should be similar :

Please note that , Test to 1 Minutes of low load time starts , Quickly reach a very high load , Then there is the recovery period of low load .
please remember , The purpose of this test is to suddenly overwhelm the system . Don't be afraid to add more than the worst-case forecast VU Number . According to your needs , You may want to extend the recovery phase to 10 Minutes or more , To see when the system finally recovers .
Conclusion
Stress and peak tests help prepare you for the extreme conditions that your system will inevitably encounter in production .
Preparing for the inevitable is a sign of the maturity of technical organizations . Stress testing not only makes your system more reliable , It also reduces the pressure level of the operation and development team .
Once your system is stress resistant , You may need to run Soak Test , To see if other reliability problems will not occur in a long time .
You can also have a look at
Refer to official documentation
Official document address : https://k6.io/docs/
边栏推荐
- JS ------ Chapter 5 functions and events
- NVIDIA inspector detailed instructions
- Piziheng embedded: the method of making source code into lib Library under MCU Xpress IDE and its difference with IAR and MDK
- C语言学习之分支与循环语句
- Development direction and problems of optaplanner
- 云计算三类巨头:IaaS、PaaS、SaaS,分别是什么意思,应用场景是什么?
- Mandatory interview questions: 1. shallow copy and deep copy_ Deep copy
- yolov5
- 代码覆盖率
- JDBC 驱动升级到 Version 8.0.28 连接 MySQL 的踩坑记录
猜你喜欢

ShardingSphere-数据库分库分表简介

JS ------ Chapter 5 functions and events

指针与数组

Notes of Teacher Li Hongyi's 2020 in-depth learning series 9

Piziheng embedded: the method of making source code into lib Library under MCU Xpress IDE and its difference with IAR and MDK

Are you still using system. Currenttimemillis()? Take a look at stopwatch

Qt项目-安防监控系统(各个界面功能实现)

C语言学习之分支与循环语句

WP wechat export chat record backup to computer

Power consumption of chip
随机推荐
In pgplsql: = and=
把字符串转换成整数与不要二
Convert a string to an integer and don't double it
剖析kubernetes集群内部DNS解析原理
Opengauss kernel analysis: query rewriting
Analyzing the principle of DNS resolution in kubernetes cluster
Development direction and problems of optaplanner
做一个文艺的测试/开发程序员,慢慢改变自己......
Collection of common online testing tools
[brother hero July training] day 20: search Binary Tree
How to speculate on the Internet? Is it safe to speculate on mobile phones
codeforces round #805 ABCDEFG
Transmission download list, download file migration machine guide
HLS编程入门
Notes of Teacher Li Hongyi's 2020 in-depth learning series 3
基于TensorFlow和Keras的卷积神经网络实现猫狗数据集分类实验
Notes of Teacher Li Hongyi's 2020 in-depth learning series 2
Modify the existing annotator name in the word document
Xiezhendong: Exploration and practice of digital transformation and upgrading of public transport industry
c语言:深度刨析函数栈帧