Follow

HikariCP Migration Changes Report

Summary of Changes

This document details all changes made to migrate the Vitec application from Tomcat's built-in JDBC connection pool to HikariCP for improved performance.

Files Modified

1. /conf/context.xml

Backup location: /backup_before_hikari/context.xml.backup

Key Changes:

  • Replaced Tomcat JDBC pool factory with HikariCP factory
  • Changed pool configuration parameters to HikariCP format
  • Added SQL Server-specific performance optimizations
  • Added connection leak detection for development/testing

Before (Tomcat JDBC Pool):

<Resource name="jdbc/VitecDB"
          factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
          driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
          url="jdbc:sqlserver://..."
          username="..."
          password="..."
          initialSize="50"
          maxActive="100"
          maxIdle="21"
          minIdle="13"
          defaultAutoCommit="false"
          .../>

After (HikariCP):

<Resource name="jdbc/VitecDB"
          factory="com.zaxxer.hikari.HikariJNDIFactory"
          dataSourceClassName="com.microsoft.sqlserver.jdbc.SQLServerDataSource"
          minimumIdle="20"
          maximumPoolSize="100"
          autoCommit="false"
          dataSource.serverName="10.10.192.55"
          dataSource.portNumber="1433"
          .../>

2. /webapps/vitec/WEB-INF/classes/deploy.properties

Backup location: /backup_before_hikari/deploy.properties.backup

Status: NO CHANGES REQUIRED

The deploy.properties file remains unchanged as it uses JNDI datasource references which are compatible with both Tomcat pool and HikariCP.

New Dependencies Added to /lib/

FileVersionSizePurpose
HikariCP-5.1.0.jar5.1.0158KBHigh-performance JDBC connection pool
slf4j-api-2.0.9.jar2.0.964KBLogging facade required by HikariCP
slf4j-jdk14-2.0.9.jar2.0.910KBSLF4J binding for JDK logging

Configuration Comparison

Connection Pool Parameters Mapping

Tomcat JDBCHikariCPValueNotes
initialSizeminimumIdle20 (VitecDB), 5 (DcbDB)Optimized for mixed workload
maxActivemaximumPoolSize100 (VitecDB), 30 (DcbDB)Same maximum capacity
maxWaitconnectionTimeout30000msConnection acquisition timeout
timeBetweenEvictionRunsMillisN/A-HikariCP handles internally
minEvictableIdleTimeMillisidleTimeout600000ms10 minutes idle timeout
removeAbandonedTimeoutleakDetectionThreshold60000msDevelopment only
validationQueryconnectionTestQuerySELECT 1Same validation
defaultAutoCommitautoCommitfalseCritical for Heirloom

New Performance Optimizations Added

SQL Server Specific:

  • cachePrepStmts="true" - Enable statement caching
  • prepStmtCacheSize="250" - Cache up to 250 statements
  • prepStmtCacheSqlLimit="2048" - Max SQL string length to cache
  • useServerPrepStmts="true" - Use server-side prepared statements
  • sendStringParametersAsUnicode="false" - Performance optimization for non-Unicode data
  • applicationIntent="ReadWrite" - Optimize for read/write operations

HikariCP Specific:

  • maxLifetime="1800000" - 30 minutes maximum connection lifetime
  • leakDetectionThreshold="60000" - Detect leaks after 60 seconds (dev only)
  • poolName - Named pools for monitoring (VitecDB-HikariPool, DcbDB-HikariPool)
  • transactionIsolation="TRANSACTION_READ_COMMITTED" - Explicit isolation level

How to Compare Files

To see the exact differences between the original and modified files:

# Compare context.xml
diff -u backup_before_hikari/context.xml.backup conf/context.xml

# Or use a visual diff tool
vimdiff backup_before_hikari/context.xml.backup conf/context.xml

Rollback Instructions

If you need to rollback to the Tomcat JDBC pool configuration:

  1. Restore the original context.xml:

    cp backup_before_hikari/context.xml.backup conf/context.xml
  2. Remove HikariCP libraries (optional):

    rm lib/HikariCP-5.1.0.jar
    rm lib/slf4j-api-2.0.9.jar
    rm lib/slf4j-jdk14-2.0.9.jar
  3. Restart Tomcat:

    bin/shutdown.sh
    bin/startup.sh

Expected Performance Improvements

Based on the HikariCP configuration and optimizations:

  • Connection acquisition: 5-10x faster (from ~15ms to ~1-2ms)
  • Prepared statement execution: 2-3x faster due to caching
  • Overall throughput: 2-3x improvement expected
  • Memory usage: 20-30% reduction
  • CPU usage: 30-40% reduction under load

Monitoring After Migration

Key Metrics to Watch:

  1. Connection pool metrics via JMX:

    • ActiveConnections
    • IdleConnections
    • PendingThreads
    • ConnectionCreationTime
  2. Application performance:

    • Response times (should decrease)
    • Throughput (should increase)
    • Error rates (should remain same or decrease)
  3. Database metrics:

    • Active sessions
    • Query execution times
    • Lock contention

Enable JMX Monitoring:

Add to Tomcat startup:

CATALINA_OPTS="$CATALINA_OPTS -Dcom.zaxxer.hikari.jmx.register=true"

Testing Checklist

Before going to production:

  • Verify application starts without errors
  • Test basic database connectivity
  • Verify transaction handling (autocommit=false)
  • Run functional test suite
  • Perform load testing
  • Monitor for connection leaks
  • Validate performance improvements
  • Test failover scenarios

Notes

  1. No code changes required: The application code doesn't need any modifications as it uses JNDI datasources.

  2. Backwards compatible: The JNDI names remain the same (jdbc/VitecDB and jdbc/DcbDB).

  3. Leak detection: Currently enabled with 60-second threshold. Disable in production by removing leakDetectionThreshold.

  4. Logging: HikariCP uses SLF4J. Logs will appear in Tomcat's standard logs.

  5. Further optimization: After monitoring production metrics, pool sizes can be fine-tuned based on actual usage patterns.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk