Are there any known drawbacks to sharing a single SessionFactory object 
between multiple client databases in a multi-tenant application?

At work I help develop a large WebForms application that uses a separate 
SQL Server database for each of our 64 clients. We use a mix of legacy 
stored procedures and NHibernate for data access.

I'm looking into reducing our memory footprint, which routinely climbs to 
almost 4GB. Nearly half of that is due to the fact that we're holding on to 
one 26MB copy of SessionFactory for each client. The legacy code is 
creating new SessionFactory objects explicitly by attempting to retrieve a 
cached SessionFactory using the client's database name as a key, and 
creating a new SessionFactory if a cached one isn't retrieved.

These 64 databases have identical schemas, and everything I've been able to 
find on the web indicates that you can share a SessionFactory in these 
cases. I've confirmed that tweaking our caching code to use a common key 
for all client databases eliminates the duplicate SessionFactory objects. 
And we've already implemented a custom IConnectionProvider that seems to 
handle switching connections strings perfectly when creating sessions.

But our app is large (+1 million lines of code) and so I'm hesitant to make 
a change like this that could cause hard-to-detect problems.

>From what I've read, it seems like a single SessionFactory should be fine, 
but 26MB seems like a ton of state to share between 64 clients. I'm 
wondering if there are any obvious pitfalls that we should be aware of or 
avenues I should investigate. 

There seems to be very little on the web that discusses multi-tenant 
architectures, aside from basic blog posts describing how to set up 
NHibernate to use multiple databases. If I've overlooked a resource, I'd be 
grateful if you could point me in the right direction.

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/nhusers/-/riaY6qJ3UNUJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to