Recommended use of couchrest model in a multi-tenant app -
i'm looking recommendations on how implement multi-tenancy couchrest model in rails app. multi-tenant app, i'm thinking of 2 options:
{ edit - removed ugly options because they'll confuse future readers }
i work 10k users.
solution: based on sam's advice, here's did , it's working - in case, needed override proxy_database method because standard naming proxy databases didn't match naming.
created master
class site < couchrest::model::base property :name property :slug proxy_for :users proxy_for ...(all other multi-tenant models) # databases on same server in example def proxy_database @db ||= self.server.database!(slug) end end then in each multi-tenant model
class user < couchrest::model::base ... proxied_by :site in applicationhelper create 'site' method can reuse in controllers.
module applicationhelper def site db_name = current_user.db_name @site ||= site.create(slug: "#{db_name}_#{rails.env}" ) end then controller might like:
def show user = site.users.find(params[:id]) render :json => user end
you might want checkout proxying feature of couchrest model this. more details can found here:
http://www.couchrest.info/model/proxying.html
although have no personal experience, understand couchdb handles >10k databases. here thread of ways of scaling number of users:
http://comments.gmane.org/gmane.comp.db.couchdb.user/13862
a few considerations take account when dealing lots of databases:
- file system sub-directory count, not problem ext4.
- namespace databases split between sub-directories and/or servers.
- system open file limit. around 10k. fine if not databases accessed @ same time.
hope helps.
Comments
Post a Comment