OSX-PROXMOX/scripts/orion-performance-tuning

119 lines
4.4 KiB
Bash
Executable File

#!/bin/bash
#########################################################################################################################
#
# Script: orion-performance-tuning
# Purpose: Apply performance optimizations for Dell R730 ORION
# Description: One-time boot script to optimize system for routing and virtualization
#
#########################################################################################################################
LOG_FILE="/var/log/orion/performance-tuning.log"
# Create log directory
mkdir -p /var/log/orion
# Logging function
log() {
local level=$1
shift
local message="$@"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo "${timestamp} [${level}] ${message}" | tee -a "$LOG_FILE"
}
log INFO "ORION Performance Tuning starting..."
# 1. CPU Governor - Set to performance mode
log INFO "Setting CPU governor to performance mode..."
for cpu in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do
if [ -f "$cpu" ]; then
echo performance > "$cpu" 2>/dev/null || log WARNING "Failed to set governor for $cpu"
fi
done
# 2. Disable CPU C-States (prevents TSC issues with macOS)
log INFO "Disabling CPU C-States for stable TSC..."
# This is typically done in BIOS, but we can try via kernel
if [ -f /sys/module/intel_idle/parameters/max_cstate ]; then
echo 0 > /sys/module/intel_idle/parameters/max_cstate 2>/dev/null || log WARNING "Failed to disable C-States"
fi
# 3. Network Interface Optimizations
log INFO "Tuning network interfaces..."
for iface in eno1 eno2 eno3 eno4 eno5 eno6 enp3s0f0 enp3s0f1; do
if ip link show "$iface" >/dev/null 2>&1; then
log INFO "Tuning $iface..."
# Increase ring buffer sizes
ethtool -G "$iface" rx 4096 tx 4096 2>/dev/null || log WARNING "Failed to set ring buffers for $iface"
# Enable hardware offloading
ethtool -K "$iface" tso on gso on gro on 2>/dev/null || log WARNING "Failed to enable offloading for $iface"
# Disable power management
ethtool -s "$iface" wol d 2>/dev/null || log WARNING "Failed to disable WoL for $iface"
fi
done
# 4. Kernel Network Stack Tuning
log INFO "Tuning kernel network stack..."
sysctl -w net.core.rmem_max=134217728 >/dev/null 2>&1
sysctl -w net.core.wmem_max=134217728 >/dev/null 2>&1
sysctl -w net.core.rmem_default=16777216 >/dev/null 2>&1
sysctl -w net.core.wmem_default=16777216 >/dev/null 2>&1
sysctl -w net.core.netdev_max_backlog=50000 >/dev/null 2>&1
sysctl -w net.ipv4.tcp_rmem="4096 87380 134217728" >/dev/null 2>&1
sysctl -w net.ipv4.tcp_wmem="4096 65536 134217728" >/dev/null 2>&1
sysctl -w net.ipv4.tcp_congestion_control=bbr >/dev/null 2>&1
# 5. VM Swap and Memory Tuning
log INFO "Tuning memory and swap..."
sysctl -w vm.swappiness=10 >/dev/null 2>&1
sysctl -w vm.vfs_cache_pressure=50 >/dev/null 2>&1
sysctl -w vm.dirty_ratio=10 >/dev/null 2>&1
sysctl -w vm.dirty_background_ratio=5 >/dev/null 2>&1
# 6. Increase open file limits
log INFO "Increasing file descriptor limits..."
ulimit -n 1048576 2>/dev/null || log WARNING "Failed to set file descriptor limit"
# 7. Disable unnecessary services
log INFO "Optimizing system services..."
# (Be careful with this - only disable if certain)
# systemctl disable bluetooth.service 2>/dev/null
# systemctl disable cups.service 2>/dev/null
# 8. IRQ Affinity (balance interrupts across CPUs)
log INFO "Configuring IRQ affinity..."
if command -v irqbalance >/dev/null 2>&1; then
systemctl enable irqbalance
systemctl restart irqbalance
log INFO "IRQ balancing enabled"
fi
# 9. Transparent Huge Pages (THP) - Enable for better performance
log INFO "Configuring Transparent Huge Pages..."
if [ -f /sys/kernel/mm/transparent_hugepage/enabled ]; then
echo always > /sys/kernel/mm/transparent_hugepage/enabled 2>/dev/null || log WARNING "Failed to enable THP"
fi
# 10. I/O Scheduler - Set to none for SSDs, mq-deadline for HDDs
log INFO "Configuring I/O scheduler..."
for disk in /sys/block/sd*/queue/scheduler; do
if [ -f "$disk" ]; then
echo none > "$disk" 2>/dev/null || echo mq-deadline > "$disk" 2>/dev/null
fi
done
log INFO "Performance tuning completed successfully"
log INFO "Optimization summary:"
log INFO " - CPU governor: performance"
log INFO " - Network interfaces: optimized (ring buffers, offloading)"
log INFO " - Kernel network stack: BBR, large buffers"
log INFO " - Memory: low swappiness, optimized cache pressure"
log INFO " - IRQ balancing: enabled"
log INFO " - Transparent Huge Pages: enabled"
exit 0