Martini Managing JDBC Connections
In Martini, database connections are efficiently managed through a connection pool to facilitate reuse across requests. However, it's essential to understand how to handle potential issues like reaching connection limits or encountering leaks.
Connection Pool Management
Each database pool in Martini maintains a maximum number of open connections based on its properties. When this limit is reached or exceeded, it can lead to connection unavailability during runtime.
Detecting Connection Leaks
While Martini attempts to return connections to their pools after use, you may encounter connection leaks under certain circumstances. To monitor JDBC connections for potential leaks, you can enable stacktrace recording upon connection creation.
Monitoring JDBC Connections
To enable stacktrace recording:
- From the Martini Designer menu bar, select
Martini
>Open Logs
. - On the right side, click on
Configure Loggers
. - Set the logger level of
io.toro.martini.database
toDEBUG
. - Use the
getDatabaseConnections
operation from the REST API to query connection metadata.
If io.toro.martini.database
is not present in the list of logger names, you can manually add it by pressing the +
button on the right.
Sample Response
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
This response indicates the existence of an active connection named coder-722795987
from the coder
database pool. It was initiated and opened by the GetEmployees
Gloop service at line 17.
Important Considerations
- Recorded connections are only available after configuring the log level to
DEBUG
. - Previous connections are not returned by the API.
- For immediate tracking, restart the database pool to reset connections.
- Remember to revert the log level after troubleshooting to avoid performance overhead.