Anyone using nginx and know how to fix 504 gateway timeout issues?

1,583 views
Skip to first unread message

katz

unread,
Sep 15, 2009, 2:29:28 AM9/15/09
to ruby...@googlegroups.com
Hello, I've been working on a project which is nearly complete and we're launching site in 2 weeks.
Problem is the server setup. I have followed Slicehost articles on nginx, mongrel_cluster ...

http://articles.slicehost.com/2009/2/27/ubuntu-intrepid-installing-nginx-via-aptitude
http://articles.slicehost.com/2009/2/27/ubuntu-intrepid-mongrel-and-mongrel-cluster
http://articles.slicehost.com/2009/3/11/ubuntu-intrepid-nginx-rails-and-mongrels

on my nginx conf file, I changed the values of the following:
worker_processes  4;
keepalive_timeout  5;
tcp_nodelay        off;

The error we always get is 504 gateway timeout whether those values are changed or not.
If I use Apache2, I have a feeling site will be 2x slower.

Also another issue which is major is the speed - very slow. I am trying to optimize certain pages but I do not think I can optimize those with flash elements.
Any help on this?
Would greatly appreciate any help on the issue. I'm really not much of a server admin. Have focused more on design in the past.


Kates Gasis

unread,
Sep 15, 2009, 2:36:27 AM9/15/09
to ruby...@googlegroups.com
found this in the passenger list.
http://groups.google.com/group/phusion-passenger/browse_thread/thread/2ce11bef1fa7032d

send_timeout 300;
proxy_read_timeout 300;

Katherine

unread,
Sep 15, 2009, 3:41:12 AM9/15/09
to Philippine Ruby Users Group (PRUG/PhRUG)
Thanks...
Hope it would fix the issue.
I am no longer using passenger. I was not aware of the cause of the
timeouts. Also saw nothing on error log.

On Sep 15, 2:36 pm, Kates Gasis <katesga...@gmail.com> wrote:
> found this in the passenger list.http://groups.google.com/group/phusion-passenger/browse_thread/thread...
>
> send_timeout 300;
> proxy_read_timeout 300;

Jason Torres

unread,
Sep 15, 2009, 3:45:58 AM9/15/09
to ruby...@googlegroups.com
There's more to change than configs. Timeouts usually really happens when there's long processes running making your passenger workers very busy, and the requests keeps piling up. If you feel there isnt much visitors yet (since it isn't live yet) and it's timing out, go for code optimizations first. Spending a great deal on caching, and site optimization would do, optimizing your DB and indices would help a lot also first, do that right before deciding on adding more servers. Also, if you're on a 256mb/512mb slice going on production, I suggest getting one higher before going live.

J
--
Jason Torres
http://twitter.com/jasontorres
+63-91750-JASON
Samuel Goldwyn  - "I'm willing to admit that I may not always be right, but I am never wrong."

Kates Gasis

unread,
Sep 15, 2009, 4:01:50 AM9/15/09
to ruby...@googlegroups.com
another thing to watch out when proxying to mongrels is that when the
mongrel dies or restarted, it loses the connection to your webserver.
a nagios script to hit your app once in a while helps and when the
mongrel dies, we usually restart everthing including httpd or nginx.

Katherine

unread,
Sep 15, 2009, 4:11:35 AM9/15/09
to Philippine Ruby Users Group (PRUG/PhRUG)
I've added index on all tables. I always do create index on foreign
keys.
Optimization code - none written. Can't do page cache - only fragment
cache.
Not sure about memcached - I think that only helps for social
networking projects, am I right?
This is just an informational & e-commerce site.

Hmmm.. we moved from Linode to Slicehost. Noticed site on Linode was
faster. Same settings - Nginx and mongrel..
higher than 512 MB is a lot.
Oh well, they'll pay for it anyway.. :D

Jason Torres

unread,
Sep 15, 2009, 4:23:10 AM9/15/09
to ruby...@googlegroups.com
512MB for a production app is small, suggest going for 1GB+ or even more
--
Jason Torres
http://twitter.com/jasontorres
+63-91750-JASON
Charles de Gaulle  - "The better I get to know men, the more I find myself loving dogs."

katz

unread,
Sep 15, 2009, 1:50:26 PM9/15/09
to ruby...@googlegroups.com
We're going for Linode 720 for now. Staging for 2 weeks.
I monitored server, we're using 80% of available memory... sucks. I think one reason is it's Ubuntu Jaunty 64-bit and not 32-bit.
Slicehost does not offer 32-bit.

katz

unread,
Sep 15, 2009, 10:04:32 PM9/15/09
to ruby...@googlegroups.com
katz wrote:
We're going for Linode 720 for now. Staging for 2 weeks.
I monitored server, we're using 80% of available memory... sucks. I think one reason is it's Ubuntu Jaunty 64-bit and not 32-bit.
Slicehost does not offer 32-bit.
Wrong it's more like 13% at an average. But I am not sure what is the cause of timeouts.
>From Passenger, I moved to using Mongrels which seems like a bad idea.
Now I get this exception error:
A Mongrel::TimeoutError occurred in application#index:

  Mongrel timed out this thread: shutdown
  /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:221:in `rescue_action_without_handler'
This happens when they upload an image. I use the new rails feature - accepts_nested_attributes_for.
And allowed client to upload 3 photos at a time.. Some timeout issues apparently.
Anyway thanks all.
Think I'm gonna rebuild later this week after debugging some issues and use this: http://github.com/mbailey/deprec/

Jason Torres

unread,
Sep 15, 2009, 10:19:25 PM9/15/09
to ruby...@googlegroups.com
looks like your machine is. I don't think it's accepts_nested_attributes_for also,

Imagemagick might be,  How many mongrels are you using? see if 1 mongrel has an average of 200MB+ per instance, then your server will be full always, there isn't much enough for other processes to run like imagemagick, also if considering mysql is running on the same machine. I seriously suggest going back to passengers since mongrels are more harder to maintain.

It's really either you keep on optimizing code, go for caching and queues OR really.... Go get a big server hehehe.
--
Jason Torres
http://twitter.com/jasontorres
+63-91750-JASON
Joan Crawford  - "I, Joan Crawford, I believe in the dollar. Everything I earn, I spend."

katz

unread,
Sep 16, 2009, 12:01:12 AM9/16/09
to ruby...@googlegroups.com
Jason Torres wrote:
looks like your machine is. I don't think it's accepts_nested_attributes_for also,

Imagemagick might be,  How many mongrels are you using? see if 1 mongrel has an average of 200MB+ per instance, then your server will be full always, there isn't much enough for other processes to run like imagemagick, also if considering mysql is running on the same machine. I seriously suggest going back to passengers since mongrels are more harder to maintain.

It's really either you keep on optimizing code, go for caching and queues OR really.... Go get a big server hehehe.
LOL. Kaya pala. 2 mongrels and not enough RAM.
On a big server, yeah.. mayaman dapat clients kung Rails ang gagamitin LOL. I tried Sinatra recently. Ok naman sa memory.
Gonna try deprec tomorrow and set up on Linode server. Maybe it won't fail on 32-bit Ubuntu Jaunty, 720MB RAM.  We're not expecting too many visitors yet so I think that's OK.

Kates Gasis

unread,
Sep 16, 2009, 12:14:47 AM9/16/09
to ruby...@googlegroups.com
have you tried using unicorn instead of mongrel? i've read good things
about it. we just moved to nginx-passenger so no way for me to try
nginx-unicorn combo on production.

katz

unread,
Sep 16, 2009, 3:49:07 AM9/16/09
to ruby...@googlegroups.com
Kates Gasis wrote:
have you tried using unicorn instead of mongrel? i've read good things
about it. we just moved to nginx-passenger so no way for me to try
nginx-unicorn combo on production.
  
No. I haven't ... just had a chat with the Australian developer who's also helping me with the server issues. He said unicorn sounds pretty solid.
Since I've got like one week to finalize some features, we decided to try using one mongrel instead of two. It seems to work. But very temporary fix.
Probably late next week I will try deprec - Ruby 1.8.7, Nginx, Mongrel on a larger server.
Passenger is slow.. I noticed it's a bit slow compared to using Mongrel.
Reply all
Reply to author
Forward
0 new messages