unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* Unicorn vs Apache
@ 2011-07-11 16:07 Matt Smith
  2011-07-11 16:50 ` Steve Klabnik
  2011-07-11 18:45 ` Eric Wong
  0 siblings, 2 replies; 7+ messages in thread
From: Matt Smith @ 2011-07-11 16:07 UTC (permalink / raw)
  To: mongrel-unicorn

Hello all,

I have always deploys rails apps with unicorn and nginx as a reverse
proxy in the past. However, I am working with a new firm and they would
like to use Apache with mod_pagespeed in front of unicorn.

We will be deploying a rails 3.1 app with streaming. To me,
mod_pagespeed does not seem like a magic bullet, as it appears to be a
collection of best practices which have to be rewritten as a page is
being served. Why not code with the best practices in mind as to not
have to scan and yet again reprocess the content?

Searching on the web, I find few entries about mod_page speed and rails,
and relatively few entries about apache with unicorn.

To me it seems that using best practices, with appropriate use of
caching, and nginx would be a better solution than apache with
mod_pagespeed.

Questions:

1) Does nginx provide any necessary services to unicorn, that apache
cannot provide?

2) If apache can provide all necessary services, does it do them as well
as nginx.

3) We would like the fastest user experience possible. Does apache with
mod_pagespeed hold any weight here over nginx?

4) Part of a fast user experience is how fast you get the page, correct?
Seems like nginx has the upper hand here, due to nginx's nio vs apache's
threading.

5) Would it make since to put nginx in front of apache w/mod_pagespeed
(or visa versa), to use the applicable mod_pagespeed filters? Or is this
a bad idea to begin with?

6) Is there anything else I am missing? Are there any specific resources
I need to look at?

7) Should we go with nginx or apache? (Opinions ok.)

Much thanks,

Matt Smith



_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unicorn vs Apache
  2011-07-11 16:07 Matt Smith
@ 2011-07-11 16:50 ` Steve Klabnik
  2011-07-11 18:50   ` Eric Wong
  2011-07-11 18:45 ` Eric Wong
  1 sibling, 1 reply; 7+ messages in thread
From: Steve Klabnik @ 2011-07-11 16:50 UTC (permalink / raw)
  To: unicorn list

I only have a barely informed opinion here, but I will say two things:

1) You do know that 3.1 streaming is still very much experimental, right?

2) Introducing an additional layer in front of the application by
putting nginx in front of apache doesn't seem to be a good idea to me,
though I have done it in the past. Performance was the _last_
consideration with that application.

3) We can talk in theory all we want, but we don't have your
application. Try it, and profile. Then you'll have a real answer, not
some crap that we all make up. Especially with something like
webserver setup, you should be able to just try all these combinations
in a day or two, and see what works for your app.

There is no silver bullet.

-Steve
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unicorn vs Apache
  2011-07-11 16:07 Matt Smith
  2011-07-11 16:50 ` Steve Klabnik
@ 2011-07-11 18:45 ` Eric Wong
  2011-07-11 18:57   ` Steve Klabnik
  1 sibling, 1 reply; 7+ messages in thread
From: Eric Wong @ 2011-07-11 18:45 UTC (permalink / raw)
  To: unicorn list

Matt Smith <matthewcalebsmith@gmail.com> wrote:
> Hello all,
> 
> I have always deploys rails apps with unicorn and nginx as a reverse
> proxy in the past. However, I am working with a new firm and they would
> like to use Apache with mod_pagespeed in front of unicorn.
> 
> We will be deploying a rails 3.1 app with streaming. To me,
> mod_pagespeed does not seem like a magic bullet, as it appears to be a
> collection of best practices which have to be rewritten as a page is
> being served.

note: mod_pagespeed is totally independent if Rails 3.1 streaming.

Keep in mind the most important feature of nginx Unicorn relies on (full
request/response buffering) also defeats Rails 3.1 streaming because of
how it's currently implemented.

> Why not code with the best practices in mind as to not
> have to scan and yet again reprocess the content?

My thoughts exactly :)  But implementing those best practices
isn't cheap, either.  If you have to run mod_pagespeed, the safest
configuration would be:

  nginx <-> mod_pagespeed <-> unicorn

Of course that would introduce latency.  Maybe there's Rack middleware
that works like mod_pagespeed...

> Searching on the web, I find few entries about mod_page speed and rails,
> and relatively few entries about apache with unicorn.

Apache + Unicorn is still unsupported since (as far as anybody knows),
it doesn't fully buffer responses and requests to completely isolate
Unicorn from the harmful effects of slow clients.

> To me it seems that using best practices, with appropriate use of
> caching, and nginx would be a better solution than apache with
> mod_pagespeed.

I agree.

> Questions:
> 
> 1) Does nginx provide any necessary services to unicorn, that apache
> cannot provide?

nginx provides full request + response buffering (all uploads, and large
response bodies that can't fit into socket buffers).  nginx also
provides inexpensive handling of idle keepalive connections; so you
can have a lot of idle connections for little memory usage.

Apache 2.x mpm_event /should/ be as good *if* (and only if) it an
provide the full request/response buffering; but I don't have any
experience with it.  mpm_worker can be fairly efficient with Linux+NPTL
if you can use smaller pthreads stack sizes (and are using 64-bit).

> 2) If apache can provide all necessary services, does it do them as well
> as nginx.

Buffering + keepalive maintenance is the most important thing I care
about, and as far as I know, Apache doesn't do that as well as nginx.

> 3) We would like the fastest user experience possible. Does apache with
> mod_pagespeed hold any weight here over nginx?

The full request/response buffering of nginx also hurts latency a
little, so the user experience is slightly worse under low load.
However, nginx does the best job of keeping things going under high
load.

> 4) Part of a fast user experience is how fast you get the page, correct?
> Seems like nginx has the upper hand here, due to nginx's nio vs apache's
> threading.

Not sure what "nio" means... non-blocking I/O?  Apache can use mpm_event
which is like the non-blocking + event loop nginx uses, but AFAIK the
buffering of requests responses is not like what nginx implements.

> 5) Would it make since to put nginx in front of apache w/mod_pagespeed
> (or visa versa), to use the applicable mod_pagespeed filters? Or is this
> a bad idea to begin with?

nginx <-> mod_pagespeed <-> unicorn should be alright, but of course not
ideal because of the extra copying + latency involved.

For non-Ruby/Rack apps, I've always recommended nginx sit in front of
any Apache 1.3 or 2.x+mpm_prefork apps that are exposed to slow clients,
too.

> 6) Is there anything else I am missing? Are there any specific resources
> I need to look at?

If you're willing to take a risk with Rainbows!, I posted some notes
about making it work with Rails 3.1 streaming here:

http://thread.gmane.org/gmane.comp.lang.ruby.rainbows.general/229

Keep in mind nobody I know of uses Rainbows! in production; but
it /should/ be able to work without nginx (or any proxy).

> 7) Should we go with nginx or apache? (Opinions ok.)

nginx remains the only supported reverse proxy for Unicorn at this
moment.

-- 
Eric Wong
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unicorn vs Apache
  2011-07-11 16:50 ` Steve Klabnik
@ 2011-07-11 18:50   ` Eric Wong
  2011-07-11 19:22     ` Steve Klabnik
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Wong @ 2011-07-11 18:50 UTC (permalink / raw)
  To: unicorn list

Steve Klabnik <steve@steveklabnik.com> wrote:
> 3) We can talk in theory all we want, but we don't have your
> application. Try it, and profile. Then you'll have a real answer, not
> some crap that we all make up. Especially with something like
> webserver setup, you should be able to just try all these combinations
> in a day or two, and see what works for your app.

Be careful about relying on profiling/benchmarking tools, most of them
don't replicate network latency and simulate slow/idle/keepalive clients
at all.

I wrote david many years ago to simulate slow client behavior
and to convince Apache mpm_prefork + (mod_php|mod_perl) users to
put nginx in front of their apps regardless of what benchmarks
were saying: http://bogomips.org/david.git

-- 
Eric Wong
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unicorn vs Apache
  2011-07-11 18:45 ` Eric Wong
@ 2011-07-11 18:57   ` Steve Klabnik
  0 siblings, 0 replies; 7+ messages in thread
From: Steve Klabnik @ 2011-07-11 18:57 UTC (permalink / raw)
  To: unicorn list

> Of course that would introduce latency.  Maybe there's Rack middleware
> that works like mod_pagespeed...


I knew I remembered something like this:
http://rack-pagespeed.heroku.com/ I think that's what this is...
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unicorn vs Apache
  2011-07-11 18:50   ` Eric Wong
@ 2011-07-11 19:22     ` Steve Klabnik
  0 siblings, 0 replies; 7+ messages in thread
From: Steve Klabnik @ 2011-07-11 19:22 UTC (permalink / raw)
  To: unicorn list

Quite fair. Like I said, barely informed opinion here. :)
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unicorn vs Apache
@ 2011-07-11 21:43 Matt Smith
  0 siblings, 0 replies; 7+ messages in thread
From: Matt Smith @ 2011-07-11 21:43 UTC (permalink / raw)
  To: mongrel-unicorn

Thanks Eric and Steve,

I really appreciate the input and time. And thanks for reading through
my typos... You understood exactly what I meant to say.

I have read about Rainbows! before. I will have to give it a shot on
some upcomming projects, as I really enjoy using Unicorn.

Thanks for pointing out rack-pagespeed.

Much thanks,

Matt Smith



_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-07-11 22:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-11 21:43 Unicorn vs Apache Matt Smith
  -- strict thread matches above, loose matches on Subject: below --
2011-07-11 16:07 Matt Smith
2011-07-11 16:50 ` Steve Klabnik
2011-07-11 18:50   ` Eric Wong
2011-07-11 19:22     ` Steve Klabnik
2011-07-11 18:45 ` Eric Wong
2011-07-11 18:57   ` Steve Klabnik

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/unicorn.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).