4

I need to monitor my application performance and its use of database connections. The application, an ASP.NET Core 2.2 app, uses Entity Framework Core 2.x and a PostgreSQL database server with Npgsql. All of that runs in production on Ubuntu Linux, development is with Visual Studio on Windows 10. Connection pooling is activated and a maximum pool size is set in the connection string.

How can I find out how many connections are currently in the pool, and is there additional data available about how much the pool is used (min/max active connections, wait time etc.)?

I've read about Performance Counters in ADO.NET (via this question) but that seems to apply to Windows only and may not be supported by .NET Core.

ygoe
  • 18,655
  • 23
  • 113
  • 210
  • Did you ever figure out a way to do this? – mikesigs Aug 13 '20 at 23:44
  • @mikesigs No. I added some counters in interesting places so that I know how many connections (probably rather: DbContexts) are used for a certain purpose, but the total number is still unclear. I guess it's not possible so production will have to react to errors rather than being able to monitor this properly. – ygoe Aug 14 '20 at 08:05
  • I hope this bumps the comment. I get an error, that's pretty generic, and it would be useful to determine which of the one is failing. `Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.` Okay, which one is it. It seems impossible to tell. – christopher clark Oct 13 '20 at 19:39
  • @christopherclark Which one is *what*? To me, this looks like you've set a pool max size and wanted to use one more connection than that, but all others are busy with long-running work, or you just have so many requests that some will not be satisfied in time. Look where the exception is thrown and you know where it comes from. But it may be random. – ygoe Oct 14 '20 at 10:23
  • 1
    I came here with pretty much the same question -- we are using connection pooling in a Linux docker container, and the SQL connection works for awhile, and then decides to stop working and never comes back from that point on. – Jarvis Apr 26 '21 at 14:17
  • Hi @Jarvis, I'm having the same problem - did you figure out a solution to this? – Dirk Boer Jun 12 '21 at 21:07
  • Not exactly. Ended up injecting a DBContextFactory instead of the singleton DBContext itself, and now we new/dispose one every time. – Jarvis Jun 15 '21 at 12:36

0 Answers0