Loading

[nginx]sendfile + tcp_nopush + tcp_nodelay 开启高效的文件传输模式

NGINX官方文档 sendfile
NGINX官方文档 tcp_nopush
NGINX官方文档 tcp_nodelay
image

image
image

#开启sendfile
sendfile off;
#开启tcp_nopush
tcp_nopush on;
#开启tcp_nodelay
tcp_nodelay on;
  • tcp_nopush会先将数据缓存到缓存区,存满后发送,主要用来提升网络包的传输效率,仅在sendfile开启时有效
  • tcp_nodelay仅在keepalive状态下才能生效,有数据就发送

tcp_nopush和tcp_nodelay看起来是互斥的,一个是缓存后发送,一个是有数据就发送。但是在linux2.5.9以后这两者可以兼容.以下截图自黑马程序员笔记
image

以下是使用sendfile与否的处理流程区别(摘自黑马程序员nginx笔记)
image

posted @ 2022-06-26 22:36  丘丘CRUD  阅读(832)  评论(0)    收藏  举报