System Buffer Tuning - TCP and Network Performance Optimization
系統缓冲通訊:"網路問題"背后的隱藏罪惡
摘要
TCP 視窗或應用程式的性能被怪罪到網路基礎上。 在進行了广泛的包抓取、tcpdump和網路分析后,常被發現出真正的瓶颈: 在客戶端或伺服器系統上已耗盡的 NIC (Network Interface Card) 或 OS- 等級缓冲器.
這篇文章提供Linux、Windows和macOS的相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相關相相關相相相相相相關相關相相關相關相關相關相關相關相關相關相關相關相關相相相相相相相相
第 二 章
- TCP 包中零視窗事件
- 高再接送率,尽管接通的网位低
- 應用程式吞吐量相當于可提供寬度
- 在載入量下降后能改善的下載性能降解
- 相近相關相關相通相通的相通性能
- 套接字錯誤或「 暫時資源不可用」 訊息
二. 理解
TCP 視窗放大机制
TCP使用流控机制,由接收者做出"窗口大小"的廣告,表示能接受多少相關資料. 在系統缓冲器被填滿后, 這個視窗會收縮到零, 迫使發件人等待 。 它被看做是網路問題 但其實是主機資源問題
在缓冲相關的地方
- Socket 缓冲区 (SO SNDBUF/ SO RCVBUF): 相接相接相接相接
- TCP 視窗缓冲: 接通的最大 TCP 視窗大小
- 網路裝置缓冲 : 包排程的 NIC 環式缓冲器
- 全系统內存: 为建立網路而分取出的全部內存
诊断命令
Linux 诊断
# 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"
視窗诊断
# 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 诊断
# 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
Linux 缓冲通訊錄
遺傳 Linux 設定(2009 Circa)
| 參數 | 遗产价值(2009年) | 描述 |
|---|---|---|
| net. core.rmem default | 124928 (122KB) | 默认收受套接字缓冲大小 |
| 网易. core.rmem max | 131071 (128KB) | 最大接取套接字缓冲区大小 |
| net. core.wmem default | 124928 (122KB) | 預設 socket 缓冲区大小 |
| 网易. core.wmem max | 131071 (128KB) | 最大寄出套接字缓冲大小 |
| net.ipv4.tcp rmem (正末) | 4096 87380 174760 | TCP 接收缓冲: min, 預設值, 最大 (以字元為單位) |
| 網易. ipv4.tcp wmem | 4096 16384 131072 | TCP 傳出缓冲: min, 缺省, 最大 (以字元為單位) |
| net.ipv4.tcp mem | 196608 262144 393216 | TCP 有: 有: 有: 有: 有: 有: 有: 有: 有: 有: 有: 有: 有: 有: 有: 有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有:有: |
| net.core.netdev max 后端log | 1 000 | 在輸入列中最大包數 |
| net. core.optmem max (正數) | 第10240次(10KB) | 每套接字最大自動缓冲大小 |
目前 Linux 設定 (2025-2026)
| Parameter | 目前推荐值 | 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 接收缓冲:分, 缺省, 最大 (128MB 最大) |
| net.ipv4.tcp_wmem | 4096 65536 134217728 | TCP 傳出缓冲: min, 預設值, 最大 (128MB 最大) |
| net.ipv4.tcp_mem | 8388608 12582912 16777216 | TCP 內存頁面: 低, 有壓力, 有高 (64GB系統) |
| net.core.netdev_max_backlog | 250 000 | 在輸入列中最大包 (10GbE+) |
| net.core.optmem_max | 65536 (64KB) | Maximum ancillary buffer size per socket |
| net.ipv4.tcp 摄入 控制 | bbr (出自: | 使用 BBR 堵塞控制 (Google 算法) |
| net.ipv4.tcp 窗口 縮放 | 1 | 開啟 TCP 視窗縮放 (RFC 1323) |
| net.ipv4.tcp 時刻戳 | 1 | 为更好的 RTT 估計開啟 TCP 時間戳 |
| 網易. ipv4.tcp sack | 1 | 開啟選擇性的認證 |
| net.ipv4.tcp 無相量相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相 | 1 | 禁用 TCP 分量 |
Linux 設定應用程式
新增到這些設定值 /etc/sysctl.conf 或建立新檔案 /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 環向缓冲
# 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
- 相接回憶體 : 每個連接可以使用到 rmem max + wmem max (256MB 有128MB 缓冲区)
- 系統總衝擊: 1 000 接通 × 256MB = 256GB 可能使用
- 安全估計: 最大同時接通相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相相相相相接相相相相相相相相相相相相相接相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相
- 示例 64.GB 伺服器應把最大連接限制到 ~125 有128MB 相接高通量接通
- 关于使用 < 16GB RAM 的伺服器的建議: 將缓冲被降低到最大 16- 32MB并成正比地調整 tcp mem
視窗缓冲通訊錄
(Circa,2009-Windows Vista/7/Server,2008年)
| Parameter | Legacy Value (2009) | 位置 |
|---|---|---|
| 二相窗口大小 | 65535 (64KB) | 登記: HKLM\ system\ ControlSet\ services\Tcpip\相關公尺 |
| 三相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相 | 0 (残疾) | 在預設下視窗縮放已關閉 |
| 預設收取視窗 | 8192 (8KB) | 預設接收視窗 |
| 第 二 章 | 8192 (8KB) | 預設送出視窗 |
| GlobalMax-Tcp Window-Size (下同) | 65535 (64KB) | 最大 TCP 視窗大小 |
| 二相接 | 第16777214号决议 | 最大 TCP 連接 |
目前視窗設定 (Windows 10/11/Server 2019-2025)
現代視窗使用: 接收視窗自動突擊 特性,能被活性地調整出 根据網路條件得到的缓冲。
| 地貌 | 目前建議的設定 | Description |
|---|---|---|
| 自動突擊等級 | (或10GbE+的高實驗性) | 动态接收視窗調整 |
| 收視- Side 放大 (RSS) | 已啟用 | 在 CPU 中分佈網路處理 |
| 煙灰倒入 | 自動( 在現代NICs上被禁用) | TCP 卸入 NIC 硬件 |
| NetDMA | 已禁用 | 直接內存存取( 已耗盡) |
| TCP 全球參數 | 參觀下方的命令 | 全系统 TCP 設定 |
| 提供方 | CUBIC (或新雷諾倒轉) | TCP 堵塞控制算法 |
Windows 配置命令
# 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
高级 NIC 缓冲設定( 通过裝置管理器或 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
(已提高 -- -- 有注意地使用)
# 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)
macOS 缓冲通訊錄
(Circa,2009-Mac OS X 10.5/10.6)
| Parameter | Legacy Value (2009) | Description |
|---|---|---|
| (克克克所克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克 | 262144 (256KB) | 最大套接字缓冲大小 |
| net.inet.tcp.sendspace (已取消) | 32768 (32KB) | 默认 TCP 送出缓冲器 |
| 网易.inet.tcp.recvspace | 32768 (32KB) | 默认 TCP 接收缓冲器 |
| (克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克. | 131072 (128KB) | 最大自動調解收取缓冲 |
| (克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克克 | 131072 (128KB) | 最大自動調整傳出缓冲器 |
| 网易. | 0 (disabled) | TCP 視窗縮放 |
目前 macOS 設定 (macOS 12-15 Monterey 透過 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 (已啟用) | 開啟 TCP 視窗縮放 |
| 网易.inet.tcp.sack. | 1 (enabled) | Enable Selective Acknowledgment |
| (正末后出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出入出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出出 | 第1440起 | 預設 TCP 最大片段大小 |
| 已延后( A) | 三 | 延后ACK 行為 |
macOS 設定應用程式
# 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 <为持續設定建立啟動程序
# Create /Library/LaunchDaemons/com.local.sysctl.plist sudo tee /Library/LaunchDaemons/com.local.sysctl.plist <EOF sudo chmod 644 /Library/LaunchDaemons/com.local.sysctl.plist sudo launchctl load /Library/LaunchDaemons/com.local.sysctl.plist Label com.local.sysctl ProgramArguments /usr/sbin/sysctl -w kern.ipc.maxsockbuf=8388608 RunAtLoad 警告: 相當於相關地區相關地區, 有的內核參數可能無法被變更, 即使有 sudo 。 在您特定的環境中做測試設定 。
性能測試和驗證
測試缓冲性能的工具
iperf3 - 網路性能測試
# 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 - 抓取 TCP 視窗大小
# 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'
有線沙克分析
找找這些起缓冲作用的指標:
- TCP 零視窗訊息
- TCP 視窗更新包
- TCP 視窗完整通知
- 有低RTT的重傳率高
系統監控
# 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 產出 (BDP) 計算
为您決定網路的最佳缓冲大小, 計算 Bandwidth- Delay 產出:
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.
工作负荷 -- -- 有分別的建議
| 工作负荷型態 | 建議的缓冲大小 | 金鑰參數 |
|---|---|---|
| Web 伺服器 (Low latency) | 4-16 MB | 有更低的缓冲、更接通、更快回應 |
| 數據庫伺服器 | 16-32 MB | 中度缓冲器, 相容的吞吐量 |
| 檔案傳出/ 備份 | 64-128 MB | 最大缓冲区, 高通量优先级 |
| 有影片流出 | 32-64 MB | 有相通的交付率 |
| HPC / 資料中心 | 128-256 MB | 最大缓冲, 專用拥堵控制 |
| 有線/ 有通 | 二至八 MB | 保守的缓冲器,可變的暫時處理 |
二. 常见的錯誤和陷阱
避免出錯
- 过度阻塞: 有相當大的缓冲能造成缓冲,
- 忽略記憶力限制: 有一萬個接通和一 二八MB 的伺服器需要 1. 25TB 的 RAM
- 有原因地禁用自動調整 : 現代OS自動調整通常比靜態設定要好
- 在變更后不做測試 : 有活性能的改善
- 忘了NIC 缓冲: 環狀缓冲器可以被分解出 socket 缓冲器
- 不相容的設定 : 客戶端和伺服器應有相容的缓冲設定
- 忽略堵塞控制: BBR和CUBIC相當好于更古老的算法
二. 工作流程中出问题
- 确定基准: 以 iperf3 或相近的工具度量目前的性能
- 抓取包 : 使用 tcpdump/ Wireshark 以辨識 TCP 視窗行為
- 檢查系統數據: 尋找滴出、 缓冲耗盡和再傳送
- 計算 BDP : 二. 确定最理想的缓冲大小
- 套用增量變更 : 就不要一去不复返了
- 測試和驗證: 二. 衡量业绩改善
- 有時監控 : 在不同的荷載下确保設定保持最优化
參考和再讀
- RFC 1323 - TCP高性能延伸( Window 放大)
- RFC 2018 - TCP 有選擇的認可選擇
- RFC 6928 - 增加 TCP 初始窗口
- RFC 8312 - CUBIC 通量控制算法
- BBR 摄取控制 (Google) - https://research.google/pubs/pub45646/
- Linux克內爾文件- 網路/ ip- sysctl. txt
- Windows TCP/IP 性能調整指南 (微軟)
- Esnet網路通訊指南-https://fasterdata.es.net/
第 二 部 分
有相關的性能出問題, 網路工程師能迅速分辨并解決這些問題。
取出鑰匙:
- 相较於傳統(2009年),
- 就您所謂的網路條件計算 BDP
- 有需要就使用OS自動調整功能 (Windows, 現代 Linux)
- 監控和測試以驗證變更
- 在調整時要想出相關的工作需要
記住:由包分析所揭示出以顯示 TCP 零視窗的"網路問題"實際上是主機系統資源問題. 有相當的缓冲調音 就可去除這些錯誤的診斷并達到最佳的性能
最後更新: 2026年2月2日
作者: Baud9600 技術小組