简体   繁体   English

Spring Boot MySQL睡眠连接

[英]Spring boot mysql sleep connections

Im building a app that with spring boot that uses mysql as db, as im seen is that spring boot opens 10 connections with the db but uses only one. 我建立了一个使用spring boot的应用程序,该应用程序使用mysql作为db,im看到的是spring boot打开了与db的10个连接,但只使用了一个。

Every time i run show processlist on db, 9 connections are sleep and only one is doing something. 每次我在db上运行show processlist时,有9个连接处于睡眠状态,只有一个正在做某事。

There's a way to split all the process between the 10 opened connections? 有没有办法在10个打开的连接之间拆分所有过程?

My app need better mysql processing because every minute about 300 records is inserted, so i think spliting between this opened connections will get better results. 我的应用程序需要更好的mysql处理,因为每分钟大约会插入300条记录,因此我认为在此打开的连接之间进行拆分将获得更好的结果。

My aplication.yml: 我的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

There's a way to do this? 有办法吗?

  1. You can check my.ini,[mysqld] max_connections ,make sure more connections are allowed by your mysql. 您可以检查my.ini,[mysqld] max_connections,确保mysql允许更多连接。

  2. You can adjust these config in your application.yml 您可以在application.yml中调整这些配置。

    spring.datasource.max-active spring.datasource.max-age spring.datasource.max-idle spring.datasource.max-lifetime spring.datasource.max-open-prepared-statements spring.datasource.max-wait spring.datasource.maximum-pool-size spring.datasource.min-evictable-idle-time-millis spring.datasource.min-idle spring.datasource.max-活动spring.datasource.max-age spring.datasource.max-idle spring.datasource.max-lifetime spring.datasource.max-open-prepared语句spring.datasource.max-waiting spring.datasource。最大池大小spring.datasource.min-evictable-idle-time-millis spring.datasource.min-idle

After all, I do not think this is a problem . 毕竟,我认为这不是问题。 Mysql can handle 1000+ insertion per second. Mysql每秒可以处理1000次以上的插入。 300 per minute is too few for pool to open more than one connection. 每分钟300个池对于打开多个连接来说太少了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM