Welcome! Log In Create A New Profile

Advanced

Re: keepalive connection to fastcgi backend hangs

Maxim Dounin
December 20, 2021 09:12AM
Hello!

On Sun, Dec 19, 2021 at 07:56:51PM +0000, Nicolas Franck wrote:

> In order to make nginx keep the tcp connections alive,
> I've added the following settings:
>
> * proxy_socket_keepalive on
> * proxy_http_version 1.1;
> * proxy_set_header Connection "";

Just a side note: you don't need any of these to keep FastCGI
connections alive.

> * fastcgi_keep_conn on;
> * added an upstream "fgi":
>
> upstream fcgi {
> keepalive 10;
> server myhost:9000;
> }
>
> * added a location block (only snippet given):
>
> location /fcgi {
> fastcgi_pass_request_headers on;
> fastcgi_pass fcgi;
> fastcgi_keep_conn on;
> }
>
> What I see: after a couple of requests nginx "hangs" when I
> visit path "/fcgi".
>
> This disappears when
>
> * I remove the setting "keepalive" from the upstream (but that
> disables keepalive altogether)
> * bind the fcgi application to a unix socket, and let nginx bind
> to that. But that requires nginx and the fcgi to be on the same
> server.
> * reduce the number of nginx workers to exactly 1. Not sure why
> that works.
> * I spawn the application with tool "supervisord" (a fcgi
> process manager written in python)
>
> Does anyone know what is happening here?
> Fcgi has little documentation on the web..

[...]

> Spawn: spawn-fcgi -f /path/to/fcgi_example.cpp -p 9000

The spawn-fcgi defaults to 1 child process, and each child process
can handle just one connection. On the other hand, your
configuration instruct nginx to cache up to 10 connections per
nginx process.

As long as the only one connection your upstream server can handle
is cached in another nginx process, nginx won't be able able to
reach the upstream server, and will return 504 Gateway Timeout
error once the fastcgi_connect_timeout expires (60s by default).
Likely this is something you see as "hangs".

Obvious fix would be to add additional fastcgi processes. Given
"keepalive 10;" in nginx configuration, you'll need at least 10 *
<number of nginx worker processes>. Something like:

spawn-fcgi -F 20 -f /path/to/fcgi -p 9000

should fix things for up to 2 nginx worker processes.

Just in case, that's exactly the problem upstream keepalive
documentation warns about (http://nginx.org/r/keepalive): "The
connections parameter should be set to a number small enough to
let upstream servers process new incoming connections as well".

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

keepalive connection to fastcgi backend hangs

Nicolas Franck December 19, 2021 02:58PM

Re: keepalive connection to fastcgi backend hangs

Maxim Dounin December 20, 2021 09:12AM

Re: keepalive connection to fastcgi backend hangs

Nicolas Franck December 20, 2021 11:02AM

Re: keepalive connection to fastcgi backend hangs

Maxim Dounin December 20, 2021 02:36PM

Re: keepalive connection to fastcgi backend hangs

Nicolas Franck December 20, 2021 03:56PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 293
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready