Ari
Ari

Reputation: 3127

WCF Async working too long

I have wcf service with some debug method:

public Result DebugMethod(TimeSpan time){
    Thread.Sleep(time);
    return new Result { Code = new Random().Next()};
}

I wanted to test performance between sync and async calling.

I packed up Result into Response class, that have mutex waiting for result:

class Response {
    public Result result;
    bool loaded = false;
    public ManualResetEvent _wait = new ManualResetEvent(false);
    public Result get(){
        if(!loaded){
            _wait.WaitOne();
            loaded = true;
        }
        return result;
    }

And my DebugMethodCompleted event:

     //r - correct response structure, result - wcf response
     r.result = result
     r._wait.Set();

And I'm calling DebugMethodAsync 10 times, each with TimeSpan = 1 sec. Then, after all async calls, I'm checking results (just to wait for them).

So I thought it would take about 1s. But all times it is taking 5s.

If I change number of calls to n, it is taking n/2 s to get all responses, like there could be just to async tasks processing at time.

EDIT: It seems like all async call in client app are made, but server is handling up to 2 concurrently (from one client).

So: Client made 4 async call and is waiting for result, server is handling first two, then, after 1s., third and forth.

Upvotes: 1

Views: 191

Answers (2)

Ari
Ari

Reputation: 3127

There are few things needs to be done.

First, ServiceThrottling should be set on server service behavior. There are number of concurrent calls that can be done to service.

<behavior ...>
    ...
    <serviceThrottling
        maxConcurrentCalls="A"
        maxConcurrentSessions="B"
        maxConcurrentInstances="C"
    />
</behavior>

Next, on clinet app, System.Net.ServicePointManager.DefaultConnectionLimit should be set. Default value is 2.

// somewhere in the code
System.Net.ServicePointManager.DefaultConnectionLimit = X;

Upvotes: 0

usr
usr

Reputation: 171218

Did you check WCF limits and throttling? It is probably set to 2. Client OS's have a hard-coded limit of max. 10 that you cannot configure away.

Upvotes: 1

Related Questions