티스토리 뷰

Spring-boot

[Spring boot] undertow

개발자-김씨 2021. 4. 23. 12:44
반응형

spring boot 학습 & 세팅 1탄 ~

 

Spring boot 공식 was undertow 

언더토우의 다른 was와 차이, 특징, 설치 방법은 다른 블로그들에 잘 정리되어 있으니 pass

hyojaedev.tistory.com/32

 

👨🏻‍💻 Undertow 적용하기 (다른 WAS 적용해보기)

📌 서론 SpringBoot를 사용하면서 내장 WAS가 디폴트로 설정되어 있는 Tomcat 이외에 다른 WAS를 사용해보겠다는 생각이 다소 없었던 것 같다. SpringBoot 관련 스터디를 진행하면서 아래와 같은 피드백

hyojaedev.tistory.com

 

 

undertow 옵션

<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.9.RELEASE</version>

스프링부트 2.3.9 RELEASE 버전에서 언더토우 2.1 버전대가 깔린다.

스프링 부트에서 undertow옵션을 설정하려면  server.undertow.xxxxx 로 한다.

스프링 부트 2.3.9RELEASE appendix-application-properties 문서 참고

옵션이 많은데 중요한 옵션은 요 2개가 아닌가 싶다.

옵션명

기본값

server.undertow.threads.io

Number of I/O threads to create for the worker. The default is derived from the number of available processors.

server.undertow.threads.worker

Number of worker threads. The default is 8 times the number of I/O threads.

 

threads.worker는 톰캣으로 치면 max-threads와 비슷한 옵션이고 threads.io는 톰캣에는 없는 옵션이다.

톰캣은 사용자 요청이 오면 읽기 - 처리 - 쓰기 모두 동일한 스레드에서 처리되는데 언더토우는 읽기 쓰기 작업은 io thread가, 처리 작업은 worker스레드가 담당하게 된다고 보면 된다.

스프링부트에서 언더토우의 IO스레드와 WORKER스레드의 기본값은 IO스레드는 Core만큼, WORKER스레드는 IO스레드 의 8배입니다. 일반적으로 WAS의 스레드로 Core * 8은 많이 부족해 보입니다.

 

언더토우 2.1 공식 문서에 스레드 숫자와 관련된 내용이 있습니다.

WORKER_IO_THREADS

Two IO threads per CPU core is a reasonable default.

WORKER_TASK_CORE_THREADS

The number of threads in the workers blocking task thread pool. When performing blocking operations such as Servlet requests threads from this pool will be used. In general it is hard to give a reasonable default for this, as it depends on the server workload. Generally this should be reasonably high, around 10 per CPU core.

 

IO스레드는 cpu core * 2가 합리적이고 WORKERS는 서버 워크로드에 따라 다르기 때문에 합리적인 기본값을 제공하기 어렵고 core의 10배 정도로 상당히 높아야 한다고 합니다. 그런데 공식 문서는 논블록킹 작업(처리)에 국한된 내용이 아니라 그대로 참고하긴 힘듭니다.

 

보통 was는 DB나 API호출같은 블로킹 작업들이 많기 때문에 IO스레드는 core * 2로 하더라도 WORKER스레드는 많이 필요합니다. 일반적으로 톰캣의 max-threads를 참고하여 주면 될 듯합니다.

서버 성격에 따라 다르기 때문에 물론 정답은 없습니다. 블로킹 작업이 별로 없는 서버이고 요청이 빈번하거나 요청과 응답값의 데이터가 크다면 IO스레드를 조금 더 늘려주고 WORKER스레드를 조금 더 줄여도 됩니다. 만약 그것도 귀찮다면 조금 넉넉하게 줘도 되겠죠.

 

덧붙이기 : 간단한 테스트

만약 worker스레드를 2로 하면 해당 서버는 동시 요청을 2개씩 밖에 못 합니다.

 

 

스프링 부트 application.yml - 언더토우 설정하면서 마무리 ~

server:
  port : 8080
  undertow:
    threads:
      io: 8
      worker: 200

 

 

server.undertow.no-request-timeout 옵션도 중요한 같은데 차후에 정리되면 내용 추가

반응형

'Spring-boot' 카테고리의 다른 글

[Spring boot]Redis - Lettuce 설정  (5) 2021.05.06
[Spring boot] 초기화 코드  (0) 2021.04.28
[Spring boot] Filter 설정  (2) 2021.04.28
[Spring boot]yml configuration  (0) 2021.04.27
댓글