db_connection icon indicating copy to clipboard operation
db_connection copied to clipboard

Add metrics for connection pool usage

Open peixian opened this issue 1 year ago • 6 comments

This PR adds support for a DBConnection.ConnectionPool.get_metrics() function that returns the current state of active and waiting connections, to allow upstream callers to gain some visibility on their database usage. We're using a form of this in our internal forks.

peixian avatar Aug 10 '23 20:08 peixian

Hi @peixian! This looks good to me but I would consider using :counters instead, so we can read them decentralized. We would also need tests. :)

josevalim avatar Aug 11 '23 08:08 josevalim

counters is such a good idea for this 👏

whatyouhide avatar Aug 11 '23 09:08 whatyouhide

@josevalim I'll change it to counters. For tests, it appears that the tests are by default already broken? I didn't add onto it because I wasn't sure what the state of tests are.

For example:

 ~/c/db_connection_master (master)> git log | head                                                                                             
commit 022393b7895f5bd3a7e884a35c7590f4fa549986
Author: Andrea Leopardi <[email protected]>
Date:   Thu Jul 27 18:33:49 2023 +0200

    Add DBConnection.available_connection_options/0 (#291)
    
    
~/c/db_connection_master (master) [2]> mix test .     
.......
Finished in 1.7 seconds (1.7s async, 0.00s sync)
202 tests, 32 failures
    

peixian avatar Aug 11 '23 11:08 peixian

Instead of mix test ., please do mix test.all.

Also, when a new connection is started, it always checks itself in once ready to use, so you need to take that into account.

josevalim avatar Aug 11 '23 16:08 josevalim

@josevalim this is good for re-review, I've got all the tests passing and added a few.

peixian avatar Aug 15 '23 17:08 peixian

@josevalim I'm interested in this feature. What's the current status? Any help required?

romul avatar Mar 14 '24 11:03 romul