1

I run a website with a lot of traffic. I'm using nginx and php fast-cgi. However, when loading simple php documents in the browser, it takes up to 5-6 seconds before the page is loaded. Sometimes it even just results in a "404 not found" nginx error.

When using "htop" on debian, I am nowhere near using the ressources of my server. So what's going on? Is it nginx? Is it PHP-fast-cgi? I can't tell where the bottle neck is.

A snippet of my nginx config:

user  www-data www-data;
worker_processes  2;

events {
    worker_connections  4048;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  10;
    include /usr/local/nginx/sites-enabled/*;
...
}

A snippet of my fast-cgi config:

EXEC_AS_USER=www-data

# Host and TCP port for FASTCGI-Listener (default: localhost:9000)

FCGI_HOST=localhost
FCGI_PORT=9000

# Environment variables, which are processed by PHP

PHP_FCGI_CHILDREN=8
PHP_FCGI_MAX_REQUESTS=0

Thank you very much!!

2
  • Call me a fool, but I can't imagine nginx being a bottleneck (vs PHP that is)
    – Justin T.
    Jun 12, 2012 at 17:16
  • I'd agree. But can you spot anything in my PHP configuration that might be bottlenecking the server? I have not been able to really find any information online. Jun 12, 2012 at 17:41

3 Answers 3

0

How much is a lot traffic? Just a few tips:

  • use cache as much as possible
  • the number of worker processes could be equal to number of CPU cores
  • close live connections as early as possible or disable them completely (try let's say keepalive_timeout 5)
  • each connection needs a filehandle worker_rlimit_nofile 20000;
  • total amount of users you can serve in 1 second (approximately) = worker_processes * worker_connections/ (keepalive_timeout * 2)
  • disable access logs unless you really need them
  • use a balancer (if it's not feasible with one server)
1

Quiet the server, put strace on all the php and nginx processes, try a request and watch where it waits.

Alternatively, look for a profiling tool for php and gather some data with it.

1
  • OK. Thanks, I will try that later today. But how does my configuration look? It seems that nobody really knows what the optimal config should be for either nginx or fast-cgi. Jun 13, 2012 at 6:43
0
  1. Try to configure FastCGI as unix socket and not internet socket. This would save you in some cases up to 20% of time spent.
  2. You can push your worker_processes higher up to number of available cores.
  3. Check your php-fpm config as it has enough options to:
    • kill very long running requests;
    • report about long running request.
  4. Change PHP_FCGI_MAX_REQUESTS to something relevant like 1000. Just for the case of memory corruption.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .