不懂就要问,请教大神一个 NGINX 的问题。

2019-06-18 09:48:07 +08:00
 VIPID

看到一些 NGINX 安装教程中有以下操作:
编译参数添加 --with-cc-opt=-DTCP_FASTOPEN=23
然后配置文件监听端口后面添加 fastopen=3 reuseport
我想知道:
1.这是干什么的,能带来哪些好处?
2.等号后面的数字,代表什么意思,是否还有其他值可选?

1646 次点击
所在节点    程序员
1 条回复
CivAx
2019-06-18 11:06:56 +08:00
tcp_fastopen 是在 CentOS 3.10 (是不是啊,我不太记得具体版本了,我在用 5.1 )上被支持的特性

具体干啥的可用自己查,大致来说就是我们俩握过手 py 过,下次见面就不用再握了,直接 py。这个主要依靠 cookies 判断(需要客户端、服务端、程序一并支持)

--with-cc-opt 代表在构建时自定义一个额外参数,然后在构建时传给 C 编译器
[值得收藏: https://www.ttl178.com/thread-13-1-2.html]

-D TCP_FASTOPEN 是启用 TCP_FastOpen,并使用选项 2 和 3。实际上通常是用 2,3 代表 1+2 ;要么 2,要么 3

关于 FastOpen:
tcp_fastopen - INTEGER
Enable TCP Fast Open feature (draft-ietf-tcpm-fastopen) to send data in the opening SYN packet. To use this feature, the client application must use sendmsg() or sendto() with MSG_FASTOPEN flag rather than connect() to perform a TCP handshake automatically.

The values (bitmap) are
1: Enables sending data in the opening SYN on the client w/ MSG_FASTOPEN.
丨 允许在已建立的 SYN 链接中使用 MSG_FastOpen [发送]数据
2: Enables TCP Fast Open on the server side, i.e., allowing data in a SYN packet to be accepted and passed to the application before 3-way hand shake finishes.
丨 允许服务器端使用 TCP FastOpen,意思是说允许在三次握手完成前就开始[接收] SYN 包中的数据(这就是 FastOpen 的意义,类似于总开关,想用就必开)
4: Send data in the opening SYN regardless of cookie availability and without a cookie option.
丨 无论是否存在 cookies,都允许向任何未校验的 SYN 链接[发送]数据
0x100: Accept SYN data w/o validating the cookie.
丨 不验证 Cookies,[接收]任何 SYN 数据
0x200: Accept data-in-SYN w/o any cookie option present.
丨 接受没有任何 cookie 选项的 SYN-in-SYN 数据
0x400/0x800: Enable Fast Open on all listeners regardless of the TCP_FASTOPEN socket option. The two different flags esignate two different ways of setting max_qlen without the TCP_FASTOPEN socket option.
丨 看不懂

Default: 1

Note that the client & server side Fast Open flags (1 and 2 respectively) must be also enabled before the rest of flags can take effect.

See include/net/tcp.h and the code for more details.

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/574963

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX