Sharding databases for performance
There are a few scenarios where it may be appropriate to partition data horizontally across several servers, with performance being the most obvious reason. The concept itself is known as sharding and is used in many large scale applications, such as Facebook.
In this recipe, we'll show you how to use NHibernate.Shards to split our data set across three databases.
Getting ready
In SQL Server, create three new, blank databases named Shard1, Shard2, and Shard3. Complete the Getting Ready instructions at the beginning of Chapter 4, Queries.
How to do it...
Add a reference to
NHibernate.Shardsusing NuGet Package Manager Console:Install-Package NHibernate.Shards –Project QueryRecipesAdd a new folder named
Shardingto the project:Add a new embedded resource named
ShardedProduct.hbm.xml:<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="QueryRecipes" namespace="QueryRecipes.Sharding"> <class...