0
点赞
收藏
分享

微信扫一扫

Nginx基础篇(16)文件读取模块

巧乐兹_d41f 2022-06-06 阅读 126

统称:ngx_http_core_module

语法:

Syntax:   sendfile on | off;
Default: sendfile on;
Context: http, server, location, if in location
Syntax:   tcp_nopush on | off;
Default: tcp_nopush off;
Context: http, server, location
Syntax:   tcp_nodelay on | off;
Default: tcp_nodelay on;
Context: http, server, location

原理:

sendfile

未使用sendfile() 的传统网络传输过程:

硬盘 >> kernel buffer >> user buffer>> kernel socket buffer >>协议栈

使用 sendfile() 来进行网络传输的过程:

硬盘 >> kernel buffer (快速拷贝到kernelsocket buffer) >>协议栈

sendfile() 不但能减少切换次数而且还能减少拷贝次数。


tcp_nopush

未使用tcp_nopush()网络资源浪费:

​应用程序每产生一次操作就会发送一个包,而典型情况下一个包会拥有一个字节的数据以及40个字节长的包头,于是产生4000%的过载,很轻易地就能令网络发生拥塞。同时也浪费资源

使用tcp_nopush()网络传输效率提升:

当包累计到一定大小后再发送。


tcp_nodelay

​​开启或关闭nginx使用TCP_NODELAY选项的功能。 这个选项仅在将连接转变为长连接的时候才被启用。

TCP_NODELAY是禁用Nagle算法,即数据包立即发送出去。

由于Nagle和DelayedACK的原因,数据包的确认信息需要积攒到两个时才发送,长连接情况下,奇数包会造成延时40ms,所以tcp_nodelay会将ack立刻发出去。 如果不在长连接时,可以关闭此模块,因为ack会被立刻发出去。

启用模块

http {
location /video/ {
sendfile on;
tcp_nopush on;
}
}
举报

相关推荐

0 条评论