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.

PHP running too slow, always showing "504 Gateway Time-out"

My server spec:
Dual core ATOM 330 CPU
2GB RAM
Use nginx with PHP in fastcgi
use eaccelerator

CPU 74.3%id
RAM used: 350MB of 2GB

I have lots of sites in my server, with cron running every minutes all time, even on some minutes, double or triple cron running at same time.

All my sites cron is heavy, usually the cron running more than one minutes.

my nginx.conf has become too big until nginx refuse to start because too many sites in it. it has been solved by increasing server_names_hash_max_size. Im planning to add more sites in my server

Now, opening my website always showing 504 Gateway Time-out. I have tested many eaccelerator and PHP setting, but this 504 Gateway Time-out still happen.

the 504 Gateway Time-out will dissappeared when cron is disabled

I have no idea: is this because not enough processor power?

And what should I do? upgrade my processor?

--------added

this is top for my CPU just now:

Cpu(s): 17.5%us,  3.8%sy,  0.1%ni, 71.6%id,  6.9%wa,  0.1%hi,  0.1%si,  0.0%st
share|improve this question
add comment

2 Answers

That error is nginx telling you that PHP is timing out.

To determine what's wrong we'd need to look at what that PHP code is actually doing.

If the error is strongly correlated with the cron jobs, and I'm assuming that those cron jobs are running PHP scripts and/or competing for the same resources that your regular PHP code uses (maybe a DB or something) - then you should start looking for contention at that point.

Something is causing your PHP sessions to not complete their code and hang - focus on that and you'll find your answer. (Also - set up graceful error pages for that situation - I think nginx lets you do that!)

share|improve this answer
add comment

And what should I do? upgrade my processor?

Clearly not - from your stat, your processor is sitting around 75% idle, so that's most likely not the problem.

Have you looked at your IO usage? I'd put money on the guess that your processes are having to wait for IO and as such, are taking much longer than they normally would.

Run top and watch the %wa item in the CPU usage row. Here's example output from one of my servers:

Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st

If that %wa value is higher than say 20% or so, that's most likely your problem.

share|improve this answer
    
the top for my CPU has been added above –  komase Sep 14 '10 at 3:31
add comment

Your Answer

 
discard

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