Tuesday, July 29, 2014

Improving the performance of a WCF service

Recently I was tasked to look into certain performance issues of a large Enterprise application having a service oriented architecture. The front end web site is based on Microsoft ASP.Net MVC and the entire business logic layer of the application is implemented as a series of WCF web services that are primarily exposed over TCP (i.e. using net.tcp binding). In order to increase the scalability of the system, each tier of the application deployed in separate servers. After spending some time improving the web front end, I quickly realized that the primary reason for intermittent slowness of the application is due to the fact that a large amount of data passing between the service layer and the web layer (i.e. web server and application server). If we are to improve this situation, then we have either to improve the network infrastructure or reduce the amount of data. Since, upgrading the network connectivity was not an option, I was focusing my effort on the later. As a result, I was investigating the possibility of compressing the traffic between the web server and application server.

How to enable compression on WCF traffic?

As it turns out, enabling compression is not trivial in WCF services. However, if your services are hosted in IIS, then you will be able to utilize the built-in compression module for certain message types. [UPDATE: Since, .net v4.5, you can actually enable compression for binary message encoder] Fortunately, I found a wonderful sample on MSDN where data compression is achieved via a custom message encoder. After going through the sample implementation, I decided to implement a reusable component where I can enable compression for both binary and text message encoders with the extra option of able to decide the compression algorithm (Gzip, Bzip2, Deflate, etc…). I created a Nuget package of my initial implementation and now it is available on nuget.org I will explain more on using this package in a future article and I hope it will be useful for others as well.

Technorati Tags: ,,,

1 comment:

  1. You have given great content here.data compression research papers I am glad to discover this post as I found lots of valuable data in your article. Thanks for sharing an article like this.