PGSimpleDataSource + HikariCP длительное время установления соединения - PullRequest
0 голосов
/ 16 сентября 2018

Загрузите приложение Spring * 1.4.1.RELEASE.Во время загрузки службы я вижу, что пул соединений Hikari создается с приведенными ниже конфигурациями, однако получение соединения JDBC занимает очень много времени.Вот из журналов:

**34880058484** nanoseconds spent acquiring 1 JDBC connections;
0 nanoseconds spent releasing 0 JDBC connections;
8074041 nanoseconds spent preparing 6 JDBC statements;
58549577 nanoseconds spent executing 3 JDBC statements;
350394122 nanoseconds spent executing 3 JDBC batches;
0 nanoseconds spent performing 0 L2C puts;
0 nanoseconds spent performing 0 L2C hits;
0 nanoseconds spent performing 0 L2C misses;
394751462 nanoseconds spent executing 2 flushes (flushing a total of 4 entities and 0 collections);
0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0 entities and 0 collections)

build.gradle соответствующих конфигураций:

compile('org.springframework.boot:spring-boot-starter-data-jpa') {
    exclude group: 'org.apache.tomcat', module: 'tomcat-jdbc'
}
// HikariCP
compile('com.zaxxer:HikariCP:3.2.0') {
    exclude group: 'org.hibernate', module: 'hibernate-core'
}

// Need this in order to get the HikariCPConnectionProvider
compile('org.hibernate:hibernate-hikaricp:5.2.11.Final') {
    exclude group: 'com.zaxxer', module: 'HikariCP'
    exclude group: 'org.hibernate', module: 'hibernate-core'
}

Настройки источника spring.dat:

spring.datasource.platform=postgres
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432
spring.datasource.username=username
spring.datasource.password=password
spring.datasource.type=com.zaxxer.hikari.HikariDataSource

Конфигурации HikariCP:

# Hikari will use the above plus the following to setup connection pooling
spring.datasource.hikari.data-source-class-name=org.postgresql.ds.PGSimpleDataSource
spring.datasource.hikari.data-source-properties.url=${spring.datasource.url}
spring.datasource.hikari.data-source-properties.user=${spring.datasource.username}
spring.datasource.hikari.data-source-properties.password=${spring.datasource.password}
spring.datasource.hikari.data-source-properties.reWriteBatchedInserts=true
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.maximum-pool-size=50
spring.datasource.hikari.idle-timeout=30000
spring.datasource.hikari.pool-name=SessionServiceHikariCP
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.connection-test-query=SELECT 1 from session
spring.datasource.hikari.auto-commit=true
spring.jpa.hibernate.connection.provider_class=org.hibernate.hikaricp.internal.HikariCPConnectionProvider

Application.java

@Bean
public HikariDataSource hikariDataSource() throws Exception{
    return new HikariDataSource(hikariConfig());
}
@Bean
@Primary
@ConfigurationProperties(prefix = "spring.datasource.hikari")
public HikariConfig hikariConfig() throws Exception{
    return new HikariConfig();
}

@Bean
public JdbcTemplate getJdbcTemplate() throws Exception {
    return new JdbcTemplate(hikariDataSource());
}

Кажется, соединение не используется из пула, но JDBC каждый раз создает новое соединение.В чем может быть причина?

...