Spring启动mysql睡眠连接

时间:2017-08-01 22:50:23

标签: java mysql spring spring-boot

我正在构建一个使用mysql作为db的spring引导的应用程序,因为我看到的是Spring引导与db打开了10个连接,但只使用了一个。

每次我在db上运行show processlist时,9个连接都处于休眠状态,只有一个正在做某事。

有一种方法可以在10个打开的连接之间拆分所有进程吗?

我的应用程序需要更好的mysql处理,因为每分钟插入大约300条记录,所以我认为在这些打开的连接之间进行分割将获得更好的结果。

我的aplication.yml:

security:
    basic:
      enabled: false
  server:
    context-path: /invest/
    compression:
      enabled: true
      mime-types:
      - application/json,application/xml,text/html,text/xml,text/plain
  spring:
    jackson:
      default-property-inclusion: non-null
      serialization:
        write-bigdecimal-as-plain: true
      deserialization:
        read-enums-using-to-string: true
    datasource:
      platform: MYSQL
      url: jdbc:mysql://localhost:3306/invest?useSSL=true
      username: #
      password: #
      separator: $$
      dbcp2:
        test-while-idle: true
        validation-query: SELECT 1
    jpa:
      show-sql: false    
      hibernate:
        ddl-auto: update
        naming:
          strategy: org.hibernate.cfg.ImprovedNamingStrategy
      properties:
        hibernate:
          dialect: org.hibernate.dialect.MySQL5Dialect
    http:
      encoding:
        charset: UTF-8
        enabled: true
        force: true

有办法做到这一点吗?

1 个答案:

答案 0 :(得分:0)

  1. 您可以查看my.ini,[mysqld] max_connections,确保您的mysql允许更多连接。

  2. 您可以在application.yml

    中调整这些配置

    spring.datasource.max活性 spring.datasource.max年龄 spring.datasource.max空闲 spring.datasource.max一生 spring.datasource.max开准备语句 spring.datasource.max-等待 spring.datasource.maximum池大小 spring.datasource.min-evictable空闲时间,米利斯 spring.datasource.min空闲

  3. 毕竟,我不认为这是一个问题。 Mysql每秒可以处理1000+次插入。每分钟300个太少,游泳池无法打开多个连接。