Table of Contents
Spring Boot Hello World App 은 왜 많은 메모리가 필요할까
테스트 프로젝트 생성
여기 를 참조하여 프로젝트를 생성합니다.
-XX:MaxRAM=512M
시스템의 최대 메모리를 무시하고, 메모리 최대치를 설정해 줍니다.
java -XX:MaxRAM=512M -jar demo6-0.0.1-NOLIMIT.jar
-Xmx256M -Xms256M
java -XX:MaxRAM=512M -Xmx256M -Xms256M -jar demo6-0.0.1-NOLIMIT.jar
-Xss256k
스래드 각각의 스텍 메모리를 256k 로 제한합니다.
(디폴트는 1M 입니다.)
java -XX:MaxRAM=512M -Xmx256M -Xms256M -Xss256k -jar demo6-0.0.1-NOLIMIT.jar
stress test 시작하기
java -XX:MaxRAM=256M -Xmx128M -Xms128M -Xss256k -jar demo6-0.0.1-NOLIMIT.jar
wget https://hey-release.s3.us-east-2.amazonaws.com/hey_linux_amd64
chmod 777 hey_linux_amd64
sudo mv hey_linux_amd64 /usr/bin/hey
hey -z 5m -c 200 http://localhost:8080/
스래드가 200개 넘게 생성됩니다.
톰캣 스래드는 디폴트로 200개까지 생성되고, 스래드 한개당 1M 메모리를 사용합니다.
server.tomcat.threads.max = 20
application.yml
server:
tomcat:
threads:
max: 20
톰캣 스래드 최대 갯수를 20개로 제한해 봅니다.
hey -z 5m -c 200 http://localhost:8080/
^C
Summary:
Total: 90.2399 secs
Slowest: 0.2185 secs
Fastest: 0.0001 secs
Average: 0.0180 secs
Requests/sec: 15233.6118
Total data: 17870827 bytes
Size/request: 17 bytes
Response time histogram:
0.000 [1] |
0.022 [928403] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
0.044 [69069] |■■■
0.066 [1893] |
0.087 [225] |
0.109 [222] |
hey -z 5m -c 200 http://localhost:8080/
^C
Summary:
Total: 55.0945 secs
Slowest: 0.3929 secs
Fastest: 0.0001 secs
Average: 0.0121 secs
Requests/sec: 16536.8339
Total data: 11844144 bytes
Size/request: 13 bytes
Response time histogram:
0.000 [1] |
0.039 [907673] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
0.079 [2514] |
0.118 [337] |
0.157 [248] |
톰캣 스래드를 1/10 로 줄였지만 성능차이는 없습니다.
물론 테스트중인 앱이 Hello World 앱이기 때문일 수 있습니다.
최대 메모리를 제한해 보니까 꽤 다이나믹하게 메모리가 움직이네요.
https://stackoverflow.com/questions/44491257/how-to-reduce-spring-boot-memory-usage