John Joseph Bachir
2011-Sep-30 17:04 UTC
Multiple rack applications on the same server with unicorn
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
Eric Wong
2011-Sep-30 17:16 UTC
Multiple rack applications on the same server with unicorn
John Joseph Bachir <johnjosephbachir at 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
Hongli Lai
2011-Sep-30 19:50 UTC
Multiple rack applications on the same server with unicorn
On Fri, Sep 30, 2011 at 7:04 PM, John Joseph Bachir <johnjosephbachir at 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 at phusion.nl Chamber of commerce no: 08173483 (The Netherlands)