no way to determine if a given AsyncMysqlConnection came from the pool
- Dominant language
- C++
- Stars
- 18.7k
- Forks
- 3.1k
- Avg merge
- 1h 47m
- Merged PRs (30d)
- 2
Description
The current API seemingly offers no way for a caller to reliably determine if a given connection returned from `AsyncMysqlConnectionPool->connect()` was recycled from the pool or was actually a new connection.
This makes it difficult to properly instrument our application to determine how effective the pools are being at connection reuse.
I've attempted to work around this in the following ways:
1. Looking at the `elapsedMicros()` that is returned as part of the `AsyncMysqlConnectResult`, we can infer whether the connection came from the pool or not based on how long it took to establish the connection. Some very rough tests showed that it took on the order of 10-20 microseconds when the connection came from the cache, but at least hundreds of microseconds when the connection had to actually be established.
2. The `AsyncMysqlConnectionPool::getPoolStats()` API does return the number of hits vs new connections created, so we could have each connect attempt grab the pool stats before and after the connection, compare the two, and infer from there whether the connection was reused or not. However, since it is possible that multiple async connections could be happening concurrently, this isn't actually thread-safe.
Ideally, the `AsyncMysqlConnectResult` would include a `wasReused()` boolean function to indicate clearly and reliably whether it was a new connection or came from the pool.
Contributor guide
Assessment
This issue has not been assessed yet.