Performance
Chapter 47: Memory & CPU Optimization
Section titled “Chapter 47: Memory & CPU Optimization”Overview
Section titled “Overview”Optimizing blockchain node performance is crucial for maintaining network participation, reducing operational costs, and ensuring reliable RPC services. Blockchain nodes are resource-intensive applications that require careful tuning of memory, CPU, storage, and network parameters. This chapter provides comprehensive guidance on optimizing node performance across different hardware configurations and use cases.
47.1 Memory Optimization
Section titled “47.1 Memory Optimization”Understanding Memory Usage
Section titled “Understanding Memory Usage”Blockchain nodes have complex memory requirements:
┌─────────────────────────────────────────────────────────────┐│ GETH MEMORY USAGE BREAKDOWN │├─────────────────────────────────────────────────────────────┤│ ││ Total Memory: 16-64 GB ││ ││ ┌─────────────────────────────────────────────────────┐ ││ │ Heap Memory │ ││ │ ┌───────────┬───────────────┬───────────────┐ │ ││ │ │ State │ Cache │ Trie Cache │ │ ││ │ │ (EVM) │ (Blocks) │ (Merkle) │ │ ││ │ │ ~4GB │ ~2GB │ ~2GB │ │ ││ │ └───────────┴───────────────┴───────────────┘ │ ││ └─────────────────────────────────────────────────────┘ ││ ││ ┌─────────────────────────────────────────────────────┐ ││ │ Off-Heap Memory │ ││ │ ┌───────────┬───────────────┬───────────────┐ │ ││ │ │ LevelDB │ MDBX │ Snapshots │ │ ││ │ │ Cache │ Cache │ (Read-Only) │ │ ││ │ │ ~4GB │ ~4GB │ ~8GB │ │ ││ │ └───────────┴───────────────┴───────────────┘ │ ││ └─────────────────────────────────────────────────────┘ ││ │└─────────────────────────────────────────────────────────────┘Cache Configuration
Section titled “Cache Configuration”Geth Cache Flags
Section titled “Geth Cache Flags”# Cache size in megabytes# Default: 4096 MB (4 GB)
# For 16GB RAM systemgeth --cache 4096
# For 32GB RAM systemgeth --cache 8192
# For 64GB RAM systemgeth --cache 16384
# For high-performance serversgeth --cache 32768
# View cache statisticsgeth attach http://localhost:8545> debug.getBlockChainInfo()Memory-Tuned Configuration
Section titled “Memory-Tuned Configuration”Configuration for Different RAM Sizes
Section titled “Configuration for Different RAM Sizes”| System RAM | Cache | GC Settings | Notes |
|---|---|---|---|
| 8 GB | 2048 | Default | Minimal configuration |
| 16 GB | 4096 | Default | Standard configuration |
| 32 GB | 8192 | GOGC=200 | Good performance |
| 64 GB | 16384 | GOGC=300 | High performance |
| 128 GB | 32768 | GOGC=400 | Maximum performance |
# High-memory configurationexport GOGC=300export GOMEMLIMIT=32GiB
geth \ --cache 16384 \ --cache.database 8192 \ --cache.trie 4096 \ --cache.snapshot 4096Memory Monitoring
Section titled “Memory Monitoring”# Monitor memory usagewatch -n 5 'free -h'
# Detailed process memoryps aux | grep geth
# Memory over timepmap -x $(pgrep geth) | tail -1
# Check for memory leaksjournalctl -u geth | grep -i "memory"journalctl -u geth | grep -i "gc"
# Using gotop (if installed)gotop47.2 CPU Optimization
Section titled “47.2 CPU Optimization”CPU Architecture Considerations
Section titled “CPU Architecture Considerations”┌─────────────────────────────────────────────────────────────┐│ CPU OPTIMIZATION STRATEGY │├─────────────────────────────────────────────────────────────┤│ ││ Blockchain Workload: ││ ┌─────────────────────────────────────────────────────┐ ││ │ 40% - Cryptographic operations (hashing) │ ││ │ 30% - Database I/O (LevelDB/RocksDB) │ ││ │ 20% - Network processing │ ││ │ 10% - State trie processing │ ││ └─────────────────────────────────────────────────────┘ ││ ││ Recommendations: ││ ✓ High single-thread performance is critical ││ ✓ More cores help with parallel processing ││ ✓ AVX2/AVX-512 instructions for crypto ││ ✓ ECC RAM for stability ││ │└─────────────────────────────────────────────────────────────┘CPU Configuration
Section titled “CPU Configuration”# Limit CPU usage (useful for shared servers)taskset -c 0-3 geth --syncmode snap
# View available coresnproc
# Check CPU flags for crypto supportgrep -o 'avx[0-9]*' /proc/cpuinfo | head -1
# Disable hyperthreading (sometimes helps)# In BIOS, or via:tuna --cores=0-7 gethGo Runtime Optimization
Section titled “Go Runtime Optimization”# Set GOMAXPROCS to number of coresexport GOMAXPROCS=16
# Set GOMAXPROCS dynamically# In systemd service:Environment=GOMAXPROCS=16
# Or programmatically:geth --gcmode=archive --exec "GOMAXPROCS=16"47.3 Disk Optimization
Section titled “47.3 Disk Optimization”Storage Requirements
Section titled “Storage Requirements”| Node Type | Storage | Growth/Year |
|---|---|---|
| Full Node | ~1.2 TB | ~100 GB |
| Archive Node | ~12 TB | ~500 GB |
| Pruned Node | ~400 GB | ~100 GB |
Storage Performance Comparison
Section titled “Storage Performance Comparison”| Storage Type | Read IOPS | Write IOPS | Notes |
|---|---|---|---|
| HDD | 100 | 100 | Not recommended |
| SATA SSD | 50,000 | 20,000 | Testnet only |
| NVMe SSD | 500,000+ | 300,000+ | Required for production |
| NVMe (Gen4) | 700,000+ | 500,000+ | Optimal |
Optimal Storage Configuration
Section titled “Optimal Storage Configuration”Partition Alignment
Section titled “Partition Alignment”# Check current partition alignmentblockdev --report
# For NVMe, ensure 4K alignmentsudo fdisk -l /dev/nvme0n1Filesystem Recommendations
Section titled “Filesystem Recommendations”# Use ext4 or XFS (not BTRFS for database)# Format with optimal settingssudo mkfs.ext4 -E stride=128,stripe-width=128 /dev/nvme0n1
# Mount with noatime for better performance# /etc/fstab:# /dev/nvme0n1 /data ext4 defaults,noatime,nodiratime,discard 0 2Database Optimization
Section titled “Database Optimization”LevelDB Settings (Geth default)
Section titled “LevelDB Settings (Geth default)”# Geth automatically tunes LevelDB# But you can override:
# Cache for LevelDBgeth --cache 8192
# Number of open filesgeth --cache.fdlimit 1024RocksDB Settings (Erigon)
Section titled “RocksDB Settings (Erigon)”# Erigon with RocksDB tuningerigon \ --db.size.limit=3TB \ --db.allow_unfastiate_geth=true \ --prune.mode=minimal \ --private.api.addr=localhost:9090Disk Monitoring
Section titled “Disk Monitoring”# Check disk I/Oiostat -x 5
# Check disk usagedf -h
# Check I/O wait (high = bottleneck)vmstat 1
# Monitor disk queueiostat -x 1 | grep -E "Device|vd[a-z]"
# Benchmark storagefio --name=random_read --ioengine=libaio --iodepth=32 \ --bs=4k --size=1G --numjobs=4 --runtime=30 \ --readonly --filename=/tmp/fio_test47.4 Network Optimization
Section titled “47.4 Network Optimization”Network Bandwidth
Section titled “Network Bandwidth”| Node Type | Min Bandwidth | Recommended |
|---|---|---|
| Light Node | 10 Mbps | 100 Mbps |
| Full Node | 50 Mbps | 1 Gbps |
| Archive Node | 100 Mbps | 10 Gbps |
| Validator | 100 Mbps | 1 Gbps |
Network Configuration
Section titled “Network Configuration”# Increase file descriptorsecho "* soft nofile 65536" | sudo tee -a /etc/security/limits.confecho "* hard nofile 65536" | sudo tee -a /etc/security/limits.conf
# For running user:echo "$USER soft nofile 65536" | sudo tee -a /etc/security/limits.confecho "$USER hard nofile 65536" | sudo tee -a /etc/security/limits.conf
# Increase network bufferssudo sysctl -w net.core.rmem_max=16777216sudo sysctl -w net.core.wmem_max=16777216
# Persist settingsecho "net.core.rmem_max=16777216" | sudo tee -a /etc/sysctl.confecho "net.core.wmem_max=16777216" | sudo tee -a /etc/sysctl.confP2P Optimization
Section titled “P2P Optimization”# Increase max peersgeth --maxpeers 100
# Adjust dial metricsgeth --nat extip:YOUR_PUBLIC_IP
# Enable P2P metricsgeth --pprof --pprofaddr localhost47.5 Full Optimization Guide
Section titled “47.5 Full Optimization Guide”High-Performance Configuration
Section titled “High-Performance Configuration”systemd Service File
Section titled “systemd Service File”[Unit]Description=Ethereum Geth NodeAfter=network.target
[Service]Type=simpleUser=ethereumWorkingDirectory=/home/ethereumExecStart=/usr/local/bin/geth \ --mainnet \ --syncmode snap \ --cache 16384 \ --cache.database 8192 \ --cache.trie 4096 \ --cache.snapshot 4096 \ --maxpeers 100 \ --http \ --http.addr 0.0.0.0 \ --http.port 8545 \ --http.api eth,net,web3,debug,txpool \ --http.vhosts "*" \ --http.corsdomain "*" \ --ws \ --ws.addr 0.0.0.0 \ --ws.port 8546 \ --ws.api eth,net,web3 \ --ws.origins "*" \ --datadir /data/ethereum \ --keydir /data/ethereum/keystore \ --allow-insecure-unlock \ --rpc.gascap 50000000 \ --rpc.txfeecap 100 \ --ws.txfeecap 10 \ --pprof \ --pprofaddr localhost \ --pprofport 6060
# Memory limitsMemoryMax=64GMemoryHigh=48G
# CPU limitsCPUAffinity=0-15
# Restart settingsRestart=on-failureRestartSec=5sStandardOutput=append:/var/log/geth/output.logStandardError=append:/var/log/geth/error.log
[Install]WantedBy=multi-user.targetPerformance Tuning Script
Section titled “Performance Tuning Script”#!/bin/bashecho "=== Ethereum Node Performance Optimization ==="
# 1. Set kernel parametersecho "Configuring kernel parameters..."cat >> /etc/sysctl.conf << EOF# Network optimizationsnet.core.rmem_max=16777216net.core.wmem_max=16777216net.ipv4.tcp_rmem=4096 87380 16777216net.ipv4.tcp_wmem=4096 65536 16777216
# File descriptor limitsfs.file-max=65536
# Blockchain specificvm.max_map_count=1048576EOF
sysctl -p
# 2. Set resource limitsecho "Configuring resource limits..."cat >> /etc/security/limits.conf << EOF* soft nofile 65536* hard nofile 65536* soft memlock unlimited* hard memlock unlimitedEOF
# 3. CPU governorecho "Setting CPU governor..."for cpu in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo performance > $cpudone
# 4. Disable transparent huge pagesecho "Disabling transparent huge pages..."echo never > /sys/kernel/mm/transparent_hugepage/enabledecho never > /sys/kernel/mm/transparent_hugepage/defrag
# 5. Set IO scheduler (for SSDs)echo "Setting IO scheduler..."for disk in /sys/block/sd*/queue/scheduler; do echo none > $diskdone
echo "=== Optimization Complete ==="echo "Please restart your node for changes to take effect"47.6 Performance Monitoring
Section titled “47.6 Performance Monitoring”Key Metrics
Section titled “Key Metrics”| Metric | Good | Warning | Critical |
|---|---|---|---|
| CPU Usage | < 60% | 60-80% | > 80% |
| Memory Usage | < 70% | 70-85% | > 85% |
| Disk I/O Wait | < 10% | 10-20% | > 20% |
| Network In | Stable | Variable | Dropping |
| Peer Count | > 10 | 5-10 | < 5 |
Prometheus Metrics
Section titled “Prometheus Metrics”# node_exporter config for system metricsscrape_configs: - job_name: 'node' static_configs: - targets: ['localhost:9100']
- job_name: 'geth' static_configs: - targets: ['localhost:6060']Grafana Dashboard
Section titled “Grafana Dashboard”Create a dashboard with these key queries:
# CPU Usage100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
# Memory Usage(node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes * 100
# Disk I/Orate(node_disk_read_bytes_total[5m])rate(node_disk_written_bytes_total[5m])
# Network Trafficrate(node_network_receive_bytes_total{device="eth0"}[5m])rate(node_network_transmit_bytes_total{device="eth0"}[5m])
# Geth sync progressethereum_block_height / ethereum_network_block * 10047.7 Troubleshooting Performance
Section titled “47.7 Troubleshooting Performance”Common Issues
Section titled “Common Issues”High Memory Usage
Section titled “High Memory Usage”# Check memory consumptionps aux --sort=-%mem | head -10
# Check for memory leaksjournalctl -u geth | grep -i "out of memory"
# Reduce cache if neededgeth --cache 4096High CPU Usage
Section titled “High CPU Usage”# Find process using most CPUtop -o %CPU
# Check for runaway goroutinescurl http://localhost:6060/debug/pprof/goroutine?debug=1
# Reduce sync activitygeth --syncmode fullDisk Bottleneck
Section titled “Disk Bottleneck”# Check I/O waitiostat -x 1
# Find I/O heavy processesiotop
# Consider upgrading to NVMelsblk -d -o NAME,TYPE,ROTASummary
Section titled “Summary”- Memory: Allocate appropriate cache based on available RAM (typically 50-75% of available memory)
- CPU: Prioritize single-thread performance; more cores help with parallelism
- Storage: NVMe SSDs are mandatory for production nodes
- Network: Ensure adequate bandwidth and configure file descriptor limits
- Monitoring: Track key metrics and set up alerts for degradation
- Tuning: Use the comprehensive configuration examples provided for your hardware
- Optimization: Run the optimization script for system-level improvements
Next Chapter
Section titled “Next Chapter”In Chapter 48: Network Connectivity Issues, we’ll explore network troubleshooting.
Last Updated: 2026-02-22