elixir-ecto / db_connection

Database connection behaviour
http://hexdocs.pm/db_connection/DBConnection.html
306 stars 113 forks source link

Insight into number of idle connections #209

Closed hkrutzer closed 4 years ago

hkrutzer commented 4 years ago

We have telemetry for queue time which is very helpful, and we can increase the size of the connection pool based on this data. However, decreasing the amount of connections is still trial-and-error. It would be nice if there was a way to see how many connections are idle at a given time. We can then poll this every second or so, and be more confident about changing the pool size.

josevalim commented 4 years ago

I think polling to see if it is idle or not will be ultimately imprecise. Perhaps it is better to measure the time since last check-in and emit those as part of the existing telemetry events as idle time.

So the idea is, as soon you as checkin, you get the current time, then when you checkout and we are logging, you get the current time and emit the difference as idle time.

josevalim commented 4 years ago

Closing in favor of #210.

hkrutzer commented 4 years ago

You are very quick :) I don't know if current active connections would be too imprecise but your approach will definitely be more precise. Thanks!

hkrutzer commented 4 years ago

So when rethinking this... If I have 100 connections and 20 are idle at all times, so I can safely lower the connection count by at least 15, I still have to lower the count by trial and error after adding the idle_time statistic.