[WCF] Performace Optimization

For legacy .net framework application, which OS dependent and difficult to host in containerized platform. As result, it cannot improve performance and availibility by auto scaling. In order to optimize it, there are several parts can be tune.

Optimization – Code Level

  1. Enable multi-thread for each call.

    [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall, UseSynchronizationContext = false)]
    public class Service1 : IService1
    {
    ...
    }
  2. Using AsyncPattern callback to return response.
    As WCF have method signature check, method need to start with Begin and callback method start with End.

    [OperationContract(AsyncPattern =true)]
    [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "GetSleepResponseAsync")]
    IAsyncResult BeginGetSleepResponseAsync(int value, AsyncCallback callback, object state);
    string EndGetSleepResponseAsync(IAsyncResult result);
  3. Optimize web application resource settings.

    <configuration>
        <system.net>
            <connectionManagement>
                <add address="*" maxconnection="65535"/>
            </connectionManagement>
        </system.net>
        <bindings>
              <netTcpBinding>
                  <binding name="netTcpBinding"
                        closeTimeout="00:10:00"
                        openTimeout="00:10:00"
                        receiveTimeout="00:10:00"
                        sendTimeout="00:10:00"
                        transactionFlow="false"
                        transferMode="Buffered"
                        transactionProtocol="OleTransactions"
                        hostNameComparisonMode="StrongWildcard"
                        listenBacklog="65535"
                        maxBufferPoolSize="1048576"
                        maxBufferSize="10485760"
                        maxConnections="65535"
                        maxReceivedMessageSize="10485760">
                      <readerQuotas
                         maxDepth="32"
                         maxStringContentLength="8192"
                         maxArrayLength="16384"
                         maxBytesPerRead="4096"
                         maxNameTableCharCount="16384" />
                      <reliableSession
                         ordered="true"
                         inactivityTimeout="00:10:00"
                         enabled="false" />
                      <security mode="None">
                          <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                          <message clientCredentialType="Windows" />
                      </security>
                  </binding>
              </netTcpBinding>
          </bindings>
    </configuration>

Optimization – IIS

  1. Optimize Application Pool settings.


  2. Optimize Website settings

Optimization – .net Framework settings

  1. Optimize resource allocation and concurrent access in c:\windows\Microsoft.NET\FRAMWORK64\[version]\Config\machine.config.

    </configuration>
      <system.web>
        <processModel autoConfig="true"  minWorkerThreads="1000" maxWorkerThreads="65535" minIoThreads="1000" maxIoThreads="65535" />
        <httpRuntime minFreeThreads="1000" minLocalRequestFreeThreads="1000" />  
      <system.net>
            <connectionManagement>
                <add address="*" maxconnection="65535"/>
            </connectionManagement>
        </system.net>
    </configuration>
  2. Optimize resource allocation in c:\windows\Microsoft.NET\FRAMWORK64\[version]\Aspnet.config.

    <configuration>
         <system.web>
            <applicationPool maxConcurrentRequestsPerCPU="128" maxConcurrentThreadsPerCPU="0" requestQueueLimit="5000"/>
         </system.web>
     </configuration>
About C.H. Ling 262 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.