在 Grails 4 中使用 HikariCP 时如何使用 MySQL 的性能属性?

问题描述 投票:0回答:1

在 MySQL 性能提示页面的 HikariCP 页面上。

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

建议使用4个属性

prepStmtCacheSize
prepStmtCacheSqlLimit
cachePrepStmts
useServerPrepStmts 

我很困惑这些属性是进入与 dbCreate 和方言相同级别的数据源块,还是进入属性块。

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

    }

}

或者这个

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


    }

}
mysql grails hikaricp grails-4
1个回答
0
投票

如果您尝试了这两个配置选项并且它们都不起作用,那么这可能值得尝试......

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
        }
    }
}

您还可以通过 logback 打开 Hikari 日志记录:

<logger name="com.zaxxer.hikari" level="DEBUG" additivity="false">
    <appender-ref ref="STDOUT" />
</logger>
© www.soinside.com 2019 - 2024. All rights reserved.