Monitoring the Connection Pool


We've spent all our time looking at how to create the datasource, but we haven't mentioned how you can interact with the underlying connection pool during the life of your application. You need to set up the datasource only once, but your application will use it every day. In this lab we will find the connection pool and see how to interact with its management interface to monitor and tune it.

How do I do that?

Each datasource declared in a ds.xml file translates into several MBeans that you can interact with in the JMX Console. All the datasource-related objects are in the jboss.jca domain. You can find them by searching through the JMX Console page, or by using jboss.jca:* as the query filter.

This is enough of a filter to spot the items related to the MySQL datasource, but you could use a more specific filter, such as jboss.jca:name=MySqlDS,*, to see only the MySQL entries. In either case, four MBeans will be related to the MySQL datasource:

  • name=MySqlDS,service=DataSourceBinding

  • name=MySqlDS,service=LocalTxCM

  • name=MySqlDS,service=ManagedConnectionFactory

  • name=MySqlDS,service=ManagedConnectionPool

While each plays a critical role in providing the datasource functionality in JBoss, you are most likely to need to interact with the connection pool. Click the connection pool MBean to expose the management attributes and operations.

The mysql-ds.xml file we've been using specified a minimum connection pool size of 2 and a maximum pool size of 10. You'll see those values reflected in the MinSize and MaxSize attributes. You can change the values in the running server by adjusting the values and clicking Apply Changes.

Setting the values here affects the connection pool only in memory. To change the configuration permanently, update the mysql-ds.xml file. Try setting the pool sizes there. When you save the file, JBoss will redeploy the datasource and the new pool sizes will be displayed when you reload the page.

You might occasionally want to adjust the pool size to account for usage; you are more likely to be curious how much of the connection pool is being used. The ConnectionCount attribute shows how many connections are currently open to the database. However, open connections are not necessarily in use by application code. The InUseConnectionCount attribute shows how many of the open connections are in use. Viewing the statistic from the other direction, AvailableConnectionCount shows how much room is left in the pool.

Finally, the MBean has several statistics that track connection pool usage over the pool's lifetime. ConnectionCreatedCount and Connection-DestroyedCount keep running totals of the number of connections created and destroyed by the pool. If IdleTimeout is greater than 0, connections will eventually timeout, be destroyed, and be replaced by fresh connections. This will cause the created and destroyed counts to rise constantly. The MaxConnectionsInUseCount attribute keeps track of the highest number of connections in use at a time.

If you notice anything awkward in the connection pool, or you just want to reset the statistics, you can flush the connection pool using the flush operation on the MBean. This will cause a new connection pool to be created, abandoning the previous connection pool.

What just happened?

You've seen a whole set of attributes that will prove invaluable when you need to understand how an application is using its database connections. All the MBean attributes are visible through the JMX management tool of your choice. We've used the JBoss JMX Console in this lab, but other options exist.


Note: We will use some of the more advanced monitoring and alerting features of the web console in Chapter 8.

To give you a taste of what you can do, Figure 4-2 shows a graph of the ConnectionCount attribute over a short, 10-minute time period that we used the ToDo application. The graph was created by the JBoss Web Console application, the GUI companion to the JMX Console we've been using.

Developer's Notebook 4-2. A graph of a datasource connection count




JBoss. A Developer's Notebook
JBoss: A Developers Notebook
ISBN: 0596100078
EAN: 2147483647
Year: 2003
Pages: 106

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net