简体   繁体   English

Nginx,sendfile和FastCGI

[英]Nginx, sendfile and FastCGI

If nginx is only configured to forward requests to a FastCGI backend (Mono, PHP etc), without any file based caching involved, would the use of sendfile on in nginx.conf bring any performance improvements? 如果nginx仅配置为将请求转发到FastCGI后端(Mono,PHP等),而没有涉及任何基于文件的缓存,那么在nginx.conf中使用sendfile on是否会带来任何性能改进?

Example nginx.conf: 示例nginx.conf:

worker_processes  1;
daemon off;

events {
    worker_connections  1024;
    use epoll;
}

http {
    sendfile        on; # <-- ???
    tcp_nopush      on;
    tcp_nodelay     on;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   /usr/aspnet/;
            fastcgi_pass 127.0.0.1:9000;
            include /etc/nginx/nginx-fastcgi-params.conf;
        }
    }
}

From the Sendfile man pages : Sendfile手册页

ssize_t sendfile(int out_fd, int in_fd, off_t * offset ", size_t" " count" ); ssize_t sendfile(int out_fd,int in_fd,off_t *偏移量“,size_t”“ count”);
.... ....
The in_fd argument must correspond to a file which supports mmap(2)-like operations (ie, it cannot be a socket). in_fd参数必须与支持类似mmap(2)的操作的文件相对应(即,它不能是套接字)。

In other words, enabling sendfile won't make any difference unless nginx is reading from something which can be mapped into the virtual memory space like a file. 换句话说,启用sendfile不会有任何区别,除非nginx正在读取可以映射到虚拟内存空间(例如文件)的内容。 So it won't make any difference to performance with fastcgi_pass. 因此,使用fastcgi_pass不会对性能产生任何影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM