Linux Performance Testing and Optimization Practice Notes

Original link: https://wsgzao.github.io/post/linux-performance/

foreword

Linux performance testing, monitoring, and optimization is an ongoing process. The picture above is a schematic diagram of the Linux benchmarking tools shared by Brendan D. Gregg at LinuxCon, which covers a wide range of topics. We can capture most of the information through mature monitoring solutions such as Prometheus and Zabbix. In actual work, we will often pay attention to performance issues such as CPU, Memory, I/O, and Network. This article adds Ni Pengfei’s “Linux” produced by Geek Time. Performance Optimization Practice” column course study notes.

Donald Knuth said “premature optimization is the root of all evil”


update record

October 18, 2022 – Added Linux performance optimization in action
August 31, 2022 – Added bench.sh and yabs.sh
March 06, 2015 – first draft

Read the original article – https://wsgzao.github.io/post/linux-performance/

Extended reading

Linux Performance – http://www.brendangregg.com/linuxperf.html


CPU

Confirm CPU model

 1
2
3
 cat /proc/cpuinfo |grep "model name" |uniq|cut -f2 -d:

Intel(R) Xeon(R) CPU E5-2650 v2 @ 2.60GHz

Super PI

The shorter the computation time, the better

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

time echo "scale=500;4*a(1)" |bc -l -q

3.141592653589793238462643383279502884197169399375105820974944592307\
81640628620899862803482534211706798214808651328230664709384460955058\
22317253594081284811174502841027019385211055596446229489549303819644\
28810975665933446128475648233786783165271201909145648566923460348610\
45432664821339360726024914127372458700660631558817488152092096282925\
40917153643678925903600113305305488204665213841469519415116094330572\
70365759591953092186117381932611793105118548074462379962749567351885\
75272489122793818301194912

real 0m0.081s
user 0m0.076s
sys 0m0.000s

Disk

Empty the cache

It is recommended to clear the cache before each read and write test

 1
2
3
4
5
6
 sync; echo 3 > /proc/sys/vm/drop_caches
````

### Test read performance

> Select the test disk, it is recommended to do 2-3 groups to take the average

hdparm -t /dev/sda

/dev/sda:
Timing buffered disk reads: 1074 MB in 3.00 seconds = 357.92 MB/sec

 1
2
3
4

### Test write performance

> Select different BlockSize sizes according to the business and take the average of multiple tests as needed

time dd if=/dev/zero of=/tmp/speed bs=1M count=2K conv=fsync;rm /tmp/speed

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
twenty one
twenty two
twenty three
twenty four
25
26
27
28
29
30
31
32
33
34
35

### Reference data

> Take a 10,000 rpm 300 GB SAS hard disk as an example, the model is IBM x3650 M4, and the Raid parameters are as follows

1.Read Policy: Ahead (controller cache read policy: read ahead)
2.Write Policy: Write Back with BBU (controller cache write policy: write back when there is battery backup)
3.IO Policy: Direct
4. Drive Cache: disable

Raid | Read(MB) | Write(MB)
------|-------|-------
Raid 1 | 170 | 130
Raid 5 | 350 | 250
Raid 10 | 300 | 215

---

## Open source one-click testing tool


###bench.sh

One-click test script bench.sh

1. Display various system information;
2. Taken from the test points of Speedtest data centers around the world, the network test is more comprehensive;
3. Support IPv6 download speed measurement;
4. IO test (sequentially write 1GB data) three times, and display the average value.

Combined with the unixbench.sh script test, the performance of the VPS can be fully tested.
https://teddysun.com/245.html

Description: Auto test I/O & upload & download speed script
Intro: https://teddysun.com/444.html

wget -qO-bench.sh | bash

curl -Lso-bench.sh | bash

 1
2
3
4
5
6
7


### yabs.sh

Here's an attempt to create yet another damn Linux server benchmarking script.

https://github.com/masonr/yet-another-bench-script

curl -sL yabs.sh | bash

wget -qO- yabs.sh | bash

`

This script has been tested on the following Linux distributions: CentOS 6+, Debian 8+, Fedora 30, and Ubuntu 16.04+. It is designed to not require any external dependencies to be installed nor elevated privileges to run.

Local fio/iperf3 Packages: If the tested system has fio and/or iperf3 already installed, the local package will take precedence over the precompiled binary.

Experimental ARM Compatibility: Initial ARM compatibility has been introduced, however, is not considered entirely stable due to limited testing on distinct ARM devices. Report any errors or issues.

High Bandwidth Usage Notice: By default, this script will perform many iperf network tests, which will try to max out the network port for ~20s per location (10s in each direction). Low-bandwidth servers (such as a NAT VPS) should consider running this script with the -r flag (for reduced iperf locations) or the -i flag (to disable network tests entirely).

Linux performance optimization in practice

Linux performance optimization practice Ni Pengfei Senior Linux expert, Kubernetes project maintainer
https://time.geekbang.org/column/intro/100020901

Linux performance optimization practical notes

Linux performance optimization
https://feiyang233.club/post/linux/

This article is reprinted from: https://wsgzao.github.io/post/linux-performance/
This site is for inclusion only, and the copyright belongs to the original author.