Performance
Performance Characteristics
Section titled “Performance Characteristics”XDP Packet Processing
Section titled “XDP Packet Processing”Throughput Benchmarks:
- Single CPU core: 10M+ packets/second
- 4 CPU cores: 40M+ packets/second
- 10 Gbps line rate: Sustained with <5% CPU usage
Latency Measurements:
- XDP program execution: <1µs
- Blocklist lookup (HashMap): 50-100ns
- Stats increment (PerCpuArray): ~10ns
Memory Footprint
Section titled “Memory Footprint”Kernel (eBPF Maps):
- Blocklist (10,000 IPs): ~1MB
- Statistics (per-CPU): 16 bytes × 2 × num_cpus
- Total: <2MB
Userspace (Rust):
- Mitigation node: ~50MB Resident Set Size (RSS)
- Orchestrator: ~80MB RSS (includes Machine Learning models)
Optimization Techniques
Section titled “Optimization Techniques”PerCpuArray for Lock-Free Counters
Section titled “PerCpuArray for Lock-Free Counters”Problem: Atomic counters create cache line contention across Central Processing Unit (CPU) cores.
Solution: Each CPU maintains independent counters:
// Kernel: Simple increment, no atomicslet counter = unsafe { STATS.get(0) };if let Some(c) = counter { *c += 1; // No lock, no atomic operation}
// Userspace: Aggregate totalslet total: u64 = per_cpu_values.iter().sum();Benefit: 10x faster than atomic counters in multi-core benchmarks.
HashMap for IP Lookups
Section titled “HashMap for IP Lookups”Why not Array?
- IPv4 address space: 4 billion addresses
- Array would waste ~4GB of memory
- HashMap uses ~1MB for 10,000 IPs
Hash Function: Linux kernel SipHash (cryptographically secure, DoS-resistant)
Collision Handling: Open addressing with linear probing
XDP vs Traditional iptables
Section titled “XDP vs Traditional iptables”iptables DROP path:
- Packet reaches driver → allocate
sk_buff(1000+ bytes) - Traverse netfilter hooks (multiple table lookups)
- Evaluate iptables rules (linear scan)
- Drop packet → free
sk_buff
XDP DROP path:
- Packet reaches driver
- Execute XDP program (single HashMap lookup)
- Return
XDP_DROP
Savings: ~1,000 CPU cycles per dropped packet
Benchmarking
Section titled “Benchmarking”Generate Test Traffic
Section titled “Generate Test Traffic”Using pktgen (Linux built-in packet generator):
# Load kernel modulesudo modprobe pktgen
# Configure packet generationcat > /tmp/pktgen.sh << 'EOF'echo "add_device eth0" > /proc/net/pktgen/kpktgend_0echo "dst 192.168.100.100" > /proc/net/pktgen/eth0echo "dst_mac 00:11:22:33:44:55" > /proc/net/pktgen/eth0echo "count 10000000" > /proc/net/pktgen/eth0echo "pkt_size 64" > /proc/net/pktgen/eth0echo "start" > /proc/net/pktgen/pgctrlEOF
sudo bash /tmp/pktgen.shMonitor Performance
Section titled “Monitor Performance”# Watch real-time statisticswatch -n 1 'curl -s http://localhost:9090/api/v1/stats | jq .'
# Expected output (10M pps):# {# "packets_passed": 10000000,# "packets_dropped": 0# }
# Check CPU usagetop -p $(pgrep mitigation-node)
# Expected: 3-5% CPU at 1Gbps, 30-40% at 10GbpsStress Test Results
Section titled “Stress Test Results”| Traffic Rate | CPU Usage (4 cores) | Latency | Drop Rate |
|---|---|---|---|
| 1 Gbps (1M pps) | 3-5% | <500ns | 0% |
| 5 Gbps (5M pps) | 15-20% | <800ns | 0% |
| 10 Gbps (10M pps) | 30-40% | <1µs | 0% |
| 40 Gbps (40M pps) | 95%+ | <5µs | <0.1% |
Tuning
Section titled “Tuning”Increase Blocklist Capacity
Section titled “Increase Blocklist Capacity”Edit secbeat-ebpf/src/main.rs:
#[map]static BLOCKLIST: HashMap<u32, u8> = HashMap::with_max_entries(50000, 0); // Increase from 10k to 50kRebuild:
cargo xtask build-ebpf --releasecargo build --releaseCPU Affinity for Dedicated Cores
Section titled “CPU Affinity for Dedicated Cores”Pin XDP processing to specific CPU cores:
# Pin to CPUs 0-3 (isolate from other processes)# Mode is set via config file [platform].mode = "syn"sudo taskset -c 0-3 ./mitigation-node
# Verify affinityps -eLo pid,tid,psr,comm | grep mitigationEnable Receive Side Scaling (RSS)
Section titled “Enable Receive Side Scaling (RSS)”Distribute packet processing across multiple CPU cores:
# Check current RSS queue countethtool -l eth0
# Expected output:# Combined: 4
# Increase to 8 queues (if NIC supports)sudo ethtool -L eth0 combined 8
# Verifyethtool -S eth0 | grep rx_queueKernel Boot Parameters
Section titled “Kernel Boot Parameters”Optimize for network performance:
# Edit /etc/default/grubGRUB_CMDLINE_LINUX="isolcpus=0-3 nohz_full=0-3 rcu_nocbs=0-3"
# Update grubsudo update-grubsudo rebootThis isolates CPUs 0-3 for XDP processing (no scheduler interrupts).
Known Limitations
Section titled “Known Limitations”Platform Requirements
Section titled “Platform Requirements”- Linux Only: XDP requires Linux kernel 5.15+
- Driver Support: Not all Network Interface Cards support native XDP
- Check:
ethtool -k eth0 | grep xdp - Fallback: Generic XDP (slower, but works on all NICs)
- Check:
Container Limitations
Section titled “Container Limitations”- ❌ Docker-in-Docker: Cannot load XDP (lacks kernel access)
- ✅ Native Docker: Works with
--privilegedand host network - ✅ LXC: Full kernel access, recommended for XDP
Memory Constraints
Section titled “Memory Constraints”eBPF verifier enforces limits:
- Stack size: 512 bytes per program
- Map size: Kernel memory limits (check
ulimit -l) - Program complexity: ~1M instructions max
Profiling
Section titled “Profiling”CPU Profiling with perf
Section titled “CPU Profiling with perf”# Record CPU samples during testsudo perf record -F 99 -p $(pgrep mitigation-node) -g -- sleep 30
# Generate flamegraphsudo perf script | stackcollapse-perf.pl | flamegraph.pl > flamegraph.svg
# Open in browserfirefox flamegraph.svgeBPF Program Statistics
Section titled “eBPF Program Statistics”# View program execution statssudo bpftool prog show id 42
# Expected output:# 42: xdp name secbeat_xdp tag a1b2c3d4e5f6g7h8# loaded_at 2025-11-24T01:00:00+0000# run_time_ns 1234567890# run_cnt 10000000Calculate average latency: run_time_ns / run_cnt = 123ns per packet