Skip to Content
ドキュメント運用システム管理パフォーマンスチューニング

パフォーマンスチューニング

この記事では、ハードウェアを最大限に活用するために、Ubuntu 26.04 で一般的に使用されるパフォーマンス監視ツールと最適化手法について説明します。

システム監視ツール

htop - 対話型プロセスマネージャー

# Install (usually pre-installed on Ubuntu 26.04) sudo apt install htop # Launch htop

一般的な htop 操作:

ショートカット関数
F2セットアップ/設定
F3検索プロセス
F4フィルタープロセス
F5ツリービュー
F6選別
F9シグナルを送信 (プロセスを強制終了)
F10やめる
uユーザーによるフィルター
M記憶に基づいて並べ替える
PCPUごとに並べ替える
T時間順に並べ替える

その他の監視ツール

# top - basic process monitoring top # vmstat - virtual memory statistics vmstat 1 5 # once per second, 5 times # iostat - I/O statistics sudo apt install sysstat iostat -xz 1 # iotop - view per-process I/O sudo apt install iotop sudo iotop # nmon - comprehensive performance monitoring sudo apt install nmon nmon # glances - modern system monitoring sudo apt install glances glances # btop - visually appealing resource monitor sudo apt install btop btop

システムリソース情報の表示

# CPU information lscpu cat /proc/cpuinfo | grep "model name" | head -1 # Memory information free -h cat /proc/meminfo # Disk usage df -h # Load averages uptime cat /proc/loadavg # Network connections ss -tunapl

CPUの最適化

CPU周波数管理

# cpufrequtils is deprecated; use cpupower instead (provided by linux-tools) sudo apt install linux-tools-common linux-tools-generic # View current CPU frequency and governor cpupower frequency-info # View available frequency governors cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors # Set to performance mode sudo cpupower frequency-set -g performance # Set to power-saving mode sudo cpupower frequency-set -g powersave

デスクトップでは、上位レベルの電源管理ツール power-profiles-daemon を使用することもできます。

# List available power profiles powerprofilesctl list # Switch to performance mode powerprofilesctl set performance

プロセスの優先順位

# Use nice to start a process (-20 to 19, lower values = higher priority) nice -n 10 /path/to/task.sh # Change the priority of a running process renice -n 5 -p PID # Set real-time priority sudo chrt -f 50 /path/to/realtime-task # Pin a process to specific CPU cores taskset -c 0,1 /path/to/task.sh

メモリの最適化

スワップチューニング

# View current swap usage swapon --show free -h # View current swappiness value (default is 60) cat /proc/sys/vm/swappiness

swappiness パラメータ ガイド:

価値使用事例
0-10十分なメモリを備えたデスクトップ システム/サーバー、スワップ使用量を最小限に抑える
30-40一般的なサーバーのワークロード
60デフォルト値
80-100メモリに制約のあるシステムでは、スワップを積極的に使用する
# Temporarily change swappiness sudo sysctl vm.swappiness=10 # Permanently change swappiness echo "vm.swappiness=10" | sudo tee -a /etc/sysctl.d/99-performance.conf sudo sysctl --system

その他のメモリパラメータ

# Cache pressure (default 100; lower values retain more directory and inode caches) echo "vm.vfs_cache_pressure=50" | sudo tee -a /etc/sysctl.d/99-performance.conf # Dirty page writeback policy echo "vm.dirty_ratio=15" | sudo tee -a /etc/sysctl.d/99-performance.conf echo "vm.dirty_background_ratio=5" | sudo tee -a /etc/sysctl.d/99-performance.conf # Apply all changes sudo sysctl --system

キャッシュのクリア

# Free page cache sudo sync; echo 1 | sudo tee /proc/sys/vm/drop_caches # Free dentry and inode cache sudo sync; echo 2 | sudo tee /proc/sys/vm/drop_caches # Free all caches sudo sync; echo 3 | sudo tee /proc/sys/vm/drop_caches

I/Oスケジューラ

I/O スケジューラの表示と変更

# View current I/O scheduler cat /sys/block/sda/queue/scheduler # Example output: [mq-deadline] kyber bfq none # Temporarily change echo "bfq" | sudo tee /sys/block/sda/queue/scheduler

I/O スケジューラの選択

スケジューラ使用事例
mq-deadline汎用、ほとんどの HDD および SSD に適しています
bfqデスクトップ システムでは、インタラクティブな応答性が向上します。
kyber高性能NVMe SSD
noneNVMe SSD 直接アクセス、最小の遅延

I/O スケジューラ設定の永続化

udev ルールを作成します。

sudo nano /etc/udev/rules.d/60-scheduler.rules
# HDD uses mq-deadline ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="mq-deadline" # SSD uses none or mq-deadline ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="mq-deadline" # NVMe uses none ACTION=="add|change", KERNEL=="nvme[0-9]*", ATTR{queue/scheduler}="none"
sudo udevadm control --reload-rules

SSDの最適化

TRIM を有効にする

TRIM を使用すると、オペレーティング システムがどのデータ ブロックが使用されなくなったかを SSD に通知できるため、SSD のパフォーマンスを維持し、寿命を延ばすことができます。

# Check if the SSD supports TRIM sudo hdparm -I /dev/sda | grep TRIM # Manually run TRIM sudo fstrim -v / # Check the scheduled TRIM service systemctl status fstrim.timer # Enable scheduled TRIM (runs weekly) sudo systemctl enable --now fstrim.timer

fstab の SSD 最適化オプション

# Recommended SSD mount options UUID=xxxx / ext4 defaults,noatime,discard 0 1
オプション説明
noatimeファイルのアクセス時間を記録しないため、書き込みが減少します
discardリアルタイム TRIM (または代わりに fstrim.timer を使用)
commit=60コミット間隔を延長し、書き込み頻度を減らす

不必要なディスク書き込みの削減

# Mount /tmp to memory # Add to /etc/fstab: # tmpfs /tmp tmpfs defaults,noatime,size=2G 0 0 # Reduce journal writes sudo nano /etc/systemd/journald.conf # Set: Storage=volatile (memory only, lost after reboot) # Or: SystemMaxUse=100M (limit journal size)

ネットワークの最適化

TCPパラメータのチューニング

sudo nano /etc/sysctl.d/99-network.conf
# TCP buffer sizes net.core.rmem_max=16777216 net.core.wmem_max=16777216 net.ipv4.tcp_rmem=4096 87380 16777216 net.ipv4.tcp_wmem=4096 65536 16777216 # TCP connection optimization net.ipv4.tcp_fastopen=3 net.ipv4.tcp_mtu_probing=1 net.ipv4.tcp_congestion_control=bbr # Connection queue net.core.somaxconn=65535 net.core.netdev_max_backlog=65535 # TIME_WAIT optimization net.ipv4.tcp_tw_reuse=1 net.ipv4.tcp_fin_timeout=15
# Enable BBR congestion control echo "net.core.default_qdisc=fq" | sudo tee -a /etc/sysctl.d/99-network.conf echo "net.ipv4.tcp_congestion_control=bbr" | sudo tee -a /etc/sysctl.d/99-network.conf sudo sysctl --system # Verify BBR is active sysctl net.ipv4.tcp_congestion_control

ファイルシステムの最適化

ext4 の最適化

# View filesystem parameters sudo tune2fs -l /dev/sda2 # Reduce reserved space (default 5%, can be lowered for large partitions) sudo tune2fs -m 1 /dev/sda2

ファイル記述子の制限

# View current limit ulimit -n # Temporarily increase the limit ulimit -n 65535 # Permanently change sudo nano /etc/security/limits.conf
# /etc/security/limits.conf * soft nofile 65535 * hard nofile 65535

システムレベル:

echo "fs.file-max=2097152" | sudo tee -a /etc/sysctl.d/99-performance.conf sudo sysctl --system

ブートの最適化

# Analyze boot time systemd-analyze # View boot time per service systemd-analyze blame # View critical boot path systemd-analyze critical-chain # Disable unnecessary services sudo systemctl disable bluetooth.service # not using Bluetooth sudo systemctl disable cups.service # not using printing sudo systemctl disable ModemManager.service # not using modem # Check boot log for errors journalctl -b -p err

パフォーマンスのベンチマーク

# Disk performance test sudo apt install fio # Sequential read test fio --name=seqread --rw=read --bs=1M --size=1G --numjobs=1 --runtime=30 # Random read/write test fio --name=randreadwrite --rw=randrw --bs=4k --size=1G --numjobs=4 --runtime=30 # Simple disk write speed test dd if=/dev/zero of=/tmp/testfile bs=1M count=1024 oflag=direct # Memory bandwidth test sudo apt install sysbench sysbench memory run # CPU benchmark sysbench cpu --threads=$(nproc) run # Network performance test sudo apt install iperf3 # Server: iperf3 -s # Client: iperf3 -c server_ip