Wednesday Dec 23, 2009

Ping Connection Pool


While a JDBC/Connector Connection pool is created, there was no way of identifying the erroneous values for some of the attributes. With the introduction of a new attribute "ping" in GlassFish V3, its possible to do so. 

An incorrect value of a database connectivity property is another case where pooling infrastructure does not warn the user when pool is created or reconfigured.

For example, if a user tries to set a wrong value for isolation level during creation like :


asadmin create–jdbc–connection–pool ........ ––isolationlevel xyz poolName

The erroneous isolation level is identified only at runtime when the pool is initialized. A get connection from an application following this would throw a WARNING message. This can be identified at an earlier stage by setting a flag like

asadmin create–jdbc–connection–pool ........ ––isolationlevel xyz --ping=true poolName

The default value of this flag is false.

CLI

Ping CLI attribute

GUI

Ping admin console

Notes

The Ping button in admin console as well as the admin CLI command asadmin ping-connection-pool are still supported in GlassFish V3.

[1] Ping CLI Command

Tuesday Dec 22, 2009

Disable Connection Pooling

Connection pooling allows you to reuse connections from a pool
instead of creating a new connection object everytime. If you desire to
turn off the connection pooling in GlassFish V3, there is a new
attribute that could be used.

By default, connection pooling is enabled in both jdbc as well as
connector connection pools. To disable this, set the "pooling" attribute to false.

In the earlier releases of GlassFish, there was a system property called "com.sun.enterprise.Connectors.SwitchoffACCConnectionPooling"
that could be set to true to turn off connection pooling in application
clients. This property is still supported in the new GlassFish V3.

How to set the flag

In administration CLI, use the following :

asadmin set server.resources.jdbc-connection-pool.
           ‹CONNECTION_POOL_NAME›.pooling=false

In admin GUI http://localhost:4848, see the Pooling checkbox.


Pooling in Admin Console

Effects observed

  • Associate with thread functionality is invalid

  • Flush connection pool cannot be done

Attributes useful only in pooled environment

There are a few attributes that are useful only in pooled environment hence a WARNING message is seen in the server.log when they are used.


  • Connection validation

  • Validate Atmost Once (Related to Connection Validation)

  • Match Connections

  • Max Connection Usage

  • Idle Timeout

Thursday Dec 17, 2009

Statement Caching in GlassFish V3


In general, Statement Caching is a functionality of a jdbc driver. There do exist a few jdbc drivers that do not support caching of PreparedStatement, CallableStatement and Statement objects.

A new feature in GlassFish V3, Statement caching improves performance by searching for a match in the cache and returning the object instead of preparing the statement object every time. This is useful for applications that repeatedly execute the above type of statements. Pooling infrastructure in GlassFish V3 does what is depicted in the figure below.


Statement Cache Process


GlassFish V3 uses a Least Recently Used (LRU) strategy for evicting statement objects from the cache. Every time a new statement is parsed and created, there is an overhead and to overcome this, set statementcachesize attribute of jdbc connection pool to a non–zero value.

CLI


Create jdbc connection pool


Statement cache Size in CLI

GUI

Statement cache Size in GUI

Effects of statement caching on pool

When Statement caching is set to a non-negative value, and Flush connection pool is executed, connections in the statement cache are recreated.

Wednesday Dec 16, 2009

JDBC in GlassFish V3

GlassFish V3, the first application server in the world that supports JavaEE6  is released !!!! For the JDBC users, there are some great features introduced in the newest version of GlassFish.


New features


Flush Connection Pool

To reinitialize aged/old connections in a connection pool. There is no need to reconfigure the pool to kill/destroy live connections.

Ping

The existing Ping button in admin console and asadmin ping-connection-pool reveal the unsupported values of configured attributes of a connection pool only at the time of usage (or runtime). A pool configured with "ping" attribute identifies erroneous values at the time of creation of the pool.

java.sql.Driver based Pooling Support

Mainly for applications that use java.sql.Driver  implementations, to configure non-compliant jdbc drivers.

Disable Pooling

Disable connection pooling by just setting a flag "pooling" to false. The existing system property com.sun.enterprise.connectors.SwitchoffACCConnectionPooling was useful only for application clients. This feature is for the non appclient pools.

Statement Caching

Cache Statement, PreparedStatement, CallableStatement objects executed repeatedly by applications to improve performance. Some JDBC drivers do not support caching and this feature comes in handy.

Custom Validation

Specify your own implementation for performing a connection validation. A custom implementation could be made available to the application server and used to perform validation when connection validation is turned ON. Validation routines could be performance oriented or database specific.

Init SQL

Execute a SQL query during connection creation. Mainly to set request/session specific properties.

Introspection of JDBC Drivers

A really useful feature that introspects and lists datasource/driver classnames based on the database vendor and resource type in the administration console. User does not need to remember the classnames anymore for a strange uncommon JDBC driver used with GlassFish.

Tracing SQL Statements

Trace SQL statements executed by your application using a jdbc connection pool. Administrators can filter the server.log for easier SQL statement analyses.


What has changed in GlassFish V3



  • Connection validation method has been defaulted to "table" as the auto–commit and meta–data values are cached by most of the JDBC drivers

  • GlassFish V3 pooling infrastructure will provide wrapped objects for Statement, Prepared/Callable Statement, ResultSet and DatabaseMetaData by default


    • wrap–jdbc–objects defaulted to true


Highlights

  • Monitoring support is provided in GlassFish V3 for JDBC using the new probe provider framework.

  • Smart admin GUI for JDBC leading to easier user administration


    • ex: listing of connection validation table names by introspection

    • ex: listing of jdbc classnames for a particular vendor


More on the above topics (new features) are coming soon. Watch out!

Flush Connection Pool

Re-initialize connections established in the pool without reconfiguration? – Flush Connection Pool is the solution.

This is a new feature in the latest GlassFish V3 that works to recreate the connections in the jdbc connection pool and brings the pool back to the steady pool size. Administrator's work is simplified by just executing the command (CLI) or pressing the Flush button in the GUI.

Effects


  • Live connections are killed/destroyed

  • Existing transactions are lost & hence should be retired

  • Pool brought to steady pool size after flush

Example

max-pool-size set to 5
steady-pool-size set to 5 (5 connections are initialized in the pool when it is created)

We would verify how Flush works based on physical connection IDs

An application that uses the jdbc resource of this connection pool gets 4 connections and closes them everytime in a loop. In this process, the logical connections are closed and returned back to the pool. The physical connection handles [1] for these 4 connections would be the same.

When a Flush is executed after this, the 5 connections that are in the pool are killed and recreated. When a 5th connection is got from the pool, the physical connection handle would be different.

How-Tos

Flush connection pool can be invoked in multiple ways :



Admin Console Flush


Some of the WARNING messages you might encounter when database server is not up or pool is not initialized and Flush is invoked :





References

[1] Obtain physical connection from a Wrapped connection

Tuesday Dec 15, 2009

Custom Validation in GlassFish V3

Connection Validation mechanism in GlassFish has been extended to provide a new type of validation mechanism – Custom Validation. Users can provide their own implementation to validate a connection during each application request.

During times when database server is restarted or a network failure, connections could become stale in the connection pool. When such connections are used by the applications, exceptions are thrown that connection got is invalid. There are types of connection validation mechanisms already existent in GlassFish : autocommit, metadata and table.

The connection-validation-method attribute can be set to custom-validation. This validation mechanism could could aid users to implement faster validation routines. If connection validation fails, pooling infrastructure will return the next valid connection or create a new connection to return to the application.

GlassFish provides a public interface org.glassfish.api.jdbc.ConnectionValidation for the users to implement and provide value to an attribute validation-classname.

Setting Custom Validation

Turn on Validation, set validation type to custom-validation and set an appropriate implementation class with the entire package name to validation-classname.


Turn on validation


Set to custom-validation


Set validation classname

In Admin console (http://localhost:4848) Connection validation settings can be made in the advanced tab.

Custom Validation mechanisms in GF

There are some default validation mechanisms provided by GlassFish for the users to use for certain databases. These are listed in the admin console against the validation classname field.


  • org.glassfish.api.jdbc.validation.DerbyConnectionValidation

  • org.glassfish.api.jdbc.validation.MySQLConnectionValidation

  • org.glassfish.api.jdbc.validation.PostgresConnectionValidation

  • org.glassfish.api.jdbc.validation.OracleConnectionValidation


There is also a generic validation implementation provided for jdbc 4.0 compliant drivers


  • org.glassfish.api.jdbc.validation.JDBC40ConnectionValidation

References

[1] Connection Validation in GlassFish

About

shalini_m

Search

Categories
Archives
« December 2009 »
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
18
19
20
21
24
25
26
27
28
29
30
31
  
       
Today