System Buffer Tuning - TCP and Network Performance Optimization

Sistemo Buffer Tuning: La Hidden Culprit Malantaŭ "Network Problems"

Administra Resumo

Retaj inĝenieroj ofte renkontas situaciojn kie TCP-fenestro aŭ aplikiĝefikeco estas kulpigita sur retinfrastrukturo. Post rezultado de ampleksaj pakaĵasimiladoj, tcpdumps, kaj sendostacia analizo, la vera proplempunkto ofte estas malkovrita: elĉerpita NIC (Network Interface Card) aŭ Os-nivelaj bufroj sur la kliento aŭ servilsistemoj.

Tiu artikolo disponigas kaj heredaĵon (ĉirkaŭ 2009) kaj nunan (2025-2026) bufrokonfiguraciojn por Linukso, Fenestroj, kaj makOS, kune kun diagnozaj teknikoj por identigi bufrodeprenon antaŭ ol ĝi iĝas kritika temo.

Oftaj simptomoj de Buffer Exhaustion

  • TCP Zero Window okazaĵoj en pakaĵaj kaptoj
  • Altaj redissendtarifoj malgraŭ malalta sendostacia latenteco
  • Aplikas signife sub havebla bendolarĝo
  • Efikecdegenero sub ŝarĝo kiu pliboniĝas kiam ŝarĝo malpliiĝas
  • Inconsistent efikeco trans similaj hardvarkonfiguracioj
  • Socket-eraroj aŭ "Resource provizore neatingeblaj" mesaĝoj

Kompreni la problemon

TCP Window Scaling Mechanism

TCP uzas fluokontrolmekanismon kie la ricevilo reklamas "fenestrograndecon" indikante kiom multe da datenoj ĝi povas akcepti. Kiam sistembufroj plenigas supren, tiu fenestro ŝrumpas al nul, devigante la sendinton atendi. Tio prezentiĝas kiel retproblemo sed estas fakte mastro-resurstemo.

kie la malsano suferas

  • Socket Buffers (SO SNDBUF/SO RCVBUF): Per-socket sendas kaj ricevas bufrojn
  • TCP Window Buffers: Maksimuma TCP-fenestrograndeco por ligoj
  • Network Device Buffers: NIC ringobufroj por pakaĵeto
  • Nacia Memoro: Totala memoro asignita por interkonektado

Diagnozaj komandoj

Linuksoj

# Check current TCP buffer settings
sysctl net.ipv4.tcp_rmem
sysctl net.ipv4.tcp_wmem
sysctl net.core.rmem_max
sysctl net.core.wmem_max

# Check NIC ring buffer sizes
ethtool -g eth0

# Monitor socket buffer usage
ss -tm

# Check for TCP zero window events
tcpdump -i any 'tcp[tcpflags] & tcp-push != 0' -vv

# Check network statistics for buffer issues
netstat -s | grep -i "buffer\|queue\|drop"

Fenestroj

# Check TCP parameters
netsh interface tcp show global

# View network adapter buffer settings
Get-NetAdapterAdvancedProperty -Name "Ethernet" | Where-Object {$_.DisplayName -like "*buffer*"}

# Monitor TCP statistics
netstat -s -p tcp

# Check receive window auto-tuning
netsh interface tcp show global | findstr "Receive Window"

MacOS Diagnostiko

# Check current buffer settings
sysctl kern.ipc.maxsockbuf
sysctl net.inet.tcp.sendspace
sysctl net.inet.tcp.recvspace

# View network statistics
netstat -s -p tcp

# Monitor socket buffers
netstat -an -p tcp

Linukso Buffer Tuning

Legacy Linux Settings (Circa 2009)

Parametro Legacy Value (2009) Priskribo Priskribo
reto.core.rmem defaŭlto 124928 (122KB) Defaŭlto ricevas socketan bufrograndecon
Neta.core.rmem max 131071 (128KB) Maksimumo ricevas socketan bufrograndecon
Netaturo.wmem defaŭlto 124928 (122KB) Defaŭlto sendas torakan bufrograndecon
La reto.wself max 131071 (128KB) Maksimuma sendi torakan bufrograndecon
reto.ipv4.tcp r mem 4096 87380 174760 TCP ricevas bufron: min, defaŭlto, maks (en bajtoj)
reto.ipv4.tcp w mem 4096 16384 131072 TCP sendas bufron: min, defaŭlto, maks (en bajtoj)
reto.ipv4.tcp mem 196608 262144 393216 TCP memorpaĝoj: malalta, premo, alta
Net.netdev max backlog 1000 Maksimumaj pakaĵetoj en enigo atendovico
Neta.core.opt mem max 10240 (10KB) Maksimuma ancila bufrograndeco per socket

Nunaj Linuksoj (2025-2026)

Parameter Nuna Rekomendita Valoro Description
net.core.rmem_default 16777216 (16MB) Default receive socket buffer size
net.core.rmem_max 134217728 (128MB) Maximum receive socket buffer size
net.core.wmem_default 16777216 (16MB) Default send socket buffer size
net.core.wmem_max 134217728 (128MB) Maximum send socket buffer size
net.ipv4.tcp_rmem 4096 87380 134217728 TCP ricevas bufron: min, defaŭlto, maks (128MB maks)
net.ipv4.tcp_wmem 4096 65536 1342177 TCP sendas bufron: min, defaŭlto, maks (128MB max)
net.ipv4.tcp_mem 8388608 12582912 16777216 TCP memorpaĝoj: malalta, premo, alta (64GB-sistemo)
net.core.netdev_max_backlog 250000 Maksimumaj pakaĵetoj en enirvico (10GbE +)
net.core.optmem_max 65536 (64KB) Maximum ancillary buffer size per socket
reto.ipv4.tcp congestion control bbr Uzu BBR-ŝtopiĝkontrolon (la algoritmo de Google)
reto.ipv4.tcp window scaling 1 1 1 1 Endabla TCP fenestro skalanta (RFC 1323)
reto.ipv4.tcp timestamps 1 Enable TCP tempstampoj por pli bona RTT-takso
reto.ipv4.tcp sack 1 Enable Selective Acsciledgment
reto.ipv4.tcp no metrics save 1 Disigebla kaĉado de TCP-metrikoj

Linukso-konfiguracio

Aldonu tiujn agordojn al /etc/sysctl.conf aŭ krei novan dosieron /etc/sysctl.d/99-network-tuning.conf:

# Network Buffer Tuning for High-Performance Applications
# Optimized for 10GbE+ networks with RTT up to 300ms

# Core socket buffer settings
net.core.rmem_default = 16777216
net.core.rmem_max = 134217728
net.core.wmem_default = 16777216
net.core.wmem_max = 134217728

# TCP buffer settings
net.ipv4.tcp_rmem = 4096 87380 134217728
net.ipv4.tcp_wmem = 4096 65536 134217728
net.ipv4.tcp_mem = 8388608 12582912 16777216

# Device buffer settings
net.core.netdev_max_backlog = 250000
net.core.netdev_budget = 50000
net.core.netdev_budget_usecs = 5000
net.core.optmem_max = 65536

# TCP optimizations
net.ipv4.tcp_congestion_control = bbr
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_sack = 1
net.ipv4.tcp_no_metrics_save = 1
net.ipv4.tcp_moderate_rcvbuf = 1

# Apply with: sysctl -p /etc/sysctl.d/99-network-tuning.conf

NIC Ring Buffer Tuning

# Check current ring buffer sizes
ethtool -g eth0

# Set maximum ring buffer sizes (adjust based on NIC capabilities)
ethtool -G eth0 rx 4096 tx 4096

# Make persistent by adding to /etc/network/interfaces or systemd service
Kritika averto - Memoro-Konstruaĵo: La tcp mem-valoroj estas en memorpaĝoj (tipe 4KB). Grandaj bufrograndecoj povas kaŭzi severan memorpremon:
  • Per-ligo memoro: Ĉiu ligo povas uzi ĝis r mem max + w mem max (256MB kun 128MB bufroj)
  • Totala sistemefiko: 1,000 ligoj × 256MB = 256GB ebla uzokutimo
  • Sekura takso: Max samtempaj ligoj × 256MB ne devus superi 50% de sistemo RAM
  • Ekzemplo: 64GB-servilo devus limigi maksligojn al 125 samtempaj alt-trakligoj kun 128MB bufroj
  • Rekomendo por serviloj kun <16GB RAM: Redukti bufrojn al 16-32MB maks kaj adapti tcp mem proporcie

Windows Buffer Tuning

Legacy Windows Settings (Circa 2009 - Fenestroj Vista/7/Server 2008)

Parameter Legacy Value (2009) Situo
TcpWindows 65535 (64KB) Registro: HKLMSystem \CurrentControlSet-Services\Tcpip\Parameters
Tcp1323 Opts 0 (disable) Fenestra skarpo handikapita defaŭlte
Defaŭlta ReceiveWindow 8192 (8KB) Defaŭlto ricevas fenestron
Defaŭltaj plendoj 8192 (8KB) Defaŭlo sendas fenestron
GlobalMaxTcpWindowSize 65535 (64KB) Maksimuma TCP-fenestrograndeco
TcpNumConnections 16777214 Maksimuma TCP-ligoj

Nunaj Vindozo Settings (Windows 10/11/Server 2019-2025)

Modernaj fenestroj uzas la Vidu ankaŭ: Windows Auto-Tuning trajto, kiu dinamike adaptas ricevas bufrojn bazitajn sur retkondiĉoj.

Trajto Nuna Rekomendita Setting Description
Auto-Tuning Level normala (aŭ tre eksperimenta por 10GbE +) Dinamiko ricevas fenestron
Ricevi-Side Scaling (RSS) ebligis Distribute-retpretigo trans CPUoj
Chimney Offload aŭtomata (aŭ handikapita sur modernaj NICoj) TCP malŝarĝo al NIC-hardvaro
NetDMA handikapita handikapulo Rekta Memoro Aliro (malprecedigita)
TCP Global Parameters Vidu komandojn sub Sistemo-kovranta TCP-valoroj
Kontentigo Provizanto CUBIC (aŭ NewReno-lanugo) TCP-ŝtopiĝo-kontrolo-algoritmo

Windows Configuration Commands

# Check current auto-tuning level
netsh interface tcp show global

# Enable auto-tuning (normal mode - default for most scenarios)
netsh interface tcp set global autotuninglevel=normal

# For high-bandwidth, high-latency networks (10GbE+, data center environments)
netsh interface tcp set global autotuninglevel=experimental

# For conservative tuning (if experimental causes issues)
netsh interface tcp set global autotuninglevel=restricted

# For very conservative tuning (not recommended for high-performance networks)
netsh interface tcp set global autotuninglevel=highlyrestricted

# Enable CUBIC congestion provider (Windows Server 2022/Windows 11+ only)
netsh interface tcp set supplemental template=Internet congestionprovider=cubic

# Note: Windows 10 and Server 2019 use Compound TCP or NewReno by default
# CUBIC is not available on these older versions

# Enable Receive-Side Scaling (RSS)
netsh interface tcp set global rss=enabled

# Set chimney offload (automatic is recommended)
netsh interface tcp set global chimney=automatic

# Disable NetDMA (recommended for modern systems)
netsh interface tcp set global netdma=disabled

# Enable Direct Cache Access (if supported)
netsh interface tcp set global dca=enabled

# Enable ECN (Explicit Congestion Notification)
netsh interface tcp set global ecncapability=enabled

# Set initial congestion window to 10 (RFC 6928)
netsh interface tcp set global initialRto=3000

Progresinta NIC Buffer Settings (per Device Manager aŭ PowerShell)

# View current adapter settings
Get-NetAdapterAdvancedProperty -Name "Ethernet"

# Increase receive buffers (adjust based on NIC)
Set-NetAdapterAdvancedProperty -Name "Ethernet" -DisplayName "Receive Buffers" -DisplayValue 2048

# Increase transmit buffers
Set-NetAdapterAdvancedProperty -Name "Ethernet" -DisplayName "Transmit Buffers" -DisplayValue 2048

# Enable Jumbo Frames (if network supports it)
Set-NetAdapterAdvancedProperty -Name "Ethernet" -DisplayName "Jumbo Packet" -DisplayValue 9014

# Enable Large Send Offload (LSO)
Set-NetAdapterAdvancedProperty -Name "Ethernet" -DisplayName "Large Send Offload V2 (IPv4)" -DisplayValue Enabled
Set-NetAdapterAdvancedProperty -Name "Ethernet" -DisplayName "Large Send Offload V2 (IPv6)" -DisplayValue Enabled

Registro Tweaks (Advanced - Uzo kun Caution)

# These settings are typically NOT needed on Windows 10/11 due to auto-tuning
# Only modify if auto-tuning is disabled or problematic

# Registry path: HKLM\System\CurrentControlSet\Services\Tcpip\Parameters

# Maximum TCP window size (if auto-tuning disabled)
# TcpWindowSize = 16777216 (16MB) - REG_DWORD

# Enable window scaling (enabled by default on modern Windows)
# Tcp1323Opts = 3 - REG_DWORD

# Number of TCP Timed Wait Delay
# TcpTimedWaitDelay = 30 - REG_DWORD (default 240)
Averto: Sur modernaj Fenestroj (10/11/Server 2019+), evitas manajn registromodifojn se aŭto-tunela kaŭzas temojn. La aŭto-tunadaj algoritmoj estas ĝenerale supraj al senmovaj valoroj.

MacOS Buffer Tuning

Heredaĵo makOS Settings (Circa 2009 - Mac OS X 10.5/10.6)

Parameter Legacy Value (2009) Description
kerno.ipc.maxsockbuf 262144 (256KB) Maksimuma toraka bufrograndeco
reto.inet.tcp.sendspace 32768 (32KB) Defaŭlta TCP sendas bufron
reto.inet.tcp.recvspace 32768 (32KB) Defaŭlta TCP ricevas bufron
reto.inet.tcp.autorcvbufmax 131072 (128KB) Maksimuma aŭtogordita ricevas bufron
reto.inet.tcp.autosndbufmax 131072 (128KB) Maksimuma aŭtogordita sendas bufron
reto.inet.tcp.rfc1323 0 (disabled) TCP fenestro skalanta

Nunaj makOS Settings (macOS 12-15 Monterey tra Sequoia)

Parameter Current Recommended Value Description
kern.ipc.maxsockbuf 8388608 (8MB) Maximum socket buffer size
net.inet.tcp.sendspace 131072 (128KB) Default TCP send buffer
net.inet.tcp.recvspace 131072 (128KB) Default TCP receive buffer
net.inet.tcp.autorcvbufmax 16777216 (16MB) Maximum auto-tuned receive buffer
net.inet.tcp.autosndbufmax 16777216 (16MB) Maximum auto-tuned send buffer
net.inet.tcp.rfc1323 1 (enirebla) Enable TCP fenestro skalanta
reto.inet.tcp.sack 1 (enabled) Enable Selective Acknowledgment
reto.inet.tcp.msdflt 1440 Defaŭlta TCP Maksimuma Segment Size
reto.inet.tcp.delayed ack 3 3 3 3 Dependita ACK-konduto

MacOS Konfiguracio

# Check current settings
sysctl kern.ipc.maxsockbuf
sysctl net.inet.tcp.sendspace
sysctl net.inet.tcp.recvspace
sysctl net.inet.tcp.autorcvbufmax
sysctl net.inet.tcp.autosndbufmax

# Apply settings temporarily (until reboot)
sudo sysctl -w kern.ipc.maxsockbuf=8388608
sudo sysctl -w net.inet.tcp.sendspace=131072
sudo sysctl -w net.inet.tcp.recvspace=131072
sudo sysctl -w net.inet.tcp.autorcvbufmax=16777216
sudo sysctl -w net.inet.tcp.autosndbufmax=16777216
sudo sysctl -w net.inet.tcp.rfc1323=1
sudo sysctl -w net.inet.tcp.sack=1

# Make settings persistent (create /etc/sysctl.conf)
sudo tee /etc/sysctl.conf <

Kreante LaunchDaemon por Persistent Settings

# Create /Library/LaunchDaemons/com.local.sysctl.plist
sudo tee /Library/LaunchDaemons/com.local.sysctl.plist <Labelcom.local.sysctlProgramArguments/usr/sbin/sysctl-wkern.ipc.maxsockbuf=8388608RunAtLoad
EOF

sudo chmod 644 /Library/LaunchDaemons/com.local.sysctl.plist
sudo launchctl load /Library/LaunchDaemons/com.local.sysctl.plist
Averto: MacOS Ventura (13) kaj poste havas System Integrity Protection (SIP) restriktojn. Kelkaj kernparametroj ne povas esti modifitaj eĉ kun sekso. Testvaloroj en via specifa medio.

Efikeco Testado kaj Validado

Iloj por Testado Buffer Performance

iperf3 - Network Performance Testing

# Server side
iperf3 -s

# Client side - test TCP throughput
iperf3 -c server_ip -t 60 -i 5 -w 16M

# Test with multiple parallel streams
iperf3 -c server_ip -P 10 -t 60

# Test UDP performance
iperf3 -c server_ip -u -b 1000M -t 60

Tcpdump - Kapti TCP Window Sizes

# Capture and display TCP window sizes
tcpdump -i any -n 'tcp' -vv | grep -i window

# Save capture for Wireshark analysis
tcpdump -i any -w /tmp/capture.pcap 'tcp port 443'

Wireshark Analysis

Vidu tiujn indikilojn de bufrotemoj:

  • TCP Zero Window mesaĝoj
  • TCP Window Update pakaĵetoj
  • TCP Window Plenaj sciigoj
  • Altaj redissendtarifoj kun malalta RTT

Sistemo Monitorado

# Linux - Monitor network buffer statistics
watch -n 1 'cat /proc/net/sockstat'
watch -n 1 'ss -tm | grep -i mem'

# Check for drops
netstat -s | grep -i drop

# Windows - Monitor TCP statistics
netstat -e 1

# macOS - Monitor network statistics
netstat -s -p tcp

Bandwidth-Delay Product (BDP) Kalkulo

Por determini optimumajn bufrograndecojn por via reto, kalkuli la Bandwidth-Delay Produkton:

BDP = Bandwidth (bits/sec) × RTT (seconds)

Example for 10 Gigabit Ethernet with 50ms RTT:
BDP = 10,000,000,000 × 0.050 = 500,000,000 bits = 62.5 MB

Buffer Size = BDP × 2 (for bidirectional traffic and headroom)
Buffer Size = 62.5 MB × 2 = 125 MB

This is why modern settings recommend 128MB maximum buffers.

Workload-Specific Recommendations

Workload Type Rekomendita Buffer Size Ŝlosilo Parametroj
Web Server (Low Latency) 4-16 MB Pli malaltaj bufroj, pli da ligoj, rapida respondo
Datuma Servilo 16-32 MB Moderaj bufroj, kongruaj traputitaj
Translokigo / Backup 64-128 MB Maksimumaj bufroj, alta trametita prioritato
Video Streaming 32-64 Grandaj bufroj, kohera liveraĵkurzo
HPC / Data Center 128-256 MB Maksimumaj bufroj, specialigita obstrukciĝkontrolo
Sendita / Mobile 2-8 MB Konservativulbufroj, varia latenteco pritraktanta

Oftaj eraroj kaj mortoj

Eraroj por eviti

  • Troa: Trofe grandaj bufroj povas kaŭzi bufrobloat, pliigante latentecon
  • Ignori memorlimojn: Grandaj bufroj multobliĝas per ligokalkulo; servilo kun 10,000 ligoj kaj 128MB bufroj bezonas 1.25TB de RAM
  • Senkaŭzanta aŭtogordado sen kialo: Moderna Os aŭto-tunado estas kutime pli bona ol senmovaj valoroj
  • Ne testante post ŝanĝoj: Ĉiam konfirmas spektakloplibonigojn kun realaj laborkvantoj
  • Forgesante NIC-bufrojn: Ringa bufrodepreno povas okazi sendepende de susaj bufroj
  • Inconsistent-valoroj: Kliento kaj servilo devus esti kongruaj bufrokonfiguracioj
  • Nestabiliga kontrolo: BBR kaj CUBIC estas signife pli bonaj ol pli malnovaj algoritmoj

Problemoj de laboro

  1. Establi bazlinion: Mezura aktuala efikeco kun iperf3 aŭ similaj iloj
  2. Kaptaŭloj: Uzu tcpdump/Wireshark identigi TCP-fenestrokonduton
  3. Kontrolu sistemstatistikojn: Vidu gutojn, bufrodeprenon, redissendojn
  4. Kalkuli BDP: Determini teorie optimumajn bufrograndecojn
  5. Pliaj ŝanĝoj: Ne ŝanĝu ĉion tuj
  6. Testo kaj valido: Mezurata fakta spektaklo plibonigo
  7. ekrano dum tempo: Certigi agordojn restas optimumaj sub ŝanĝiĝantaj ŝarĝoj

Pliaj informoj

  • RFC 1323 - TCP Etendaĵoj por Alta Efikeco (Window Scaling)
  • RFC 2018 - TCP Selective Acscialedgment Opcioj
  • RFC 6928 - La Komenca Fenestro de Kreskanta TCP
  • RFC 8312 - CUBIC Congestion Control Algorithm
  • BBR Congestion Control (Google) - https://research.google/pubs/pub45646/
  • Linukso Kernel Dokumentaro - interkonekta/ip-sctl.txt
  • Windows TCP/IP Performance Tuning Guide (Microsoft)
  • ESnet Network Tuning Guide - https://fasterdata.es.net/

Konludo

Buffer-degaso estas ofta radikkialo de spektaklotemoj kiuj ŝajnas esti ret-rilataj. Komprenante la evoluon de bufrosizing de 2009's 128KB-limoj ĝis 128MB kapabloj, retinĝenieroj povas rapide identigi kaj solvi tiujn temojn.

Ŝlosiloj:

  • Modernaj sistemoj bezonas signife pli grandajn bufrojn ol heredaĵo (2009) konfiguracioj
  • Ĉiam kalkulas BDP por viaj specifaj retkondiĉoj
  • Uzu Os aŭto-tunantajn ecojn kiam haveble (Windows, moderna Linukso)
  • Ekrano kaj testo por konfirmi ŝanĝojn
  • Pripensu laborkvanto-specifajn postulojn dum agordado

Memoro: "retoproblemo" rivelita per pakaĵanalizo por montri TCP nul fenestrojn estas fakte mastro sistemresursproblemo. Kun bonorda bufro agordado, vi povas elimini tiujn falsajn diagnozojn kaj realigi optimuman efikecon.


Lasta Ĝisdatigita: februaro 2, 2026

Aŭtoro: Baud9600 Technical Team