簡體   English   中英

Spring Boot MySQL睡眠連接

[英]Spring boot mysql sleep connections

我建立了一個使用spring boot的應用程序,該應用程序使用mysql作為db,im看到的是spring boot打開了與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. 您可以檢查my.ini,[mysqld] max_connections,確保mysql允許更多連接。

  2. 您可以在application.yml中調整這些配置。

    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

畢竟,我認為這不是問題。 Mysql每秒可以處理1000次以上的插入。 每分鍾300個池對於打開多個連接來說太少了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM