PERFORMANCE TUNING WCF

by Adactus Ltd 15. December 2011 00:35

More often we are deploying WCF services to be used by applications hosted in the same environment.  Traditionally we have opted to choose a binding mechanism and use it for external and internal applications connecting to our service. But wait…..are we really allowing our internal applications to perform as efficiently as possible?

The answer to this question is no.

This excellent article on WCF performance, from Terrance A. Snyder, shows the performance of various binding options in WCF.

By far the best channel is netTcpBinding for performance. Great! But netTcpBinding is a bit of a pig to get configured, so let’s demystify the steps involved in getting it setup.

Before we start, let’s get one thing clear.....Microsoft got configuration in WCF just about right. There, we said it! If you’re reading articles that start discussing significant code changes to support different WCF bindings, close your browser and go make a coffee (and don't open that site again!)

Still with us? Great…..let’s look at IIS and WCF configuration to support netTcpBinding.

There are several elements to supporting netTcpBinding in an IIS7 hosted application.

1.Windows Configuration

2.IIS Configuration

3.Service Configuration

4.Client Configuration

This following examples use a Windows 2008 R2 server, running IIS 7.

WINDOWS CONFIGURATION

  1. From the Start menu, choose Control Panel.
  2. Select Programs and Features.
  3. Click Turn Windows Components on or Off.
  4. Expand the Microsoft .NET Framework 3.5.1 node and check the Windows Communication Foundation Non-HTTP Activation feature.

CORRECTING IIS CONFIGURATION

If you install WCF Activation after IIS is installed or after you install .NET Framework 4.0 and above, you will need to refresh your IIS install by running the following command from a command prompt: 

aspnet_regiis -iru

 

IIS CONFIGURATION

The next stage is to configure your websites in IIS. First configure the bindings for the website. A net.tcp binding should have been created for the default website. You can add the required bindings to other websites manually using the IIS Manager, as shown below.

Alternatively, you can use Appcmd.exe, which is installed with the Internet Information Services 7.0 (IIS) management toolset. From an administrator-level command prompt, run the following command:

%windir%\system32\inetsrv\appcmd.exe set site "Default Web Site" -+bindings.[protocol='net.tcp',bindingInformation='808:*']

 

The net.tcp protocol needs to be added to the list of enabled protocols for the website. Using IIS Manager, select the website and click 'Advanced Settings'. Enter net.tcp as an additional enabled protocol. Each protocol should be separated with a comma.

 

Alternatively, you can use Appcmd.exe, which is installed with the Internet Information Services 7.0 (IIS) management toolset. From an administrator-level command prompt, run the following command:

%windir%\system32\inetsrv\appcmd.exe set app "Default Web Site/servicemodelsamples" /enabledProtocols:http,net.tcp

 

This completes the configuration of Windows and IIS to support net.tcp binding. 

WCF Service Configuration

The following steps outline the process to enable net.tcp binding for a WCF service. In addition we will outline a proven method for optimising the WCF net.tcp binding configurations, as outlined by this excellent article on WCF performance, from Terrance A. Snyder.

Service Definition

 

<services>
      <service name="NetTcpBindingExample.HelloWorldService">
        <endpoint binding="netTcpBinding" bindingConfiguration="max" contract="NetTcpBindingExample.IHelloWorldService"/>
        <endpoint address="mex" binding="wsHttpBinding" contract="IMetadataExchange" />
      </service>
</services>

 

Behaviour Definition

 

<behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>

        </behavior>
      </serviceBehaviors>
</behaviors>

 

Binding Definition

Option 1 - basicHttpBinding -- Fast!

 

<basicHttpBinding>

        <binding name="max" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
          <security mode="None"/>
        </binding>
</basicHttpBinding>


 

Option 2 - customBinding - Faster!

 

<customBinding>
        <binding name="binaryHttpBinding">
          <binaryMessageEncoding maxReadPoolSize="2147483647" maxSessionSize="2147483647" maxWritePoolSize="2147483647" />
          <httpTransport maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" decompressionEnabled="true"/>
        </binding>
</customBinding>


 

Option 3 - netTcpBinding - Fastest!

 

<netTcpBinding>
        <binding name="max" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="2147483647" maxReceivedMessageSize="2147483647" listenBacklog="2147483647" transactionFlow="false">
          <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
          <reliableSession enabled="false"/>
          <security mode="None"/>

        </binding>
</netTcpBinding>

 

 

That completes the WCF Service configuration - simple eh? Well actually, yes. You can choose between the different binding options above, but to get real performance for locally hosted services choose netTcpBinding everytime!

Client Configuration

The client configuration for the client application is very clean. A netTcpBinding is specified and the service endpoint is configured to use net.tcp://

 

<configuration>
    <system.serviceModel>

        <bindings>
            <netTcpBinding>
                   <binding name="max" maxBufferPoolSize="2147483647"
                                                    maxBufferSize="2147483647"
                                                    maxReceivedMessageSize="2147483647">
          <reliableSession enabled="false"/>
          <security mode="None"/>
        </binding>

      </netTcpBinding>
        </bindings>
        <client>
            <endpoint address="net.tcp://demo1.contoso.com:8080/HelloWorld.svc"
                      binding="netTcpBinding"
                      bindingConfiguration="max"
                      contract="HelloWorld.IHelloWorldService"
                      name="NetTcpBinding_IHelloWorldService" />
        </client>
    </system.serviceModel>

</configuration>


That completes the performance optimised netTcp configuration for a WCF service. To transition between services configured to use basic or web http binding only requires simple configuration change in Windows, IIS and the app.config or web.config files for the target services and clients. 

Simple, but effective WCF performance!

Tags: , , , , , ,

Performance | WCF

Adactus staff ace Microsoft Exams

by Adactus Ltd 28. November 2011 11:33

Congratulations to Ian Hamlin who has recently passed both Designing and Developing Windows Phone Applications and Accessing Data with Microsoft .NET Framework 4 Microsoft Exams!


Well Done Ian!

Tags: , , ,

MCPD

Congratulations to our newest MCITP – Mark Young

by Adactus Ltd 25. November 2011 14:47

Adactus would like to congratulate our new MCITP in Database Development, Mark Young, who successfully passed his final exam in Designing Database Solutions and Data Access Using Microsoft SQL Server 2008.

Well done Mark!

About MCITP

MCITP candidates are IT professionals capable of deploying, building, designing, optimizing, and operating technologies for a particular job role. They make the design and technology decisions necessary to ensure successful technology implementation projects.

Tags: ,

Red Gate acquires Cerebrata

by Adactus Ltd 4. November 2011 09:02

Tags: , , ,

Adactus | Cloud | Windows Azure

Adactus is 10 Years Old

by Adactus Ltd 2. September 2011 13:16

Adactus has reached the grand age of 10 years old!

We would like to thank our customers, partners and suppliers that we have worked with since the 2nd September 2001.

Tags:

Adactus

Protocol-less URLs

by Adactus Ltd 11. August 2011 14:01
When offering HTTPS any content you load from external sources also needs to be loaded over HTTPS as well, otherwise you'll receive errors such as "Only secure content is displayed" and that external CSS, image or JavaScript file will be blocked unless you allow it on each page load. This is often the case with CDN content such as Google's jQuery CDN and jQueryUI etc.
Previously, the only way around this, would be hard code the HTTPS, which forces the HTTPS connection when the site is accessed in HTTP mode as well. But this causes an estimated 3.5% overhead over the standard HTTP, per call. We could use JavaScript to use the appropriate protocol, and the Google Analytics plugin uses this exact technique.
However, there is another way - the protocol-less url way - and it looks like this:
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js">
</script>
This means that the browser works out which protocol it should be using based on the page that loaded it.
It really works nicely, and more info can be seen here:
 

Tags: , , ,

Performance

Team Addition - Jeremy Cripps

by Adactus Ltd 1. August 2011 10:07

We're pleased to announce new team member Jeremy Cripps has joined Adactus.

Initially Jeremey will be working with the Goals Soccer Centres team providing bespoke solutions for 5-a-side football centres.

Tags:

Adactus

Developer Session – dynaTrace AJAX Edition

by Adactus Ltd 26. May 2011 08:50

Here at Adactus we’re quite into web performance, after all we’re official Site Confidence partners and members of the performance alliance group in the UK.

Most of our development team are aware of some of the tools to hand such as Yahoo’s YSlow and Google’s PageSpeed add-ons for FireBug but after a recent training session with web performance evangelist Stephen Thair we decided to share some of the lessons learnt with the rest of the team.

One tool Stephen introduced us to was dynaTrace AJAX Edition which records your user journey through out a website and gives full performance analysis helping you tune your pages.

The idea of this blog post is to introduce you to dynaTrace application and give a gentle introduction to the analysis available – what makes this tool so good is its ease of use and the external web links provided to help you investigate potential performance bottle necks in your web app.

User Journey

Recording a user journey is straight forward and simple but before jumping straight in you first need to plan your route. When analysing websites and their performance it’s important to know your end users and the key journey points in your website. For example a generic ecommerce site would have a home page, category page, product page, profile login/registration, basket and checkout process.

By analysing your existing website statistics you can work out your key pages.

Once you’ve planned your journey open dynaTrace and click the FireFox icon near the top right – if it’s the first time you’ve run dynaTrace it’ll prompt you to create a new Run Configuration.

For this demo I’ve set the Name to Adactus Ltd and the URL to our web address.

Once done FireFox will open with the specified URL and it’s at this point your pre-planned site journey comes into action – browse your site to your planned journey and when complete close FireFox.

You’ll notice the Cockpit panel in dynaTrace will now list your journey:

Performance Report

If your familiar with YSlow you’ll instantly understand the Performance Report section.

It’s a great overview of the performance recorded during your user journey ranked from A (best / green) to F (worst / red) for the following sections:

  • Summary
  • Caching 
  • Network 
  • Server-Side
  • JavaScript / AJAX
  • Timeline
  • Key Performance Indicators

The first bit of data you’ll see is the summary tab which provides a great overview of your site’s performance. First up is the speed rank which rates your site from A (great) to F (poor) in a set of pre-defined groups. If you’re familiar with YSlow you’ll feel instantly at home!

As already mentioned there are sub sections within the Performance Report, I’m not going to go into a lot of detail for these as they’re relatively self-explanatory and each tab has a useful link out to help decipher and interpret the results.

Caching

This tab will help identify any missing caching settings in your site.

For example the Adactus site was found to have five resources with no past date cache settings which the tool estimates a saving of 64.72kb in transfer and 1942.73ms download time.

Network

I see this as an overview to the number of HTTP calls with the more calls made the slower the site performance. For example we did a full performance report for one client who ended up with no less than 13 different CSS files and 7 JavaScript files creating a massive performance hit. If you ever find yourself in this situation look into minification and combing files (or give Adactus a call!).

Server-Side

By server side we mean the time to generate dynamic content which is typically database driven. There is a good top 10 article by dynaTrace listing the most common foibles experienced by websites:

http://blog.dynatrace.com/2010/06/15/top-10-performance-problems-taken-from-zappos-monster-and-co/

JavaScript / AJAX

Get a break down of your JavaScript calls and handlers – it’ll give you a breakdown of the call, the number of invocations and the total time in milliseconds.

Timeline

This is one of my favourite sections as it shows the time taken (in ms) for the page to render along with your computer’s CPU count. When completing your user journey the dynaTace application records every single page event be it mouse click, move, key events and more – these are all displayed in the timeline as shown in the example below. You can also drill into a specific section by clicking and dragging a time zone to investigate.

So what can we determine from the timeline?

  • First up is the CPU counter – note this is based on your own personal computer – which is rated from the usual to 0 to 100%
  • JavaScript shows the load time for specific resources and states the start time and duration to load and process
  • Rendering is the canvas draw events on the web page along with the first render event the end user sees
  • Network shows the external HTTP calls, i.e. Google Analytics or tracking tags etc
  • Events shows the load event time, first impression and fully loaded times by simply hovering over the icons shown on the timeline

Another good feature is the ability to double click on a block to drill down into the specific event – dynaTrace have called this PurePaths which we’ll go into later.

KPI’s

This covers key performance indicators such as time to first impression (when the end user sees something on the web page), onLoad and fully loaded.

Timeline

This is similar to the timeline section covered above except it shows it for each page in your user journey.

PurePaths

There are two ways of getting to the PurePaths – first off you can double click an object or event in the timelines already discussed. Alternatively you can get a list of resources and their associated times by double clicking the PurePaths option in the Cockpit panel within the dynaTrace application.

Network

This report lists all the resources, whether the item was in the local cache, status, times, size [bytes] and more. It provides a great way of identifying slow resources or large scaled images on your site.

Hot Spots

This view shows the JavaScript and rending events from the browser and again dynaTrace allows you to drill down into a specific event by double clicking it.

For example if we double clicked the second event _default(*) the report will show you both the forward and backward traces. The back trace shows which JavaScript or DOM caused the browser to draw or alter the page layout helping you identify expensive layout calls. Another good feature is the applications ability to show you the code in question – perfect for performance overviews and suggestions.

Next Steps

Like I said, this is a quick blog overview but it’s worth trying out and reading the help sections on the dynaTrace community section.

You may know of some other tips and tricks, why not share them with us by posting your tips below.

It’s also worth following industry experts such as Stephen Thair and Joshua Bixby or your local performance group.

Tags: ,

Developer Session | Performance

The Adactus Office Expands

by Adactus Ltd 20. May 2011 08:50

After a recent team expansion the hospitality team have expanded into the office next door in Thame.

Tags:

Adactus

Team Addition - John Hasler

by Adactus Ltd 16. May 2011 08:44

A new team member recently joined the hospitality team – John’s already got stuck into our larger projects and is proving to be a good asset to the team!

Tags:

Adactus

About Adactus Ltd

Adactus provides practical and bespoke software development and consulting services for web sites. As a Microsoft partner, Adactus can deliver customised web solutions, mobile development and general bespoke software development services across a wide range of eBusiness and eCommerce needs.  We also provide performance testing services for eCommerce development and other transaction-intensive web solutions.

Month List