'Connection'에 해당되는 글 3건

  1. 2021.08.09 [MySQL] HikariCP Connection Pool 관리 예.
  2. 2020.05.27 [SSH] port 22: Connection refused
  3. 2020.03.20 [Reactor Netty] WebClient connection pool?

[MySQL] HikariCP Connection Pool 관리 예.

ITWeb/개발일반 2021. 8. 9. 08:12

 

HikariCP 를 사용하고 있는데 Connection Pool 에 대한 반납과 재사용이 원활 하지 않을 때가 있습니다.

Application 내부에서 사용과 반납을 너무 빈번하게 하고 있을 경우 이런 문제가 발생 하는 것 같습니다.

보통은 별 문제 없이 사용을 했으나 이런 문제가 발생 한다면 명시적으로 Close 를 해주고 다시 Connection 을 생성해 주면 문제를 해소 할 수 있습니다.

 

기억하기 위해 기록 합니다.

 

    config.setDriverClassName("com.mysql.cj.jdbc.Driver");
    config.setJdbcUrl("jdbc:mysql://....");
    config.setUsername(user);
    config.setPassword(pwd);
    config.setMaximumPoolSize(maxPoolSize);
    config.setMinimumIdle(minimumIdle);
    config.setConnectionTimeout(30000);
    config.setValidationTimeout(10000);
    config.setConnectionTestQuery("SELECT 1");
    config.addDataSourceProperty("autoReconnect", "true");
    config.addDataSourceProperty("serverTimezone", "Asia/Seoul");
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    config.addDataSourceProperty("dataSource.useServerPrepStmts", "true");
    config.addDataSourceProperty("characterEncoding","utf8");
    config.addDataSourceProperty("useUnicode","true");
    
    this.ds = new HikariDataSource(config);

 

getConnection() 은 pool 에서 얻어 옵니다.

getConnection().close() 하면 pool 을 반납 하게 됩니다. 

 

근데 이게 반납과 재사용이 잘 안된다. 그러면 ds.close() 하고 다시 connection 을 생성 합니다. (HikariDataSource ds)

 

:

[SSH] port 22: Connection refused

ITWeb/개발일반 2020. 5. 27. 14:32

$ sudo vi /etc/ssh/sshd_config

Port 22

 

$ sudo /etc/init.d/ssh restart

[ ok ] Restarting ssh (via systemctl): ssh.service.

 

:

[Reactor Netty] WebClient connection pool?

ITWeb/개발일반 2020. 3. 20. 19:12

RestTemplate 을 사용 할 까 하다, WebClient 로 변경 했습니다.

더불어 늘 Connection Pool 에 대한 고민을 하는데요.

 

https://projectreactor.io/docs/netty/snapshot/reference/index.html#_connection_pool

By default, the TCP client uses a “fixed” connection pool with 500 
as the maximum number of the channels, 
45s as the pending acquire timeout and 1000 as the maximum number of 
the registered requests for acquire to keep in the pending queue. 
This means that the implementation creates a new channel 
if someone tries to acquire a channel but none is in the pool. 
When the maximum number of the channels in the pool is reached, 
new tries to acquire a channel are delayed 
until a channel is returned to the pool again. 
The implementation uses FIFO order for channels in the pool. 
By default, there is no idle time specified for the channels in the pool.

Channel 500개

Queue 1000개

 

그냥 신경쓰지 말고 쓰라고 합니다.

: