Spring Boot 1.2.5,Oracle和Hibernate连接池

Spring Boot 1.2.5,Oracle和Hibernate连接池,hibernate,jpa,spring-boot,c3p0,Hibernate,Jpa,Spring Boot,C3p0,我正在分析我的Spring Boot 1.2.5应用程序,发现性能相当差。在相对较轻的负载下(此时,JMeter有500个模拟用户),提供一个简单的登录页面需要4秒钟以上的时间 我正在使用VisualVM尝试分析它。似乎49%的应用程序时间都花在从Hibernate获取连接上: org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection() 49.121124

我正在分析我的Spring Boot 1.2.5应用程序,发现性能相当差。在相对较轻的负载下(此时,JMeter有500个模拟用户),提供一个简单的登录页面需要4秒钟以上的时间

我正在使用VisualVM尝试分析它。似乎49%的应用程序时间都花在从Hibernate获取连接上:

 org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection()    49.121124   4,450,911 ms (49.1%)    0.000 ms    4,573,860 ms    122,949 ms
为了缓解这种情况,我尝试启用连接池,但它似乎不起作用。我有:

将C3P0添加到我的依赖项中,因此我的休眠依赖项在pom中如下所示:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.3.3.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-c3p0</artifactId>
        <version>4.2.3.Final</version>
    </dependency>
我在文档中读到,如果我设置了Hibernate C3P0属性,那么连接池应该是活动的

然而,我不确定是不是。启动Spring Boot时,我看到的一些消息是:

2015-10-28 04:26:23.426  INFO 2182 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {4.3.3.Final}
2015-10-28 04:26:23.429  INFO 2182 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2015-10-28 04:26:23.431  INFO 2182 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2015-10-28 04:26:23.756  INFO 2182 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2015-10-28 04:26:24.207  INFO 2182 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
找不到“hibernate.properties”是我关心的问题。我意识到,即使它在application.properties中找到属性,它也可能会发出该消息

我想知道,我是否做错了什么,是否有办法验证连接池是否确实处于活动状态


非常感谢……

有了史蒂夫·沃尔德曼(Steve Waldman)的有益评论,我的工作开始了。对于任何感兴趣的人来说,由于我使用的是基于Spring4.1.7.RELEASE的SpringBoot1.2.5.RELEASE,Hibernate5并不容易获得(尽管我正在研究)

因此,要使其发挥作用,请将其放入pom中:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.3.3.Final</version>
</dependency>           
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-c3p0</artifactId>
    <version>4.3.11.Final</version>
</dependency>
如果愿意,可以将属性放入hibernate.properties文件中,它们有点不同,如下所示:

hibernate.c3p0.max_size 2000
hibernate.c3p0.min_size 100
hibernate.c3p0.timeout 5000
hibernate.c3p0.max_statements 1000
hibernate.c3p0.idle_test_period 3000
hibernate.c3p0.acquire_increment 2
hibernate.c3p0.validate false

hibernate.connection.provider_class = org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider
hibernate.connection.url=jdbc:oracle:thin:@earth-db-11.mit.edu:1521:stardev

hibernate.connection.username=yourun
hibernate.connection.password=yourpw
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect

它帮助了我的问题,尽管没有我希望的那么多

我不认为你做了任何能让c3p0真正起作用的事情。根据您的设置,您可能需要替换作为应用程序数据源的Springbean(到c3p0的
ComboPooledDataSource
),或者将hibernate连接提供程序类配置参数
connection.provider\u class
设置为
org.hibernate.connection.C3P0ConnectionProvider
。如果设置了c3p0,库将在池初始化信息中记录横幅和(长)池配置消息;我不完全明白。你是说我只需要再输入一个属性就可以了?目前,它是Spring4.2,所有东西都配置了注释;没有xml。我@Autowired了JdbcTemplate,没有提供自己的数据源。如果我需要的话,我可以,我只是不清楚怎么做。所以,我只是不太了解spring boot。但纯粹是猜测,我会尝试
spring.jpa.properties.hibernate.connection.provider\u class=org.hibernate.connection.C3P0ConnectionProvider
。同样,您应该能够在日志中看到c3p0启动,只要您允许任意消息通过at INFO。(否则,您可能需要配置以
com.mchange
libs为前缀的记录器,以便通过您使用的任何日志库登录信息。)再次感谢Steve,我认为部分问题在于我使用的版本不同。当我包含您推荐的属性时,有一个类未找到异常。我正在尝试将Hibernate all更新到最新版本(5.x),并找出当前正确的类名。另外,我可能需要c3p0的依赖性。不确定这是否有帮助,但下载后我会发现。
spring.jpa.properties.hibernate.c3p0.max_size 2000
spring.jpa.properties.hibernate.c3p0.min_size 100
spring.jpa.properties.hibernate.c3p0.timeout 5000
spring.jpa.properties.hibernate.c3p0.max_statements 1000
spring.jpa.properties.hibernate.c3p0.idle_test_period 3000
spring.jpa.properties.hibernate.c3p0.acquire_increment 2
spring.jpa.properties.hibernate.c3p0.validate false

spring.jpa.properties.hibernate.connection.provider_class = org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider
spring.jpa.properties.hibernate.connection.url=jdbc:oracle:thin:@earth-db-11.mit.edu:1521:stardev

spring.jpa.properties.hibernate.connection.username=yourun
spring.jpa.properties.hibernate.connection.password=yourpw
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
hibernate.c3p0.max_size 2000
hibernate.c3p0.min_size 100
hibernate.c3p0.timeout 5000
hibernate.c3p0.max_statements 1000
hibernate.c3p0.idle_test_period 3000
hibernate.c3p0.acquire_increment 2
hibernate.c3p0.validate false

hibernate.connection.provider_class = org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider
hibernate.connection.url=jdbc:oracle:thin:@earth-db-11.mit.edu:1521:stardev

hibernate.connection.username=yourun
hibernate.connection.password=yourpw
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect