Demo : Application Scoped Resources and JDBC Monitoring

Team

Jagadish Ramu, Shalini Muthukrishnan

Demo

This includes demonstration of

Application-Scoped-Resources

  • Setup :
    1. Install GF 3.1 MS4 promoted build
    NOTE : For preserveAppScopedResources flag of application-scoped-resources to work, use
    latest nightly build 23-Aug-10 onwards
    or
    latest gf-hudson build
    2. unzip glassfish.zip
    3. export S1AS_HOME="glassfish-installation-directory" (i.e. /space/glassfish31b16/glassfish)
    4. svn checkout -N https://svn.java.net/svn/glassfish-svn/trunk/v2/appserv-tests
    5. cd appserv-tests
    6. export APS_HOME="appserv-tests directory"
    7. edit config.properties and change "admin.password=adminadmin" property to be "admin.password="
    8. svn checkout https://svn.java.net/svn/glassfish-svn/trunk/v2/appserv-tests/config
    8a. svn checkout https://svn.java.net/svn/glassfish-svn/trunk/v2/appserv-tests/lib
    9. mkdir -p devtests
    10. cd devtests
    11. svn checkout -N https://svn.java.net/svn/glassfish-svn/trunk/v2/appserv-tests/devtests/connector
    12. cd connector
    13. svn checkout https://svn.java.net/svn/glassfish-svn/trunk/v2/appserv-tests/devtests/connector/config
    14. mkdir v3
    15. cd v3
    16. svn checkout https://svn.java.net/svn/glassfish-svn/trunk/v2/appserv-tests/devtests/connector/v3/app-scoped-resources-ms4-demo
    17. cd app-scoped-resources-ms4-demo
    18. $S1AS_HOME/bin/asadmin start-domain domain1
    19. $S1AS_HOME/bin/asadmin start-database
    20. Build and setup the dev-test :
    ant enable-monitoring init-common build setup setup-map
    21. List the applications deployed in the server.
    $S1AS_HOME/bin/asadmin list-applications
    generic-ra <connector>
    app-scoped-resourcesApp <ear, ejb, web>

    22. Use the new flag "--resources" to list application scoped resources (with prefix "java:app") per application as follows

    $S1AS_HOME/bin/asadmin list-applications --resources
    generic-ra <connector>
      java:app/generic-ra-groups-map	<WorkSecurityMap>
      java:app/generic-ra-principals-map	<WorkSecurityMap>
    app-scoped-resourcesApp <ear, ejb, web>
      java:app/jdbc/app-level-ds	<JdbcResource>
      java:app/jdbc/XAPointbase	<JdbcResource>
      java:app/jdbc/app-level-pool	<JdbcConnectionPool>
      java:app/jdbc-pointbase-pool1	<JdbcConnectionPool>

    23. Use the new flag "--subcomponents" to list sub-components in each application

    $S1AS_HOME/bin/asadmin list-applications --subcomponents
    generic-ra <connector>
    app-scoped-resourcesApp <ear, ejb, web>
      app-scoped-resources-ejb.jar <EJBModule>
      app-scoped-resources-web.war <WebModule>

    24. Use both the new flags "--resources" and "--subcomponents" to list subcomponents and resources at application level as well module level (with prefix "java:module")

    $S1AS_HOME/bin/asadmin list-applications --resources --subcomponents
    generic-ra <connector>
      java:app/generic-ra-groups-map	<WorkSecurityMap>
      java:app/generic-ra-principals-map	<WorkSecurityMap>
    app-scoped-resourcesApp <ear, ejb, web>
      java:app/jdbc/app-level-ds	<JdbcResource>
      java:app/jdbc/XAPointbase	<JdbcResource>
      java:app/jdbc/app-level-pool	<JdbcConnectionPool>
      java:app/jdbc-pointbase-pool1	<JdbcConnectionPool>
      app-scoped-resources-ejb.jar <EJBModule>
        java:module/jdbc/ejb-level-ds	<JdbcResource>
        java:module/jdbc/monitoring-ds	<JdbcResource>
        java:module/eis/testAdmin	<AdminObjectResource>
        java:module/jdbc/ejb-level-pool	<JdbcConnectionPool>
        java:module/jdbc/monitoring-pool	<JdbcConnectionPool>
      app-scoped-resources-web.war <WebModule>
        java:module/jdbc/monitoring-ds	<JdbcResource>
        java:module/jdbc/web-level-ds	<JdbcResource>
        java:module/jdbc/web-level-pool	<JdbcConnectionPool>
        java:module/jdbc/monitoring-pool	<JdbcConnectionPool>

    25. Make sure that the pool configuration of "java:module/jdbc/monitoring-pool of "ejb-module" and "web-module" are valid by doing "ping-connection-pool" with new flags to specify "appname" and "modulename"

    $S1AS_HOME/bin/asadmin ping-connection-pool --appname app-scoped-resourcesApp --modulename app-scoped-resources-ejb.jar java:module/jdbc/monitoring-pool
    
    Command ping-connection-pool executed successfully.
    $S1AS_HOME/bin/asadmin ping-connection-pool --appname app-scoped-resourcesApp --modulename app-scoped-resources-web.war java:module/jdbc/monitoring-pool
    
    Command ping-connection-pool executed successfully.

    26. To execute the test case :
    ant runtest
    27. Once the test is executed, connection pools will be initialized and used.
    Use the new monitoring hierarchy to check the monitoring information for connection pools of "ejb-module" and "web-module"

    $S1AS_HOME/bin/asadmin get --monitor=true server.applications.app-scoped-resourcesApp.* | grep -i "monitoring-pool" | grep -i "\-count" 
    server.applications.app-scoped-resourcesApp.app-scoped-resources-ejb.jar.resources.java:module.jdbc.monitoring-pool.averageconnwaittime-count = 3
    server.applications.app-scoped-resourcesApp.app-scoped-resources-ejb.jar.resources.java:module.jdbc.monitoring-pool.numconnacquired-count = 5
    server.applications.app-scoped-resourcesApp.app-scoped-resources-ejb.jar.resources.java:module.jdbc.monitoring-pool.numconncreated-count = 8
    server.applications.app-scoped-resourcesApp.app-scoped-resources-ejb.jar.resources.java:module.jdbc.monitoring-pool.numconndestroyed-count = 0
    server.applications.app-scoped-resourcesApp.app-scoped-resources-ejb.jar.resources.java:module.jdbc.monitoring-pool.numconnfailedvalidation-count = 0
    server.applications.app-scoped-resourcesApp.app-scoped-resources-ejb.jar.resources.java:module.jdbc.monitoring-pool.numconnnotsuccessfullymatched-count = 0
    server.applications.app-scoped-resourcesApp.app-scoped-resources-ejb.jar.resources.java:module.jdbc.monitoring-pool.numconnreleased-count = 5
    server.applications.app-scoped-resourcesApp.app-scoped-resources-ejb.jar.resources.java:module.jdbc.monitoring-pool.numconnsuccessfullymatched-count = 0
    server.applications.app-scoped-resourcesApp.app-scoped-resources-ejb.jar.resources.java:module.jdbc.monitoring-pool.numconntimedout-count = 0
    server.applications.app-scoped-resourcesApp.app-scoped-resources-ejb.jar.resources.java:module.jdbc.monitoring-pool.numpotentialconnleak-count = 0
    server.applications.app-scoped-resourcesApp.app-scoped-resources-ejb.jar.resources.java:module.jdbc.monitoring-pool.waitqueuelength-count = 0
    
    server.applications.app-scoped-resourcesApp.app-scoped-resources-web.war.resources.java:module.jdbc.monitoring-pool.averageconnwaittime-count = 1
    server.applications.app-scoped-resourcesApp.app-scoped-resources-web.war.resources.java:module.jdbc.monitoring-pool.numconnacquired-count = 10
    server.applications.app-scoped-resourcesApp.app-scoped-resources-web.war.resources.java:module.jdbc.monitoring-pool.numconncreated-count = 10
    server.applications.app-scoped-resourcesApp.app-scoped-resources-web.war.resources.java:module.jdbc.monitoring-pool.numconndestroyed-count = 0
    server.applications.app-scoped-resourcesApp.app-scoped-resources-web.war.resources.java:module.jdbc.monitoring-pool.numconnfailedvalidation-count = 0
    server.applications.app-scoped-resourcesApp.app-scoped-resources-web.war.resources.java:module.jdbc.monitoring-pool.numconnnotsuccessfullymatched-count = 0
    server.applications.app-scoped-resourcesApp.app-scoped-resources-web.war.resources.java:module.jdbc.monitoring-pool.numconnreleased-count = 10
    server.applications.app-scoped-resourcesApp.app-scoped-resources-web.war.resources.java:module.jdbc.monitoring-pool.numconnsuccessfullymatched-count = 0
    server.applications.app-scoped-resourcesApp.app-scoped-resources-web.war.resources.java:module.jdbc.monitoring-pool.numconntimedout-count = 0
    server.applications.app-scoped-resourcesApp.app-scoped-resources-web.war.resources.java:module.jdbc.monitoring-pool.numpotentialconnleak-count = 0
    server.applications.app-scoped-resourcesApp.app-scoped-resources-web.war.resources.java:module.jdbc.monitoring-pool.waitqueuelength-count = 0

    28. In order to flush the existing connections in the pool, use the command "flush-connection-pool" and new flags "appname" and "modulename"

    $S1AS_HOME/bin/asadmin flush-connection-pool --appname app-scoped-resourcesApp --modulename app-scoped-resources-web.war java:module/jdbc/monitoring-pool
    
    Command flush-connection-pool executed successfully.
    $S1AS_HOME/bin/asadmin flush-connection-pool --appname app-scoped-resourcesApp --modulename app-scoped-resources-ejb.jar java:module/jdbc/monitoring-pool
    
    Command flush-connection-pool executed successfully.

    29. To disable the application :
    ant disable-app
    This will disable the application and unregister the application-scoped and module-scoped resources and connection-pools of the application.
    30. ping-connection-pool and flush-connection-pool will fail indicating that the application is disabled.

    $S1AS_HOME/bin/asadmin ping-connection-pool --appname app-scoped-resourcesApp --modulename app-scoped-resources-web.war java:module/jdbc/monitoring-pool
    remote failure: Application [ app-scoped-resourcesApp ] in which the pool [java:module/jdbc/monitoring-pool ] is defined, is not enabled.
    
    Command ping-connection-pool failed.
    $S1AS_HOME/bin/asadmin flush-connection-pool --appname app-scoped-resourcesApp --modulename app-scoped-resources-ejb.jar java:module/jdbc/monitoring-pool
    remote failure: Application [ app-scoped-resourcesApp ] in which the pool [java:module/jdbc/monitoring-pool ] is defined, is not enabled.
    
    Command flush-connection-pool failed.

    31. To enable the application :
    ant enable-app
    32. Resources or Pools configuration can be obtained using dotted-names-get

    $S1AS_HOME/bin/asadmin get applications.application.app-scoped-resourcesApp.resources.jdbc-connection-pool.java:app/jdbc/app-level-pool.max-pool-size
    applications.application.app-scoped-resourcesApp.resources.jdbc-connection-pool.java:app/jdbc/app-level-pool.max-pool-size=32

    33. Set the max-pool-size of one of the pools to 500 :

    $S1AS_HOME/bin/asadmin set applications.application.app-scoped-resourcesApp.resources.jdbc-connection-pool.java:app/jdbc/app-level-pool.max-pool-size=500
    applications.application.app-scoped-resourcesApp.resources.jdbc-connection-pool.java:app/jdbc/app-level-pool.max-pool-size=500
    
    Command set executed successfully.

    34. In production environments, it is possible that the resource or pool configuration would have been tuned according to the application's usage.
    During application re-deploy (binary updates), it is possible to preserve the tuned resources configuration by using the new property "preserveAppScopedResources=true".

    $S1AS_HOME/bin/asadmin deploy --force=true --properties preserveAppScopedResources=true $APS_HOME/build/module/archive/app-scoped-resourcesApp.ear
    Application deployed successfully with name app-scoped-resourcesApp.

    35. Check whether the old pool configuration is preserved after application re-deploy as :

    $S1AS_HOME/bin/asadmin get applications.application.app-scoped-resourcesApp.resources.jdbc-connection-pool.java:app/jdbc/app-level-pool.max-pool-size
    applications.application.app-scoped-resourcesApp.resources.jdbc-connection-pool.java:app/jdbc/app-level-pool.max-pool-size=500

    36. To undeploy the application :
    ant unset unset-map
    37. Stop the server and database :
    $S1AS_HOME/bin/asadmin stop-domain domain1
    $S1AS_HOME/bin/asadmin stop-database

JDBC Monitoring features

1. Install GF 3.1 MS4 promoted build
http://javaweb.sfbay.sun.com/java/re/glassfish/3.1/promoted/b16/archive/bundles/latest-glassfish.zip
NOTE : For preserveAppScopedResources of application-scoped-resources to work, use latest nightly build 23-Aug-10 onwards
or
latest gf-hudson build http://gf-hudson.sfbay/hudson/job/gf-trunk-build-continuous/lastSuccessfulBuild/artifact/bundles/glassfish.zip
1a. unzip glassfish.zip
2. Start domain
glassfishv3/glassfish/bin/start-domain domain1
3. Start up database
glassfishv3/glassfish/bin/start-database
4. export APS_HOME=<appserv-tests>
5. export S1AS_HOME=glassfishv3/glassfish
6. export ANT_HOME=<ant home>
7. export PATH=$ANT_HOME/bin:$S1AS_HOME/bin:$PATH

Statement cache hit/miss monitoring :

Demo of the number of statement cache hits and misses observed for the jdbc connection pool. The statement cache hit and miss scenario is simulated by the following testcase :

9. Checkout the following :

The test case does the following :
a) Creates a jdbc connection pool and jdbc resource. Sets the value of statement-cache-size attribute to 5
b) Sets server.monitoring-service.module-monitoring-levels.jdbc-connection-pool=HIGH
c) Deploys an application that gets a connection and prepares 6 statements out of which the first and last have the same SQL query. Similarly a series of tests are executed for hits and misses to the statement cache.

The number of hits after executing the application is 8 and number of misses is 17.

10. APS_HOME/devtests/jdbc/stmtCaching_hit_miss.monitoring/ant build deploy run -> executes the test case.
11. The monitoring statistics numstatementcachehit and numstatementcachemiss can be observed by executing

asadmin get -m server.resources.jdbc-stmtcaching_hit_miss-pool.numstatementcachehit-count
server.resources.jdbc-stmtcaching_hit_miss-pool.numstatementcachehit-count = 8
asadmin get -m server.resources.jdbc-stmtcaching_hit_miss-pool.numstatementcachemiss-count
server.resources.jdbc-stmtcaching_hit_miss-pool.numstatementcachemiss-count = 17

12. APS_HOME/devtests/jdbc/stmtCaching_hit_miss.monitoring/ant undeploy -> Undeploy the test case.

Statement leak trace monitoring

Monitoring the number of statement leaks (number of statements not closed by applications before the statement leak timeout) for the specified jdbc connection pool. statement-leak-timeout-in-seconds attribute of a jdbc connection pool is to be set to a non-zero value, say 10.

When applications using the jdbc connection pool fail to close the statement objects within 10 seconds, the statement is classified as a leaked object.

13. Checkout the following :

The test case does the following :
a) Creates a jdbc connection pool and jdbc resource. Sets the value of statement-leak-timeout-in-seconds attribute to 3
b) Sets server.monitoring-service.module-monitoring-levels.jdbc-connection-pool=HIGH
c) Deploys an application that gets a statement and forgets to close this statement. This is done for Statement/PS/CS objects. 2 statements are got for each type and hence the total leaks observed would be 6.

14. APS_HOME/devtests/jdbc/statementleakdetection/ant build deploy run -> executes the test case.

15. Monitoring statistic numpotentialstatementleak can be observed by executing

asadmin get -m server.resources.ql-jdbc-pool.numpotentialstatementleak-count
server.resources.ql-jdbc-pool.numpotentialstatementleak-count = 6

16. APS_HOME/devtests/jdbc/statementleakdetection/ant undeploy -> Undeploy the test case.

Other new features (non-demo)

Sql Trace Monitoring :

To list the top n queries that are frequently used by applications for a specific jdbc connection pool in a specific time window.

a) Properties number-of-top-queries-to-report and time-to-keep-queries-in-minutes can be set on a jdbc connection pool to configure.
b) Default values of these properties are 10 and 5 minutes.

As per the default values, the top 10 queries used by applications in the last 5 minutes are got using the monitoring statistic : frequsedsqlqueries.

Monitoring Statistic can be observed by executing :

asadmin get -m server.resources.ql-jdbc-pool.frequsedsqlqueries-current

Monitoring grouped by applications

Monitoring statistics numconnused, numconnacquired and numconnreleased can be observed grouped by applications.

a) Application1 and Application2 using the same jdbc/connector connection pool could get different number of connections from the pool.

asadmin get -m server.resources.testPool.application1.numconnused-current
asadmin get -m server.resources.testPool.application1.numconnreleased-count
asadmin get -m server.resources.testPool.application2.numconnreleased-count
asadmin get -m server.resources.testPool.application1.numconnacquired-count
asadmin get -m server.resources.testPool.application2.numconnacquired-count

asadmin get -m server.resources.testPool.numconnreleased-count -> Total number of connections released to the pool.