对于普通用户来说,优化Linux应用环境可能是相当具有挑战性的。它涵盖了各种领域,并且有许多参数需要考虑,比如CPU、存储、缓存策略和内存管理。尽管Linux有默认设置可以处理大多数情况和场景,但是对于高性能、高并发和高可用性系统等特殊场景,需要进行调整。本文讨论的特性是tuned,它是Linux系统中常用的一种调优服务。
tuned由两个程序组成:tuned和tuned-adm。tuned是服务端程序,用于监控和收集系统各个组件的数据;而tuned-adm是客户端程序,通过命令行管理和配置tuned。
tuned提供了几种预先配置的优化策略(配置文件),可以直接使用,例如balanced、desktop、throughput-performance、latency-performance、powersave及其他优化场景。然而,不同的系统和应用场景可能需要不同的优化方法,tuned预先配置的配置文件可能并不总能满足要求。因此,tuned还允许用户创建和自定义自己的调优配置文件。
tuned子系统是独立运行的,它们共同组成了tuned的调优方案。每个子系统可以支持多个设备(每个设备可能包含多个CPU、网卡等设备),并且每个设备可以使用独立的实例进行控制。
在实际环境中,系统资源可能不足以支持正在运行的进程。管理员可以根据不同的用例和工作负载来调整系统资源的分配,以实现系统优化。
tuned是一个服务端程序,包含并启用于RHEL8/RHEL7/CentOS7的最小安装中。其守护进程tuned可以根据调优配置文件以静态和动态两种模式应用调优调整。
tuned is a server-side program that is included and enabled in the minimal installation of RHEL8. Its daemon process, tuned, can apply tuning adjustments based on tuning configuration files in both static and dynamic modes.
yum install -y tuned # 安装软件包
systemctl start tuned # 启动tuned服务
systemctl stop tuned # 停止tuned服务
systemctl enable --now tuned # 设置开机自启动
systemctl enable tuned # 自启动/禁止自启动
tuned-adm profile throughput-performance # 开启高性能
tuned-adm active # 显示当前性能模式
tuned-adm off # 关闭
tuned服务的相关配置目录:
/usr/lib/tuned/ # 原生的性能模式
/etc/tuned # DIY的性能模式
├── active_profile # 当前的性能模式
├── bootcmdline
└── tuned-main.conf
tuned提供的profiles,tuned会预先配置的一些优化策略,下面依次介绍下
CentOS7默认安装并启动了tuned服务,如果没有的话可以手动安装和启动:
# yum install tuned -- 安装tuned
# service tuned start -- 启动tuned服务
# service tuned status -- 查看tuned状态
对tuned的操作主要通过tuned-adm命令实现。
查看所有可用的profiles和当前使用的profile:
# tuned-adm list
Available profiles:
- balanced - General non-specialized tuned profile
- desktop - Optimize for the desktop use-case
- hpc-compute - Optimize for HPC compute workloads
- latency-performance - Optimize for deterministic performance at the cost of increased power consumption
- network-latency - Optimize for deterministic performance at the cost of increased power consumption, focused on low latency network performance
- network-throughput - Optimize for streaming network throughput, generally only necessary on older CPUs or 40G+ networks
- powersave - Optimize for low power consumption
- throughput-performance - Broadly applicable tuning that provides excellent performance across a variety of common server workloads
- virtual-guest - Optimize for running inside a virtual guest
- virtual-host - Optimize for running KVM guests
Current active profile: throughput-performance
只查看当前使用的profile:
[root@~]# tuned-adm active
Current active profile: throughput-performance
切换profile:
[root@~]# tuned-adm profile balanced
[root@~]# tuned-adm active
Current active profile: balanced
关闭tuned的优化策略:
[root@~]# tuned-adm off
[root@~]#
关闭tuned之后可以使用“tuned-adm profile”命令重新打开优化策略:
[root@~]# tuned-adm off
[root@~]# tuned-adm recommend
balanced
[root@~]# tuned-adm profile throughput-performance
[root@~]# tuned-adm active
Current active profile: throughput-performance
[root@~]#
查看系统推荐的profile:
[root@~]# tuned-adm recommend
balanced
# 安装cpupowerutils
yum -y install cpupowerutils
# 开启高性能
cpupower frequency-set -g performance
# 查看
cpupower frequency-info
cat /proc/cpuinfo | grep MHz
# 模式说明:
performance 运行于最大频率
powersave 运行于最小频率
userspace 运行于用户指定的频率
ondemand 按需快速动态调整CPU频率, 一有cpu计算量的任务,就会立即达到最大频率运行,空闲时间增加就降低频率
conservative 按需快速动态调整CPU频率, 比 ondemand 的调整更保守
schedutil 基于调度程序调整 CPU 频率
设置CPU governor的值为配置文件中 “governor” 参数的值;CPU governor是内核的CPU频率管理器,通过参数来对CPU的频率进行调节,主要是以下几种参数:
CPU 的governor可以使用如下命令查看:
查看目前支持的governor
[root@~]# cpupower --cpu all frequency-info --governors
analyzing CPU 0:
available cpufreq governors: performance powersave
查看正在使用的governor
[root@~]# cpupower --cpu all frequency-info --policy
analyzing CPU 0:
current policy: frequency should be within 800 MHz and 4.10 GHz.
The governor "performance" may decide which speed to use
within this range.
tuned特性主要利用Linux系统中已有的调优方法和工具,包括对电源管理、CPU、内存和磁盘等内核参数的调整。这些方法和工具被整合到具体的profile配置文件中,以便于对系统进行性能调优。
对于Linux操作系统的用户来说,根据不同的使用场景和需求调整系统性能非常方便。他们可以轻松地使用现有的配置文件或自定义自己的配置文件,极大地简化了操作系统性能调优的过程。
The tuned feature primarily utilizes existing tuning methods and tools available in the Linux system, including power management utilities and adjustments to kernel parameters such as CPU, memory, and disk. These are integrated into specific profiles to facilitate performance tuning of the system.
For users of the Linux operating system, it is convenient to adjust the system's performance based on different usage scenarios and requirements. They can easily utilize existing profiles or customize their own profiles, greatly simplifying the process of performance tuning for the operating system.
原文链接:调优系统性能
原文链接:详解Linux性能调优之tuned特性 | Lenix Blog