본문 바로가기
Nginx

reset_timedout_connection 옵션

by ybs 2021. 1. 19.
반응형

서버 모니터링을 수행하는데 Active Thread 가 끝없이 증가한적이 있었다.

 

 

nginx 는 아래와 같이 upstream 을 이용해 proxied server와 keepalive 로 연결해놓고 사용중이었다.

upstream ybs-server {
    server localhost:8080;
    # upstream 서버와 유지할 connection의 갯수를 keepalive로 설정한다.
    keepalive 200;
}

 

그런데 nginx keepalive_timeout 설정을 했음에도 불구하고 접속이 계속 유지되고 끊기지 않았다.

$ netstat -an | grep 8080
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:8080 127.0.0.1:43585 ESTABLISHED
tcp 0 0 127.0.0.1:8080 127.0.0.1:53756 ESTABLISHED
tcp 0 0 127.0.0.1:43712 127.0.0.1:8080 ESTABLISHED
tcp 0 0 127.0.0.1:46644 127.0.0.1:8080 ESTABLISHED
tcp 0 0 127.0.0.1:8080 127.0.0.1:43654 ESTABLISHED
tcp 0 0 127.0.0.1:34710 127.0.0.1:8080 ESTABLISHED
tcp 0 0 127.0.0.1:43694 127.0.0.1:8080 ESTABLISHED
tcp 0 0 127.0.0.1:43585 127.0.0.1:8080 ESTABLISHED
tcp 0 0 127.0.0.1:8080 127.0.0.1:46644 ESTABLISHED
tcp 0 0 127.0.0.1:43654 127.0.0.1:8080 ESTABLISHED
tcp 0 0 127.0.0.1:53756 127.0.0.1:8080 ESTABLISHED
tcp 0 0 127.0.0.1:8080 127.0.0.1:43712 ESTABLISHED
tcp 0 0 127.0.0.1:8080 127.0.0.1:43694 ESTABLISHED
tcp 0 0 127.0.0.1:8080 127.0.0.1:34710 ESTABLISHED​

 

reset_timedout_connection 옵션이 있는데 (default 는 off)

해당 옵션 역할에 대한 설명은 아래와 같다.

  1. It should be noted that timed out keep-alive connections are closed normally.

  2. allow the server to close connection on non responding client, this will free up memory

  3. Enables or disables resetting timed out connections and connections closed with the non-standard code 444 (1.15.2). The reset is performed as follows. Before closing a socket, the SO_LINGER option is set on it with a timeout value of 0. When the socket is closed, TCP RST is sent to the client, and all memory occupied by this socket is released. This helps avoid keeping an already closed socket with filled buffers in a FIN_WAIT1 state for a long time.

 

정리하면, 클라이언트 연결이 시한 만료가 될 때 연결 상태에 따라 이 연결과 연관된 정보가 메모리에 남게 된다. 이 옵션을 활성화 시키면 시한이 만료된 후에 이 연결과 연관된 모든 정보가 삭제된다. nginx 1.15.2 부터는 "444 응답 없이 연결 닫음" 코드를 반환한다.

 

 

참고 :
http://nginx.org/en/docs/http/ngx_http_core_module.html
https://github.com/denji/nginx-tuning/blob/master/README.md
Nginx Http Server (책)

반응형

'Nginx' 카테고리의 다른 글

rewrite break 이슈  (0) 2022.02.17
nginx 수정 하면서 썼던 명령어 정리  (0) 2021.08.03
timeout 설정 정리  (0) 2021.01.19
파일 업로드/다운로드 시 임시 디렉토리 권한 이슈  (0) 2021.01.19
nginx gzip 옵션  (0) 2021.01.17