DarthVader
DarthVader

Reputation: 55022

WCF hosting and Performance

I have WCF service. I have done some testing with basichttp binding and tcp binding.

In a console client i created hundreds of threads and hit the service with tcp and http binding. Turned out TCP is twice faster than http.

Then i made a web client that runs on IIS and hits the service. Turned out that http is faster then TCP.

How does this happen? isnt TCP supposed to be faster than basichttp? COde is like the one below. similar.

stopwatch start here

Thread[] ts = new Thread[100];  
for(int i= 0; i< ts.lenght;i++){  
  ts[i] = new Thread(foo);  // replace with bar for the second test.
  ts[i].start();  
}

for(int i 0;i< ts.lenght;i++){  
  ts[i].join();  
}  

stopwatch stop here.

public static void foo(){  
MyServiceClient myclient = new MyServiceClient("netTcpBinding");  
myclient.GetResult(1);  
} 

public static void bar(){
MyServiceClient myclient = new MyServiceClient("basicHttpBinding");
myclient.GetResult(1);
}

Upvotes: 2

Views: 537

Answers (2)

Michael Kennedy
Michael Kennedy

Reputation: 3380

Did you know that WCF has throttling turned on by default. Before you run these tests, you should turn it off by using this bit of config in your web.config's serviceModel section:

<behaviors>
  <serviceBehaviors>
    <behavior> <!-- can omit name in .NET 4 -->
      <serviceThrottling 
        maxConcurrentCalls="10000" 
        maxConcurrentSessions="100000" 
        maxConcurrentInstances="100000" />
    </behavior>
  </serviceBehaviors>
</behaviors>

The defaults vary by version but are around 16, 10, 100 or something along those lines in .NET 4. Those lower defaults are applied even if you have no throttling entry in your web.config / app.config.

Good luck.

Upvotes: 3

user585968
user585968

Reputation:

i think the problem is that of the hosting process. .NET defaults to a certain number of worker threads in the thread pool which can be overridden by the process prior to creation of thread tasks. considering your second test is in IIS, which prior to WCF4 in conjunction with AppFabric defaults to HTTP, IIS due to the nature of the beast could quite possibly be changing the default number of worker threads.

just because you ask for say 100 threads on any given machine, does not mean all will be created at once but rather queued not to mention limitations of thread context switching.

as a general rule you should not create more worker threads than the number of cores on the machine.

Upvotes: 0

Related Questions