Hikari连接池设置


maximumPoolSize

最大连接数。

This property controls the maximum size that the pool is allowed to reach, including both idle and in-use connections. Basically this value will determine the maximum number of actual connections to the database backend. A reasonable value for this is best determined by your execution environment. When the pool reaches this size, and no idle connections are available, calls to getConnection() will block for up to connectionTimeout milliseconds before timing out. Please read about pool sizing. Default: 10

About Pool Sizing给出了一个计算公式:

connections = ((core_count * 2) + effective_spindle_count)

Core count should not include HT threads, even if hyperthreading is enabled. Effective spindle count is zero if the active data set is fully cached, and approaches the actual number of spindles as the cache hit rate falls.

minimumIdle

最小空闲连接数,默认等于maximumPoolSize

This property controls the minimum number of idle connections that HikariCP tries to maintain in the pool. If the idle connections dip below this value and total connections in the pool are less than maximumPoolSize, HikariCP will make a best effort to add additional connections quickly and efficiently. However, for maximum performance and responsiveness to spike demands, we recommend not setting this value and instead allowing HikariCP to act as a fixed size connection pool. Default: same as maximumPoolSize

MySQL线程池

线程池相关设置:

show variables like 'thread%'
  • thread_handling:该参数是配置线程模型,默认情况是one-thread-per-connection,即不启用线程池;将该参数设置为pool-of-threads即启用了线程池。

  • thread_pool_size:该参数是设置线程池的Group的数量,默认为系统CPU的个数,充分利用CPU资源。

  • thread_pool_max_threads:该参数用来限制线程池最大的线程数,超过该限制后将无法再创建更多的线程,默认为100000。

参考

HikariCP

About Pool Sizing

关于MySQL线程池,这也许是目前最全面的实用帖!