I would like to connect NHibernate to a MySQL master-slave replication configuration,
so I would like to send writes to the master, and reads to the
master and slaves. Is this possible? I am also planning on having a load balancer
to balance the reads. (ldirectord)
I would like to connect NHibernate to a MySQL master-slave replication configuration, so I
Share
under the hood, nhibernate uses ado.net to connect to data sources. So you would need to look at how ado.net handles this situation.
But additionally, I don’t think you would gain anything if you could do this.
Some background:
Objects in nhibernate are tied to sessions, which are tied to session factories, which are tied to 1 connection.
Let’s say you had a load balancer with ip 1 for reads. And it balances databases on ip’s 2 and 3. And you hit ip 2 directly for writes.
So you have
If you read an object with a session tied to connection 1, you have to load that object and then save and flush to write on a session tied to connection 2. At that point, you have done 2 read’s and 1 write. Whereas if you use one session factory then you have a read and a write (assuming the same session is alive through the read and the write, or that 2nd level caching is setup).