大网数据广告活动
服务器运维问答

How to adjust TCP Window Size?

· 52CE 我爱测

I asked a similar question before, but I believe I was not clear with the details. I'm basically having some problems with my server related to high latency between the server and the clients due to the geographical distance. And…

问题原文

原帖链接 · Efe Zaladin · CC BY-SA 4.0

I asked a similar question before, but I believe I was not clear with the details.

I'm basically having some problems with my server related to high latency between the server and the clients due to the geographical distance. And making a research, it turned out that I can solve this issue by increasing the TCP Window Size.

The problem is I don't really know how to do it, and following the instructions I found on the web didn't help at all.

So I'm hoping that someone can share some documentation / commands / instructions or anything that can further improve this question.

Here is some info:

  • OS: Ubuntu 20.04 (LTS) x64
  • Server: Apache/2.4.41
  • Application Type: Python - Flask
  • Hosting Company: Digital Ocean

Edit: After several replies telling me that adjusting the Window Size won't solve the problem, I think I was not clear enough.

Please refer to this answer before telling me that changing the Window Size won't work. https://networkengineering.stackexchange.com/a/2297/71565

If you believe that I misunderstood the answer in the link above, please tell me what in particular I'm getting wrong and don't just share a cryptic reply of "it won't work" etc.

已采纳解答

原帖链接 · shodanshok · CC BY-SA 4.0

I'm not 100% convinced your issue is really window-size related. Still, below you can find the relevant info.

The base window size can not exceed 65535 bytes due to limitations of the TCP header. From RFC 1323:

The TCP header uses a 16 bit field to report the receive window size to the sender. Therefore, the largest window that can be used is 2**16 = 65K bytes.

This does not means the TCP window can't be bigger, as modern OSes support (and advertise by default) TCP Window Scaling, where the window size is dynamically increased via scaling by up to 14X factor. However, an upper limit can be configured before hitting maximum scaling.

For reference, these are the relevant parameters (and their defaults) on Ubuntu 20.04:

net.ipv4.tcp_window_scaling = 1         ;scaling enabled
net.ipv4.tcp_rmem = 4096 131072 6291456 ;min, default and max receive window
net.ipv4.tcp_wmem = 4096  16384 4194304 ;min, default and max send window
net.core.rmem_max = 212992              ;max absolute limit for receive buffer
net.core.wmem_max = 212992              ;max absolute limit for send buffer

The actual maximum window size is the smaller between [r|w]mem_max and the third value of tcp_[r|w]mem. So on Ubuntu 20.04 you have an actual max receive and send window of 212992 bytes by default. To increase that limit to 4 MB you can do the following:

sysctl -w net.core.rmem_max=4194304
sysctl -w net.core.wmem_max=4194304

If it works, you can persist the settings by editing /etc/sysctl.conf

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-10-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。