6

TLDR: Is there a way to control connection pools in AspNet Core / EF CORE Sql connections. I need something similar to this:

pool: {
    min: 0,
    max: 1,
    idle: 10000
}  

The Problem:

I have a serverless api built with AspNetCore 3.1 using EF core for data access. All works fine when the server is not under heavy load. But when we get just moderate amount of requests we run out of connections to the SQL server. Because they are not released. The database is under no stress. CPU / RAM / IO are all still "sleeping" and having no trouble keeping up with the requests.

After spending some time reading up on the problem I found 2 solutions

  • A) Upgrade database to allow for more connections
  • B) Reduce Idle time for connections and min/max connections

I don't really like options A since we already have a big instance that already now is to big for it's purpose. Don't really need more CPU/RAM wasted

So my only real options is trying to gain access to the connection pool.

My Google mojo hasn't really gotten me far and I haven't been able to find anything in the public spec. All I find is oldschool ADO.NET from blogs posts ages ago. And some few blog posts that just states the connection pooling in EF Core is magic and don't worry about it. I never have worried about it until now in a serverless enviroment.

Would really hate if we had to go away from EF Core, since it would be a major rewrite of the app.

1 Answer 1

8

If you're using SQL server, then that needs to be handled by the Min Pool Size, Max Pool Size, and Connection Lifetime parameters in your connection string. I'm not seeing a direct way to configure idle timeout, but the connection lifetime should provide a good proxy.

If you're using postgres via npgsql, their connection string parameters would be Minimum Pool Size, Maximum Pool Size, and Connection Idle Lifetime.

I'd expect other providers to have similar options, but it looks like connection pooling isn't handled at the general EFCore-level.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.