Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Tue May 12, 2009 11:30 am 
Offline
Newbie

Joined: Thu May 07, 2009 11:50 pm
Posts: 4
Website: http://zetacentauri.com
Location: Portland, OR
I have my Linode 360 set up to run Nginx and PHP FastCGI. I have around a dozen low-traffic Drupal sites and the total memory usage usually sits at around 160MB.

For the most part it's very fast and responsive. However, around every 10th page load or so I seem to be getting a 504 timeout. Since there's not much load on the server I have to imagine I have something less-than-optimal in my configuration, like maybe too many/not enough processes or some buffer size setting being out of order.

Here's my Nginx config:

Code:
user www-data;
worker_processes  2;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    server_names_hash_bucket_size 128;

    access_log  /var/log/nginx/access.log;

    sendfile        on;
    tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;

    gzip  on;
    gzip_comp_level 5;
    gzip_http_version 1.0;
    gzip_min_length 0;
    gzip_types text/plain text/html text/css image/x-icon application/x-javascript;
    gzip_vary on;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}


A typical site config for Nginx is like this:

Code:
server {
        listen 80;
        server_name www.findmud.com;
        rewrite ^/(.*) http://findmud.com/$1 permanent;
        }

server {
        listen 80;
        server_name findmud.com;
        access_log /home/zeta/public_html/findmud.com/log/access.log;
        error_log /home/zeta/public_html/findmud.com/log/error.log;

        location / {
            root /home/zeta/public_html/findmud.com/public;
            index index.php index.html index.htm;
            if (!-e $request_filename) {
                rewrite ^/(.*)$ /index.php?q=$1 last;
            }
        }

        location ~ .php$ {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /home/zeta/public_html/findmud.com/public$fastcgi_script_name;
                include /etc/nginx/fastcgi.conf;
                fastcgi_param QUERY_STRING $query_string;
                fastcgi_param REQUEST_METHOD $request_method;
                fastcgi_param CONTENT_TYPE $content_type;
                fastcgi_param CONTENT_LENGTH $content_length;
        }

        location ~* ^.(jpg|jpeg|gif|css|png|js|ico|pdf|zip|exe)$ {
            access_log off;
            expires 30d;
        }

}


Here's my PHP FastCGI config:
Code:
START=yes
EXEC_AS_USER=(not shown)
FCGI_HOST=localhost
FCGI_PORT=9000
PHP_FCGI_CHILDREN=1
PHP_FCGI_MAX_REQUESTS=1000


PHP memory limit is set at 48M, but I never really get below 180M free on the server so I'm obviously not running out of RAM.

What can I do to reduce the likelihood of a gateway timeout? If there are any other config files I should post please let me know.


Top
   
PostPosted: Tue May 12, 2009 1:24 pm 
Offline
Senior Member

Joined: Thu Apr 03, 2008 12:02 am
Posts: 103
AOL: derole
Xangis wrote:
Here's my PHP FastCGI config:
Code:
...
PHP_FCGI_CHILDREN=1
...




you only have one php process to serve php pages. i'd try at least as many as you have nginx processes (= 2)
see if that helps


Top
   
 Post subject:
PostPosted: Tue May 12, 2009 1:35 pm 
Offline
Newbie

Joined: Thu May 07, 2009 11:50 pm
Posts: 4
Website: http://zetacentauri.com
Location: Portland, OR
Thank you for the tip, I knew it'd be something obvious to someone who wasn't me.

As a general rule of thumb should children be equal the the number of Nginx-es, or is it OK to go higher (i.e. 4 or 8 if I have the extra RAM lying around)?


Top
   
 Post subject:
PostPosted: Tue May 12, 2009 1:53 pm 
Offline
Senior Member

Joined: Thu Apr 03, 2008 12:02 am
Posts: 103
AOL: derole
i'd run more nginx processes than php processes as not every http request needs php processing.
i run about 10 nginx worker instances and maybe 6 or 8 php instances, works pretty well.


Top
   
 Post subject:
PostPosted: Wed May 13, 2009 8:37 am 
Offline
Junior Member

Joined: Tue Jan 01, 2008 4:28 am
Posts: 32
oliver wrote:
i'd run more nginx processes than php processes as not every http request needs php processing.
i run about 10 nginx worker instances and maybe 6 or 8 php instances, works pretty well.


You are thinking in terms of Apache prefork MPM, where each process can only serve one request at a time.

Nginx uses async-based IO and can handle a lot more connections on a single process. I have a Linode 720 running a moderate sized Drupal site (around 2.5 million page views/70 million HTTP requests a month). With HTTP 1.1 keep alive at 15 second, currently it has 189 connections hanging onto it. It runs on 5x PHP/FastCGI process and... 1 single Nginx worker process.

Since Nginx is not blocking on IO, you don't need to have more than one process unless it's exhausting one single CPU core.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group