unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* Multiple rack applications on the same server with unicorn
@ 2011-09-30 17:04 John Joseph Bachir
  2011-09-30 17:16 ` Eric Wong
  2011-09-30 19:50 ` Hongli Lai
  0 siblings, 2 replies; 4+ messages in thread
From: John Joseph Bachir @ 2011-09-30 17:04 UTC (permalink / raw)
  To: unicorn list

If I'm running two rails apps on the same server using Unicorn, I have
to run two instances of Unicorn, right?

If so, then here's a place where passenger might win in terms of
memory use, as the rails code will be loaded into memory twice, right?

I'm still probably going with Unicorn, but just exploring this first.

Thanks,
John
_______________________________________________
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] 4+ messages in thread

* Re: Multiple rack applications on the same server with unicorn
  2011-09-30 17:04 Multiple rack applications on the same server with unicorn John Joseph Bachir
@ 2011-09-30 17:16 ` Eric Wong
  2011-09-30 19:50 ` Hongli Lai
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Wong @ 2011-09-30 17:16 UTC (permalink / raw)
  To: unicorn list

John Joseph Bachir <johnjosephbachir@gmail.com> wrote:
> If I'm running two rails apps on the same server using Unicorn, I have
> to run two instances of Unicorn, right?

I'm not sure if Rails (or any other frameworks) has issues, but plain
Rack applications will work.  Rack lets you do something like this in
config.ru:

  --------------------- config.ru ------------------
  map("http://foo.example.com/") do
    run FooApp.new
  end
  map("http://bar.example.com/") do
    run BarApp.new
  end
  ----------------------- 8< -----------------------

Both applications need to be able to work from the same working
directory, though.

> If so, then here's a place where passenger might win in terms of
> memory use, as the rails code will be loaded into memory twice, right?

It's all dependent on whether Rails lets you run two apps in the same
process or not (in which case Unicorn can do it).

The following example is pretty ugly, but lets you split your workers
between two applications:

  ----------------- unicorn.conf.rb -----------------
  preload_app false
  worker_processes 2 # need more than one
  after_fork do |server,worker|
    $unicorn_worker_nr = worker.nr
  end
  ---------------------------------------------------

  --------------------- config.ru ------------------
  if ($unicorn_worker_nr % 2) == 0
    run FooApp.new
  else
    run BarApp.new
  end
  ----------------------- 8< -----------------------

-- 
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] 4+ messages in thread

* Re: Multiple rack applications on the same server with unicorn
  2011-09-30 17:04 Multiple rack applications on the same server with unicorn John Joseph Bachir
  2011-09-30 17:16 ` Eric Wong
@ 2011-09-30 19:50 ` Hongli Lai
  2011-10-01  3:34   ` John Joseph Bachir
  1 sibling, 1 reply; 4+ messages in thread
From: Hongli Lai @ 2011-09-30 19:50 UTC (permalink / raw)
  To: unicorn list

On Fri, Sep 30, 2011 at 7:04 PM, John Joseph Bachir
<johnjosephbachir@gmail.com> wrote:
> If I'm running two rails apps on the same server using Unicorn, I have
> to run two instances of Unicorn, right?
>
> If so, then here's a place where passenger might win in terms of
> memory use, as the rails code will be loaded into memory twice, right?

If you have two apps then Phusion Passenger also loads Rails into memory twice.
Unless if you're using the 'smart' spawning method (instead of the
default 'smart-lv2' spawning method). The Phusion Passenger manual
explains the difference between these two spawning methods. However
'smart' is practically useless these days because everybody uses
Bundler. It is pretty much impossible nowadays to preload the Rails
framework and sharing it between multiple apps transparently. We're
planning on removing the 'smart' spawning method and only supporting
'smart-lv2' in the future.
In the mean time, if you want to share the same Rails memory between
apps, then you should merge them together into a single app.

-- 
Phusion | Ruby & Rails deployment, scaling and tuning solutions

Web: http://www.phusion.nl/
E-mail: info@phusion.nl
Chamber of commerce no: 08173483 (The Netherlands)
_______________________________________________
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] 4+ messages in thread

* Re: Multiple rack applications on the same server with unicorn
  2011-09-30 19:50 ` Hongli Lai
@ 2011-10-01  3:34   ` John Joseph Bachir
  0 siblings, 0 replies; 4+ messages in thread
From: John Joseph Bachir @ 2011-10-01  3:34 UTC (permalink / raw)
  To: unicorn list

I didn't realize that about bundler and smart spawning.

Very helpful, thanks!
_______________________________________________
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] 4+ messages in thread

end of thread, other threads:[~2011-10-01  4:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-30 17:04 Multiple rack applications on the same server with unicorn John Joseph Bachir
2011-09-30 17:16 ` Eric Wong
2011-09-30 19:50 ` Hongli Lai
2011-10-01  3:34   ` John Joseph Bachir

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).