Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

having some trouble with php-fastcgi running slowly. keep getting 504 timeouts. any suggestions? Below are the nginx site config, top output, and error log:

server {

        listen 80;

location / {
                root   /var/www/example/htdocs;
                index  index.html index.htm index.php;

                # Joomla SEF section
                if ( !-e $request_filename ) {
                        rewrite (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ /index.php last;


location ~ \.php$ {
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /var/www/example/htdocs$fastcgi_script_name;
                include /etc/nginx/fastcgi_params;

location ~* ^.+\.(js|swf|css|jpg|jpeg|gif|png)$ {
                root /var/www/example/htdocs;
                expires 14d;

Here is the top command when the server is experiencing slowness:

top - 22:52:10 up 207 days, 21:24,  1 user,  load average: 2.25, 2.07, 2.05
Tasks: 126 total,   2 running, 124 sleeping,   0 stopped,   0 zombie
Cpu(s): 13.3%us, 11.2%sy,  0.0%ni, 49.6%id,  0.2%wa,  0.0%hi,  0.0%si, 25.8%st
Mem:   1639756k total,  1444380k used,   195376k free,   236768k buffers
Swap:  3145720k total,    18908k used,  3126812k free,   642228k cached

 PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                             
 702 mysql     20   0  350m  35m 5344 S   69  2.2  38:36.62 mysqld                                                                                               
 6659 www-data  20   0  197m  20m 3764 S   11  1.3   1:14.59 php-cgi                                                                                              
 6658 www-data  20   0  197m  19m 3776 S    7  1.2   1:06.68 php-cgi                                                                                              
 6660 www-data  20   0  199m  20m 4380 S    6  1.3   1:11.56 php-cgi                                                                                              
 6662 www-data  20   0  191m  14m 3732 S    4  0.9   1:08.79 php-cgi                                                                                              
 6661 www-data  20   0  197m  20m 3744 S    3  1.3   1:14.09 php-cgi

The nginx log shows a lot of these errors:

2011/01/25 09:06:37 [error] 13031#0: *850 upstream timed out (110: Connection timed out) while connecting to upstream, client:, server:, request: "GET /events/item/root/calendar_event HTTP/1.1", upstream: "fastcgi://", host: "", referrer: ""
share|improve this question

The problem is definitely related to the MySQL process being at about 70% CPU usage. The reason why you're getting errors in PHP/Nginx is that PHP will probably throw an error if the connection to MySQL takes too long.

One suggestion is to tune MySQL performance for this type of usage. A good diagnostic tool is mk-query-digest, which can help find bottlenecks in MySQL.

Another (and more simple) solution is to just upgrade the database server (or offload it to a separate server) so MySQL has more memory/disk-resources to work with.

share|improve this answer

Your Answer


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.