WCF Data Services performance

By Mirek on (tags: Data Services, OData, WCF, categories: architecture, code)

The main benefit of using WCF Data Services (formerly codename ) is that this is interoperable, which means it can be accessed from clients created in different technologies. Moreover standard WCF services offers the only exposed set of methods. Data Services, as implementation of OData protocol, offers the Resource to be queried and altered using HTTP methods. That’s are the pros of WCF Data Services. And what about the performance in comparison to WCF services?
In this post I will try to measure this performance.

Testing solution will consists of MVC 3 application which will hosts WCF Data Services service and WCF service, and console clients for OData and wcf service. Both services will expose the collection of Person entity

One test will be based on receiving flat list of Person objects without Orders loaded. And at second step the Orders will be filled with some random objects of type

To avoid any additional performance hit we will use some mock repository for both services which will generate the collection of Person and Order entities

In line 53 and 61 there are IQueryable properties which will be automatically exposed in WCF Data Services. That’s the one of WCF Data Service provider requirements to have public IQueryable collections. Another is that the entity type (here Person) has an DataServiceKeyAttribute applied.

The WCF Data Service looks like this

Simple isn’t it?

And WCF service looks like this

Also simple. It is standard WCF service using basicHttpBinding so messages are encoded as a text and sent through HTTP. Current functionality of this service is only a fraction of above OData service, but this is not an subject of this post.
I will not show the code of the clients, since it is trivial.

In the tests we will measure the time from request to the response. The standard WCF services will be tested with two message encodings: Text and binary, both using HTTP protocol.
Last row in each the table contains the median of the results.

Test 1

Getting a 1000 of Person without Orders

Test 2

Getting a 1000 of Person with Orders loaded

The only change required for this test is to set the

so all Person entities will be stored with its Orders loaded in mock repository. In WCF there is no change needed while OData service client must be modified, because OData service does not automatically loads the collections. We have to use Expand method on client side like this

so the WCF Data Service will load Orders for each Person entity on sever side.

Here you can see how bad performance has OData service. Especially Expand functionality is very not efficient.

Test 3

OData service in comparison with direct database access using Entity Framework.

In the last test we will compare the OData service with Entity Framework Code First as a backend data source performance with direct Entity Framework Code First context operation. Test data contains 1000 Person entities without orders loaded. Direct access application has duplicated database in MS Sql Server CE 4.0 format and is a console application. OData client is also an console application and connects to the service hosted in MVC web site.