Search code examples
mysqlgrailshikaricpgrails-4

How to use performance properties of MySQL when using HikariCP in Grails 4?


On the HikariCP page on the page on MySQL performance tips.

https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration

It suggests using 4 properties namely

prepStmtCacheSize
prepStmtCacheSqlLimit
cachePrepStmts
useServerPrepStmts 

I am confused whether these properties go to dataSource block at the same level as dbCreate and dialect or do they go inside properties block.

dataSource {
    pooled = true
    dbCreate = "none"
    url = "jdbc:mysql://localhost:3306/dev2?useUnicode=yes&characterEncoding=UTF-8"
    driverClassName = "com.mysql.cj.jdbc.Driver"
    dialect = org.hibernate.dialect.MySQL8Dialect

    prepStmtCacheSize = 400
    prepStmtCacheSqlLimit = 2048
    cachePrepStmts = true
    useServerPrepStmts = true

    type = "com.zaxxer.hikari.HikariDataSource"
    properties {

        connectionTimeout = 200000
        maximumPoolSize = 50

    }

}

or this

dataSource {
    pooled = true
    dbCreate = "none"
    url = "jdbc:mysql://localhost:3306/dev2?useUnicode=yes&characterEncoding=UTF-8"
    driverClassName = "com.mysql.cj.jdbc.Driver"
    dialect = org.hibernate.dialect.MySQL8Dialect


    type = "com.zaxxer.hikari.HikariDataSource"
    properties {

        connectionTimeout = 200000
        maximumPoolSize = 50
    prepStmtCacheSize = 400
    prepStmtCacheSqlLimit = 2048
        cachePrepStmts = true
        useServerPrepStmts = true


    }

}

Solution

  • If you tried both of those configuration options and they didn't work, then this may be worth trying...

    dataSource {
        pooled = true
        dbCreate = "none"
        url = "jdbc:mysql://localhost:3306/dev2?useUnicode=yes&characterEncoding=UTF-8"
        driverClassName = "com.mysql.cj.jdbc.Driver"
        dialect = org.hibernate.dialect.MySQL8Dialect
        type = "com.zaxxer.hikari.HikariDataSource"
        properties {
            maximumPoolSize = 50
            connectionTimeout = 200000
            dataSourceProperties {
                prepStmtCacheSize = 400
                prepStmtCacheSqlLimit = 2048
                cachePrepStmts = true
                useServerPrepStmts = true
            }
        }
    }
    

    You can also turn on Hikari logging via logback:

    <logger name="com.zaxxer.hikari" level="DEBUG" additivity="false">
        <appender-ref ref="STDOUT" />
    </logger>