Welcome! Log In Create A New Profile

Advanced

Nginx upstream unix socket keepalive?

Posted by Mayhem30 
Nginx upstream unix socket keepalive?
August 10, 2022 11:24PM
Do I need to add any additional configuration to enable keepalive to my PHP-FPM backend?

upstream php_backend {
zone upstreams 64K;
server unix:/var/run/php-fpm.sock max_fails=1 fail_timeout=2s;
keepalive 10;
}

# Pass off php requests to PHP-FPM
location ~* \.php {
try_files $uri =404;
access_log /var/log/php-fpm/example_access.log;
include /usr/local/etc/nginx/php-fpm.conf;
fastcgi_pass php_backend;
}

In the following Nginx guides, when you don't use unix sockets you must add :

proxy_http_version 1.1;
proxy_set_header "Connection" "";

Source :
https://www.nginx.com/blog/avoiding-top-10-nginx-configuration-mistakes/#no-keepalives https://www.nginx.com/blog/avoiding-top-10-nginx-configuration-mistakes/#upstream-groups

Is there any additional config I need to add when using a unix socket?
Re: Nginx upstream unix socket keepalive?
November 13, 2024 03:35PM
I still would like to know the answer on this question please?


When we are talking about PHP-fpm. Does setting fastcgi_keep_conn on; even make sense when using a unix socket file in fastcgi_pass?

Anybody? Does keepalive make sense or not?
Re: Nginx upstream unix socket keepalive?
November 15, 2024 05:52AM
Somebody executed a benchmark, which does show still improvements when using keepalive with PHP socket files:

Test case RPS Latency
TCP / fastcgi_keep_conn OFF / keepalive OFF 8791.1 ± 161.45 225µs ± 48µs
TCP / fastcgi_keep_conn ON / keepalive OFF 8514.02 ± 79.07 232µs ± 45µs
TCP / fastcgi_keep_conn ON / keepalive ON 10356.21 ± 115.86 190µs ± 51µs
Unix / fastcgi_keep_conn OFF / keepalive OFF 9571.68 ± 66.48 206µs ± 40µs
Unix / fastcgi_keep_conn ON / keepalive OFF 9376.97 ± 73.16 211µs ± 42µs
Unix / fastcgi_keep_conn ON / keepalive ON 10333 ± 155.5 191µs ± 65µs

With the following additional information:

- Unix sockets are generally a bit faster than TCP sockets.
- Enabling fastcgi_keep_conn and keepalive provides a measurable performance boost.
- This improvement is more noticeable with TCP sockets than with Unix sockets.

See: https://github.com/yegor-usoltsev/nginx-upstream-keepalive/issues/1
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 199
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready