Just sharing some of my inconsequential lunch conversations with you... RSS  

Thursday, January 04, 2007

Benchmarking data tiers

Choosing your data tier is not always an objective choice. So I've decided to setup a data tier benchmarker. Here's how it works:

First I started choosing a simple entity: a Category.

Then I defined a simple data tier facade for it, as follows:

public interface IDataFacade

{

void Create(ISessionFacade sessionFacade, Category category);

Category Read(ISessionFacade sessionFacade, int key);

IList<Category> PagedRead(ISessionFacade sessionFacade, int page, int pageSize);

void Update(ISessionFacade sessionFacade, Category category);

void Delete(ISessionFacade sessionFacade, Category category);

}

 

As you certainly already noticed, I create another interface to façade the data tier session - ISessionFacade.

 

Then I created the integration test as follows:   

 

Category newCategory = new Category();

newCategory.Description = "testing"; 

//

// C r u d

dataFacade.Create(sessionFacade, newCategory);

//

// c R u d 

// Read

Category category = dataFacade.Read(sessionFacade, newCategory.Id);

Assert.AreEqual<string>(category.Description, newCategory.Description); 

// PagedRead

IList<Category> categories = dataFacade.PagedRead(sessionFacade, 1500, 10);

Console.WriteLine("categories.Count: " + categories.Count); 

//

// c r U d

category.Description = String.Format("{0}-{1}", category.Description,DateTime.Now.ToLongTimeString()); 

dataFacade.Update(sessionFacade, category);

sessionFacade.Flush(); 

//

// c r u D

dataFacade.Delete(sessionFacade, category);

sessionFacade.Flush();

 

 

The code above was executed on 8 threads, each iterating over 16 session openings, each callings 64 times.

 

Now for some fun: I implemented a NHibernate and a SqlClient version of this facades, for example:

 

public void Create(ISessionFacade sessionFacade, Category category)

{

((SessionImplementation)sessionFacade).Session.Save(category);

} 

And the result was: NHibernate implementation was 15% faster! Isn't it great?

Ok, I must confess, the SqlClient code didn't use parameters, that's probatly why. Yet, an excelent result for NHibernate.

And yes, it's true, this doesn't prove NHibernation's scalability. But it's a start, and at least can be backed by real data.

One of these days I'll benchmark NetTiers and LINQ for SQL, and post the results back here. Cya there :)

No comments:

Development Catharsis :: Copyright 2006 Mário Romano