[Nginx] Buffer & Timeout

반응형

이전글에 이어서 Nginx의 configuartion에 대해 알아보도록 하겠습니다.

11. Buffer & Timeout

이번글에서는 buffer와 timeout을 적절히 사용해 ngimx의 performance를 증가시키는 방법에 대해 알아보도록 하겠습니다.

11-1) buffer

먼저 buffer란 nginx와 같은 process가 ram으로 부터 데이터를 읽거나 쓰는 것을 의미합니다.

image.png

예를 들어 nginx는 http로 들어온 request를 먼저 buffer에 저장하고 처리합니다. 만약 buffer에 여유가 없을 경우 hard disk와 같은 곳에 저장해놓기도 합니다.

image.png

동일하게 reponse 값도 client에게 reutrn하기 전에 먼저 buffer에 저장된 후 nginx는 buffer에서 데이터를 읽어 client에게 전달합니다.

image.png

위와 같이 process에서 데이터를 read/write 할때는 중간에 buffer를 둡니다. 이렇게 하면 처리과정은 복잡해 지지만 성능면에서는 많은 이점을 가지게 됩니다.

image.png

하지만 buffer의 크기를 너무 크게 할당하면 메모리가 낭비될 수 있으며, 반대로 너무 작게 할당하면 data를 disk에 너무 자주 write하기 때문에 process의 속도가 느려지게 됩니다.

따라서 각자의 server의 성능에 적절하게 buffer를 setting 할 필요가 있습니다.

image.png

11-2) timeout

timeout은 cut of time for given event를 의미합니다.

예를 들어 client에서부터 request가 들어오고 몇 초가 지난후까지도 request가 진행중이라면 해당 request를 stop 합니다.

image.png

이를 통해 endless 한 data를 client가 보내는 것을 막아, 서버가 breaking 되지 않도록 보호할 수 있습니다.

12. Buffer Configuration

buffer를 설정할 수 있는 변수들은 다음과 같습니다.

image.png

12-1) buffer size for post submission

form submission의 buffer size를 정의합니다.

client_body_buffer_size 10K;

form submission의 max data size를 정의합니다. max size 이상의 form submission은 413 error를 return 합니다.

client_max_body_size 8m;

12-2) buffer size for headers

client header의 buffer size를 정의합니다.

client_header_buffer_size 1K;

12-3) skip buffering for static files

disk에 저장되어있던 static 파일이 response 될때 buffer에 저장되지 않도록 설정합니다.

sendfile on;

image.png

12-4) optimise sendfile packets

send file의 packet을 optimiz 하는 변수입니다.

tcp_nopush on;

13. Timeout Configuration

timeout을 설정할 수 있는 변수들은 다음과 같습니다.

image.png

13-1) max time to receive client headers/body

client body data의 timeout 시간을 정의합니다.

이때의 시간은 전체 data를 읽는 시간이 아닌 연속적인 읽기 작업 사이의 시간을 의미합니다.

client_body_timeout 12;

client head data의 timeout 시간을 정의합니다.

client_header_timeout 12;

13-2) max time to keep a connection open for

다음 data를 받기위해 connection을 열어놓는 최대 시간을 정의합니다.

client가 여러개의 파일을 보내거나, 무한히 connection을 연결하는 공격을 막고자 사용합니다.

keepalive_timeout 15;

13-3) max time for the client accept/receive a response

client가 response된 data 중 아무것도 받지 않는 최대 시간을 정의합니다.

send_timeout 10;

참고 자료 : https://www.udemy.com/course/nginx-fundamentals/


반응형

'Nginx' 카테고리의 다른 글

[Nginx] Header & Expire  (0) 2020.08.31
[Nginx] Adding Dynamic Module  (0) 2020.08.31
[Nginx] Worker Process  (0) 2020.08.27
[Nginx] Logging  (0) 2020.08.27
[Nginx] Try Files & Named Location  (0) 2020.08.27

댓글

Designed by JB FACTORY