[Java] Monitoring WaitQueue size

Micrometer is a metrics library that provides some support for MongoDB. I’m migrating Micrometer to use the latest java driver (from 3.x to 4.x, org.mongodb:mongodb-driver-sync).

One of the metrics that Micrometer provides for MongoDB is the size of the wait queue (this information seems to be useful for the users). The instrumentation is implemented through the ConnectionPoolListener, see MongoMetricsConnectionPoolListener. Since the ConnectionPoolWaitQueueEnteredEvent and the ConnectionPoolWaitQueueExitedEvent were removed in 4.x, we are not able to provide this metric that easily with 4.x.

ConcurrentPool has public methods to track this (getCount, getInUseCount, getAvailableCount) but its interface does not and getting a reference could also be tricky.

Is there a recommended way to track the wait queue size using the latest java driver (4.x)?

The closest approximation would be to consider ConnectionCheckOutStartedEvent as entering the wait queue and either ConnectionCheckedOutEvent or ConnectionCheckOutFailedEvent as leaving the wait queue. The only difference is that the time between those events will include, in the event that a pooled connection is not available, the time spent opening a new connection and completing the connection handshake.

Regards,
Jeff

2 Likes

Thank you very much, this makes sense, we implemented the queue size tracking the way you suggested.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.