Monday, October 1, 2012

Best Practices For WCF

There are few the recommended best practices for WCF, what I found during to resolve the performance issue. Recently one my application (WCF based software) is going into production and client had more concerns and worries about the performance because, this application had to deal with bulk data like million records.

In initial phase of development, we have faced lots of design hurdles (due to n-tired approach with SOA) against the performance.

Since last few days I am working on the performance issue and has already done lots of goggling to improve the performance and finally I found few tips and best practices

  1. Avoid multiple service round trips to populate the screen data, Make single call to get all lookup data for screen instead of making each for each data driven control.
  2. If possible and data size allowed, Use the client side caching for static data (master data).
  3. Use the singleton proxy creation pattern or proxy caching approach to create the service proxy.- avoid to create service proxy for each client request.
  4. Implement the server side caching for static data or lookup data.
  5. Choose the proper wcf binding ( nettcp, webhttp, wshttp etcs)
  6. set the right value of the below service behavior Throttling properties to improve WCF performance 
    • maxConcurrentCalls - This specifies the maximum number of messages processed across the service host. The default value for this property is 16 (WCF 4.0 is improved to default is 16 * Processor Count).
    • maxConcurrentInstances - This specifies the maximum number of instances of a context object that executes at one time with the service. The default is Int32.MaxValue.
    • maxConcurrentSessions - This specifies the maximum number of sessions at one time within the service host object. The default value is 10 (WCF 4.0 increases that to 100 * Processor Count).
   <serviceBehaviors>
        <behavior>
         
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
         
          <serviceDebug includeExceptionDetailInFaults="false" />
          <dataContractSerializer maxItemsInObjectGraph="2147483646" />         

<serviceThrottling 

maxConcurrentCalls="16" maxConcurrentSessions="100" maxConcurrentInstances="10" /> 

          <serviceMetadata httpGetEnabled="true" />         
        </behavior>
      </serviceBehaviors>


Wcf Proxy Caching - 
To generate or dispose the wcf proxy, both are very expensive task and it consume good amount of resource and time. so avoid to this,we should use singleton pattern to create wcf proxy or cache proxy.

you will be get more details to visit on below link 
http://blogs.msdn.com/b/wenlong/archive/2007/10/27/performance-improvement-of-wcf-client-proxy-creation-and-best-practices.aspx

Thanks for visiting !

No comments:

SQL Server - Identify unused indexes

 In this blog, we learn about the index usage information (SYS.DM_DB_INDEX_USAGE_STATS) and analyze the index usage data (USER_SEEKS, USER_S...