otaviosoares
otaviosoares

Reputation: 587

Web Api Entity Framework 6 High CPU Usage And Application Hang

I have an ASP.NET Web Api application with Entity Framework 6 running on 2 extra large instances os AWS.

It was 2 large instances before, but I was facing IIS 503 errors after some time.

The problem is: the app which consumes this api makes a request every 10 seconds from each connected client. We've reached 5k simultaneous clients connected, calling the api every 10 seconds. The cpu of both instances are 40% (I think it's still high).

Now the app is supporting the load. However we can reach up to 20k clients and I don't know what else can I improve in the code.

The method which is called every 10 seconds is async.

public async Task<ExampleContract> Post(ExampleRequest example)
    {
        try
        {
            return await _localizacaService.ExampleAsync(example);
        }
        catch (DataException ex)
        {
            throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
        }
    }

Windows 2008 IIS 7.5 The only IIS setting I've changed was in queue limit, from 500 to 5000.

Is anything else that I can do?

Any help would be really appreciated

Upvotes: 0

Views: 2920

Answers (1)

Peter
Peter

Reputation: 27944

You need to change the maxConcurrentRequestsPerCPU. You can set this key in the registry or set it in you application config.

<system.web>
    <applicationPool maxConcurrentRequestsPerCPU="10000" maxConcurrentThreadsPerCPU="0" requestQueueLimit="10000"/>
</system.web>

You should really change the design, making 5000 request every 10 seconds can probably handled in a better way than you are doing at this moment. Caching the result for a few seconds in your output cache for example.

Upvotes: 1

Related Questions