views:

35

answers:

1

Good morning.

I'm having concurrency issues. I've created a WCF service, and I've tested it to make sure that individual calls work just fine. Now I'm performing some load testing, and I'm seeing super high CPU utilization with long wait times for requests to be completed. My load testing tool is just a console application configured to run ms test cases on multiple threads to simulate multiple clients. And, I'm wondering if someone could tell me if there's a part of the service configuration, client proxy (auto-generated) configuration, or in the code for the service that I should change to configure it to allow for a high degree of concurrency:

Here's my service config file.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <services>
            <service behaviorConfiguration="Behavior" name="Service.MyService">
                <endpoint address=""
                  binding="netTcpBinding"
                  bindingConfiguration="Security"
                  contract="Service.IMyService">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
                <endpoint address="mex"
                  binding="mexTcpBinding"
                  bindingConfiguration=""
                  contract="IMetadataExchange" />        
                <host>
                    <baseAddresses>
                        <add baseAddress="net.tcp://localhost:808/Service" />
                    </baseAddresses>
                    <timeouts closeTimeout="00:01:00" openTimeout="00:05:00" />
                </host>
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="Behavior">
                    <serviceMetadata httpGetEnabled="false" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                    <serviceThrottling maxConcurrentCalls="300" maxConcurrentSessions="5000"  maxConcurrentInstances="300" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <bindings>
            <netTcpBinding>
                <binding name="Security" openTimeout="00:05:00" maxConnections="10">
                    <reliableSession inactivityTimeout="00:30:00" enabled="true" />
                    <security mode="None">
                        <transport clientCredentialType="None" protectionLevel="None" />
                    </security>
                </binding>
            </netTcpBinding>
        </bindings>
    </system.serviceModel>
</configuration>

Here's my client config file.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBinding_IMyService" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
            hostNameComparisonMode="StrongWildcard" listenBacklog="10"
            maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
            maxReceivedMessageSize="65536">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:30:00"
              enabled="true" />
          <security mode="None">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign">

            </transport>
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address="net.tcp://localhost:808/Service" binding="netTcpBinding"
          bindingConfiguration="NetTcpBinding_IMyService" contract="ServiceReference.IMyService"
          name="NetTcpBinding_IMyService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>
</configuration>

And, here are the attributes that I placed on my WCF service class.


[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]

I read through more than a few articles on MSDN to try and understand what I should do in this case, and I seem to have ruled out hardware being the cause of this problem.

Also, I've replaced any names of objects in the configurations above with generic names (e.g. MyService and IMyService aren't really what I call them).

A: 

If you set InstanceContextMode = PerCall, means that your service will be re-created each time a call is made. Check how much does it costs to create a new instance of the service.

You could try setting it to PerSession or Single. ( http://msdn.microsoft.com/en-us/library/system.servicemodel.concurrencymode.aspx )

Gerardo Grignoli