[Mongrel] Sharing a mongrel cluster in a multi-url environment
jalmberg at identry.com
Fri Jan 30 04:22:02 EST 2009
On Jan 29, 2009, at 10:17 PM, Will Green wrote:
> I'm not sure that instance-specific connections are supported by
> ActiveRecord (you can, however, use class-specific connections).
> From the
> ActiveRecord documentation,
> http://api.rubyonrails.org/classes/ActiveRecord/Base.html, the
> connection information is tied to your model at the class level. I
> think you can accomplish what you have described without a separate
> cluster for each virtual host.
I'm hoping I can. What I'm going to try next is to use a common
database (the one defined in environment/production.rb) for the
sessions table. Then when I switch the database to the client's db,
the session table won't be affected.
That's the theory, anyway.
> Here's an alternate idea:
> Assuming you're deploying to a *nix server, what you might try
> instead is
> having your rails app live in one location on the file system.
> Then, since
> the only thing that is different is the configuration, for each
> symlink in all but the config directory. The config directory will
> then be
> unique for each app, but all the code will be shared. When you
> update the
> application code, simply restart all the mongrel clusters.
Well, if I can get what I need working, I'll only have one shared
mongrel cluster. That is the goal -- to eliminate the need to have
dedicated mongrels for every client. I really don't want to have
hundreds of mongrels cluttering up the system.
BTW, I don't think it is a problem to have multiple mongrel clusters
on one directory. I haven't tried this, but don't see why it wouldn't
work. Just use a different pid for each cluster.
> Another idea: you may want to reconsider your application
> architecture. Do
> you really need a separate database for each host? Could you instead
> introduce a ClientAccount class (that has the value from
> X_CLIENT_ID as the
> Primary Key), and tie it into the other models with has_many
> and a before_filter on the ApplicationController? This way, you
> don't need
> separate configs, you could point each VirtualHost at the same Mongrel
> cluster, AND you could manage the Client Account within rails.
I've thought about that, but each client potentially has thousands of
records in his/her database. I believe the system will get too slow
if all records are in one db, and all clients will be impacted by the
one client who has a million records.
Plus each and every table would have to have client_id in it. That
just smells bad to me. Much simpler to just give each client his own
db and switch on the request. That's what I'm hoping for, anyway.
More information about the Mongrel-users