me hungry!
  • migrate to herdin.github.io
  • DEV TOOLS
    • IDE
      • VSCode
        • spring-boot maven config
  • Spring
    • default
      • IoC
      • resource
      • validation
      • data bind
      • SpringEL
      • DispatcherServlet
    • debug
      • mariadb connection time out - connection pool
  • Database
    • MariaDB
      • command history
  • LINUX
    • CentOS
      • install java
      • install, setting maven
      • install, setting vault
      • upgrade docker to docker-ce
  • WINDOW
    • Road to window docker
  • Arduino
    • default
    • SENSORS
      • dust sensor
        • GP2Y1010AU0F
      • humidity&temperature
        • DHT11
      • lcd
        • SKU DFR0009 - shield
    • debug
Powered by GitBook
On this page

Was this helpful?

  1. Spring
  2. debug

mariadb connection time out - connection pool

GCP, tomcat-spring-aws_mariadb 환경. 서버 띄우고 8시간이 지난 뒤에 db select 를 하면 오류가남 (오류까먹음) mariadb 에서 SHOW GLOBAL VARIABLES LIKE 'WAIT%'; 로 커넥션 타임아웃을 검색해보면 기본 값 28800 이 나오고 28800/(60*60) = 8.0 시간이 지나면 커넥션이 끊어버리는데 해당 db connection 을 dbcp 같은 pool 에서 그냥 들고 있기 때문에 생기는 에러라고 한다.

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${db.driverClass}"></property>
        <property name="url" value="${db.url}"></property>
        <property name="username" value="${db.username}"></property>
        <property name="password" value="${db.password}"></property>
        <property name="maxActive" value="5" />
        <!-- 아무것도 안할때도 테스트 -->
        <property name="testWhileIdle" value="true" />
        <!-- 아무것도 안할때 테스트 간격 -->
        <property name="timeBetweenEvictionRunsMillis" value="5000" />
        <!-- pool 에서 가져올때마다 테스트할 것인지 -->
        <property name="testOnBorrow" value="false" />
        <!-- 테스트에 사용할 쿼리 : 최대한 가벼운 쿼리 -->
        <property name="validationQuery" value="SELECT 1" />
    </bean>

위와 같이 설정하고 mariadb 에서 SHOW PROCESSLIST; 로 현재 프로세스들을 계속 조회해보면 설정한 서버에서 Command : Sleep, Time 이 timeBetweenEvictionRunsMillis 에서 설정한 값보다 적게 나오면 (지금같은경우는 0, 1, 2, 3, 4, 0, 1, 2, 3, ...) 설정이 된 것임.

PreviousdebugNextMariaDB

Last updated 6 years ago

Was this helpful?