Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!!

share|improve this question
    
Call me a fool, but I can't imagine nginx being a bottleneck (vs PHP that is) –  Justin T. Jun 12 '12 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. –  Peter Sorenson Jun 12 '12 at 17:41
add comment

3 Answers 3

up vote 0 down vote accepted

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)
share|improve this answer
add comment

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.

share|improve this answer
    
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. –  Peter Sorenson Jun 13 '12 at 6:43
add comment
  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.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.