简体   繁体   中英

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.

Every time i run show processlist on db, 9 connections are sleep and only one is doing something.

There's a way to split all the process between the 10 opened connections?

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.

My 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.

  2. You can adjust these config in your 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

After all, I do not think this is a problem . Mysql can handle 1000+ insertion per second. 300 per minute is too few for pool to open more than one connection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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