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
-
Enable multi-thread for each call.
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall, UseSynchronizationContext = false)] public class Service1 : IService1 { ... }
-
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);
-
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
-
Optimize Application Pool settings.
-
Optimize Website settings
Optimization – .net Framework settings
-
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>
-
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>
Leave a Reply