Linux性能测试和优化实践笔记
前言
Linux性能测试、监控、优化是一个持续的过程,上图为LinuxCon上Brendan D. Gregg分享的Linux benchmarking tools
示意图,涵盖面十分广泛。我们可以通过成熟的监控方案如Prometheus,Zabbix来捕获大部分信息,在实际工作中我们会经常关注CPU、Memory、I/O、Network等性能问题,本文增加了倪朋飞在极客时间出品的《Linux性能优化实战》专栏课程学习笔记。
Donald Knuth说”过早优化是万恶之源”(premature optimization is the root of all evil)
更新记录
2022年10月18日 - 增加Linux性能优化实战
2022年08月31日 - 增加bench.sh和yabs.sh
2015年03月06日 - 初稿
阅读原文 - https://wsgzao.github.io/post/linux-performance/
扩展阅读
Linux Performance - http://www.brendangregg.com/linuxperf.html
CPU
确认CPU型号
1 | cat /proc/cpuinfo |grep "model name"|uniq|cut -f2 -d: |
Super PI
计算时间越短越好
1 |
|
Disk
清空缓存
每次做读写测试前建议先清空缓存
1 | sync; echo 3 > /proc/sys/vm/drop_caches |
测试读性能
选择测试磁盘,建议做2-3组取平均值
1 | hdparm -t /dev/sda |
测试写入性能
根据业务选择不同的BlockSize大小按需多次测试取平均值
1 | time dd if=/dev/zero of=/tmp/speed bs=1M count=2K conv=fsync;rm /tmp/speed |
参考数据
以10,000 rpm 300 GB SAS硬盘为例,机型为IBM x3650 M4,Raid参数如下
1.Read Policy:Ahead (控制器缓存读策略:预读)
2.Write Policy:Write Back with BBU(控制器缓存写策略:有电池备份时回写)
3.IO Policy: Direct(IO策略:直接)
4.Drive Cache:disable (硬盘缓存:禁用)
Raid | Read(MB) | Write(MB) |
---|---|---|
Raid 1 | 170 | 130 |
Raid 5 | 350 | 250 |
Raid 10 | 300 | 215 |
开源的一键测试工具
bench.sh
一键测试脚本bench.sh
1、显示各种系统信息;
2、取自 Speedtest 世界多处的数据中心的测试点,网络测试比较全面;
3、支持 IPv6 下载测速;
4、IO 测试(顺序写入 1GB 数据)三次,并显示其平均值。
再配合 unixbench.sh 脚本测试,即可全面测试 VPS 的性能。
https://teddysun.com/245.html
Description: Auto test I/O & upload & download speed script
Intro: https://teddysun.com/444.html
1 | wget -qO- bench.sh | bash |
yabs.sh
Here’s an attempt to create yet another damn Linux server benchmarking script.
https://github.com/masonr/yet-another-bench-script
1 | curl -sL 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).
VPS常用测试工具
VPS常用测试脚本
https://zhuanlan.zhihu.com/p/117547388
流媒体检测脚本
https://github.com/sjlleo/netflix-verify
https://github.com/lmc999/RegionRestrictionCheck
Linux性能优化实战
Linux 性能优化实战
倪朋飞 资深 Linux 专家,Kubernetes 项目维护者
https://time.geekbang.org/column/intro/100020901
Linux performance optimization
https://feiyang233.club/post/linux/