HP NonStop JDBC Type 4 Driver November 22, 2004 Author: Ken Sell 1 Introduction Java applications and application environments continue to play an important role in software system development. Database access accounts for a significant portion of the time and resources used by many Java programs. As database access grows, its impact on the overall performance of an application grows as well. This document contains tips for optimizing performance when using the HP NonStop JDBC Type 4 Driver, version 1.0. 2 Overview The NonStop JDBC Type 4 Driver is one of several components that are used in accessing an HP NonStop SQL/MX database. Although this document focuses on the Type 4 driver component specifically, it also talks about other related components where applicable, such as the NonStop SQL Connectivity Service (MXCS). Optimizing performance can have many meanings, including: CPU usage on the client system (PC, HP-UX, etc.) Memory usage on the client system CPU usage on the HP NonStop server system Memory usage on the server system Throughput (number of transactions per second) Response time (the time it takes for the client application to respond) Furthermore, the meaning of performance can vary when the scalability of a system is considered. When applicable, this document indicates any negative impact that a performance improvement might have on the scalability of an application. Page 1 Hewlett-Packard Company 529619-001 November 29, 2004
3 NonStop JDBC Type 4 Driver Tuning Tips 3.1 Configuration Tips Connection pooling. Use connection pooling either explicitly with your own implementation, the Type 4 driver connection pooling mechanism (the default is no connection pooling) or implicitly through a product that supports connection pooling, such as BEA Weblogic Server, or IBM WebSphere, etc. Maximum pool size. Use the maxpoolsize and minpoolsize properties to tune the connection pool. o The default maxpoolsize is 0 unlimited pool size. o The default minpoolsize is 0 connections are never physically closed but are added to the connection pool. o Set minpoolsize to the anticipated number of connections to be used. For example, set minpoolsize to the number of application threads. Statement pooling. Set the maxstatements property to enable statement pooling (the default is no statement pooling). For example, SQLMXDataSource.setMaxStatements(100). Logging. Turn off logging. Set the t4loglevel property to OFF (the default is OFF). Set the DriverManager.setLogWriter() and/or DataSource.setLogWriter() methods to null (the default is null). Heap manager. Increase or decrease the Java virtual machine (JVM) heap size to balance performance versus memory usage. The Type 4 driver creates objects that must be garbage collected by the JVM. For additional information on JVM heap optimization, see the Tuning Garbage Collection with the 1.4.2 Java Virtual Machine at http://java.sun.com/docs/hotspot/gc1.4.2/ and Turbo-charging Java HotSpot Virtual Machine, v1.4.x to Improve the Performance and Scalability of Application Servers at http://java.sun.com/developer/technicalarticles/programming/turbo/. 3.2 Design and Programming Tips Do not use the same connection simultaneously in different threads. The connection s operations will be serialized. Use different connections with different threads to get parallel execution. Use the same connection to execute multiple statements. Closing and reopening a connection can be very costly. When using connection pooling, avoid setting the connection s catalog, schema, transaction isolation, and autocommit attributes programmatically at Page 2 Hewlett-Packard Company 529619-001 November 29, 2004
run time. Set these values appropriately with your data source properties. Note: theses properties are not reset when a connection is pooled. Use prepared statements (PreparedStatement class), and parameterize its arguments. Avoid retrieving unnecessary columns: don't use "SELECT *". Turn off autocommit when possible (the default is on). All transaction levels might operate faster with autocommit turned off, although using this setting requires you to code commits. Leave autocommit on for single statements. Avoid repeatedly calling expensive database query functions such as: getbestrowidentifier; getcolumns, getcrossreference, get ExportedKeys, getimportedkeys, getprimarykeys, gettables, and getversioncolumns. If possible, call these functions once, and cache the returned data. Use the type-correct get() method, rather than getobject(). Always close Statement and ResultSet objects as soon as possible. Use BROWSE (READ UNCOMMITTED) access on SQL statements when possible. 4 MXCS Tuning Tips Use a non-default server data source when making a connection, and configure the data source to optimize performance for your environment. See the serverdatasource property in the NonStop JDBC Type 4 Driver Programmer s Reference manual, and server data source in the SQL/MX Connectivity Service Manual. 5 Database Tuning Tip See the SQL/MX Query Guide. Safeguard supports multiple alias and password pairs for a single Guardian user name. Using these aliases or password pairs can improve performance because object caching reuses the underlying user name. You can set up an anonymous log-in capability by adding a user name such as guest with no password; then map this user name to a user group that has limited access to the SQL objects. Page 3 Hewlett-Packard Company 529619-001 November 29, 2004
Tune the priority of the processes such as DP2, SQL/MX Compiler, SQL/MX Executor. See the Mixed Workload Design Priority Guidelines white paper in the NonStop Technical Library for additional information. Use the CONTROL TABLE <table-name> PRIORITY <priority> SQL/MX control table statement to tune the priority for subsequent file system requests to the Data Manager (DAM). See the SQL/MX Reference Manual for additional information. 6 Hardware considerations Use the fastest Ethernet possible on the NonStop system. The 100-megabitper-second operation offered by the HP 3863 Fast Ethernet ServerNet adapter (FESA) on the NonStop system is recommended. 7 TCP/IP Configuration Set the DATAFORWARDCOUNT and DATAFORWARDTIMER SLSA subsystem values to 1. For additional information, see the LAN Configuration and Management Manual. 8 Performance Measuring Tools Several excellent performance measuring tools are available for analyzing the impact of accessing a SQL/MX database through the Type 4 driver, including: HPjmeter - HPjmeter is a free 100% pure Java tool for analyzing profiling information generated by the JVM. HPjmeter runs on the HP-UX, Solaris, Windows, and Linux platforms. HPjmeter allows you to measure many aspects of your JVM (CPU usage per method, memory usage, etc.). You can download HPjmeter from http://www.hp.com/products1/unix/java/hpjmeter/ Perfmon - Perfmon is available in the Windows environment and allows you to open a performance console and monitor CPU, memory, and thread usage. For more information, see the Microsoft website at http://www.microsoft.com Page 4 Hewlett-Packard Company 529619-001 November 29, 2004
Measure - The Measure performance monitor is available on NonStop systems. Measure is a data collection and measurement tool that provides a wide range of performance statistics on system resources. You can use the Measure performance monitor to gather information about SQL/MX Connectivity Services (MXCS) CPU and memory usage. For more information, see the Measure User s Guide. 8.1 Tool Usage Examples 8.1.1 HPjmeter Run a program (test.testmanythreads), enabling output of performance information (-Xeprof). Note: the -Xeprof Java option is available on HP-UX systems. The Xprof option is available with most other Java implementations and provides similar profiling data. java -Xeprof test.testmanythreads A file containing profiling data is produced. java10275.eprof Invoke HPjmeter, and open the profiling data file. Under Metric, choose Inclusive Method Times (CPU), The following chart is shown. Page 5 Hewlett-Packard Company 529619-001 November 29, 2004
Note that a large amount of time is spent in com.tandem.t4jdbc.sqlmxpreparedstatement.execitequery() (executing the query). This indicates a good place to look for optimization. For example, you might improve your query s performance by using recommendations in the SQL/MX Query Guide. Page 6 Hewlett-Packard Company 529619-001 November 29, 2004