[REFACTOR] 서버 리소스 스펙 최적화#106
Hidden character warning
Conversation
There was a problem hiding this comment.
Pull request overview
운영 서버 스펙 다운그레이드(CPU 4→2, RAM 16G→8G)에 맞춰 런타임 리소스 사용량(JVM/DB 커넥션/서버 스레드)을 낮추기 위한 설정 변경 PR입니다.
Changes:
application-prod.yml에서 Tomcat 스레드풀과 HikariCP 커넥션풀 상한을 축소docker-compose.yml에서 backend 서비스의 JVM 옵션(JAVA_OPTS) 추가 및 리소스 제한 값(CPU/메모리) 조정
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/main/resources/application-prod.yml | Tomcat thread 및 HikariCP pool 크기 축소로 서버 자원 스펙 하향에 맞춘 설정 조정 |
| docker-compose.yml | backend 컨테이너 리소스 제한 값 및 JVM(GC 로깅 포함) 옵션을 추가/조정 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| deploy: | ||
| resources: | ||
| limits: | ||
| cpus: "4.0" | ||
| memory: 16G | ||
| cpus: "2.0" | ||
| memory: 8G |
| - PINPOINT_APPLICATION_NAME=dorumdorum | ||
| - PINPOINT_AGENT_ID=${PINPOINT_AGENT_ID:-dorumdorum-backend-${HOSTNAME}} | ||
| - PINPOINT_AGENT_NAME=${PINPOINT_AGENT_NAME:-dorumdorum-be} | ||
| - JAVA_OPTS=-Xms6g -Xmx6g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -Xlog:gc*:file=/var/log/gc.log:time,uptime,level,tags:filecount=5,filesize=20m |
| - PINPOINT_APPLICATION_NAME=dorumdorum | ||
| - PINPOINT_AGENT_ID=${PINPOINT_AGENT_ID:-dorumdorum-backend-${HOSTNAME}} | ||
| - PINPOINT_AGENT_NAME=${PINPOINT_AGENT_NAME:-dorumdorum-be} | ||
| - JAVA_OPTS=-Xms6g -Xmx6g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -Xlog:gc*:file=/var/log/gc.log:time,uptime,level,tags:filecount=5,filesize=20m |
| - PINPOINT_APPLICATION_NAME=dorumdorum | ||
| - PINPOINT_AGENT_ID=${PINPOINT_AGENT_ID:-dorumdorum-backend-${HOSTNAME}} | ||
| - PINPOINT_AGENT_NAME=${PINPOINT_AGENT_NAME:-dorumdorum-be} | ||
| - JAVA_OPTS=-Xms6g -Xmx6g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -Xlog:gc*:file=/var/log/gc.log:time,uptime,level,tags:filecount=5,filesize=20m |
Walkthrough운영 환경에서 컨테이너 리소스(CPU 4→2, 메모리 16G→8G)를 축소하고 JVM 힙(-Xms/-Xmx 6g)과 GC 로깅을 활성화하며, Tomcat 스레드와 HikariCP 풀 크기를 함께 조정합니다. Changes서버 리소스 및 스레드풀 최적화
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docker-compose.yml`:
- Line 49: 현재 docker-compose.yml의 JAVA_OPTS 고정 힙 설정(환경변수 JAVA_OPTS, -Xms6g,
-Xmx6g)이 컨테이너 메모리(8GB) 대비 헤드룸이 부족해 OOM 위험이 있으니 -Xmx를 4g로 낮추거나 고정값 대신
-XX:MaxRAMPercentage=<percent>로 변경해 동적으로 힙을 할당하도록 수정하세요; 관련 심볼: JAVA_OPTS, -Xmx,
-Xms, -XX:MaxRAMPercentage를 찾아서 하나의 옵션으로 대체하고 Tomcat 스택/메타스페이스/네이티브 메모리 여유를 고려해
설정값을 적용하세요.
- Line 49: The docker-compose config sets JVM flags via JAVA_OPTS including GC
logging to /var/log/gc.log, but that path is ephemeral inside the container;
update the service's volumes section to mount /var/log/gc.log to the host (or a
named volume) so GC logs persist (e.g., add a volume mapping for
/var/log/gc.log), and if the container memory limit is 8GB reduce the heap
setting in JAVA_OPTS (change -Xmx6g to around -Xmx5.5g) or increase the
container memory limit to avoid OOM kills; ensure you update the same JAVA_OPTS
string and the service's volumes list accordingly.
- Around line 62-63: The deploy.resources.limits (cpus: "2.0", memory: 8G) in
docker-compose.yml is ignored because you run plain docker compose up; update
your deployment script to use docker compose --compatibility up so
deploy.resources.limits are honored, or alternatively change the compose service
to use the legacy container-level keys (mem_limit and cpus) so the runtime
enforces limits; also verify JAVA_OPTS (-Xms6g -Xmx6g) remains consistent with
the container memory limit you choose.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 1b7509e1-6744-42a9-8a32-ac40a6361e98
📒 Files selected for processing (2)
docker-compose.ymlsrc/main/resources/application-prod.yml
| - PINPOINT_APPLICATION_NAME=dorumdorum | ||
| - PINPOINT_AGENT_ID=${PINPOINT_AGENT_ID:-dorumdorum-backend-${HOSTNAME}} | ||
| - PINPOINT_AGENT_NAME=${PINPOINT_AGENT_NAME:-dorumdorum-be} | ||
| - JAVA_OPTS=-Xms6g -Xmx6g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -Xlog:gc*:file=/var/log/gc.log:time,uptime,level,tags:filecount=5,filesize=20m |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
find . -name "docker-compose.yml" -o -name "docker-compose.yaml" | head -20Repository: DorumDorum/BE
Length of output: 78
🏁 Script executed:
cat -n ./docker-compose.ymlRepository: DorumDorum/BE
Length of output: 6364
8GB 컨테이너에 6GB 힙 고정 설정은 메모리 헤드룸이 부족할 수 있어요.
Tomcat 스레드들의 스택 메모리, 메타스페이스, 네이티브 메모리, 그리고 Pinpoint 에이전트까지 고려하면 남은 2GB만으로는 부족해서 OOMKilled 위험이 있어요. Xmx를 4GB로 낮춰서 여유 메모리를 더 확보하거나, MaxRAMPercentage 기반으로 동적 설정하는 쪽이 더 안전해요.
권장 수정 예시
- - JAVA_OPTS=-Xms6g -Xmx6g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -Xlog:gc*:file=/var/log/gc.log:time,uptime,level,tags:filecount=5,filesize=20m
+ - JAVA_OPTS=-Xms4g -Xmx4g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -Xlog:gc*:file=/var/log/gc.log:time,uptime,level,tags:filecount=5,filesize=20m🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@docker-compose.yml` at line 49, 현재 docker-compose.yml의 JAVA_OPTS 고정 힙 설정(환경변수
JAVA_OPTS, -Xms6g, -Xmx6g)이 컨테이너 메모리(8GB) 대비 헤드룸이 부족해 OOM 위험이 있으니 -Xmx를 4g로 낮추거나
고정값 대신 -XX:MaxRAMPercentage=<percent>로 변경해 동적으로 힙을 할당하도록 수정하세요; 관련 심볼:
JAVA_OPTS, -Xmx, -Xms, -XX:MaxRAMPercentage를 찾아서 하나의 옵션으로 대체하고 Tomcat
스택/메타스페이스/네이티브 메모리 여유를 고려해 설정값을 적용하세요.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# 1) JAVA_OPTS 사용 지점 확인 (Dockerfile/entrypoint/start script)
fd -i 'Dockerfile|entrypoint|start|run' . | xargs -r rg -n -C2 'JAVA_OPTS|JAVA_TOOL_OPTIONS|exec java|java '
# 2) GC 로그 경로 볼륨 매핑 확인
rg -n -C2 '/var/log/gc\.log|volumes:' docker-compose.yml
# 3) 실행 후 실제 JVM 플래그 반영 확인 (운영/로컬에서)
# docker compose up -d backend
# docker exec -it ${CONTAINER_NAME:-dorumdorum-be} sh -lc 'ps -ef | rg "java|Xms|Xmx|Xlog"'Repository: DorumDorum/BE
Length of output: 2458
🏁 Script executed:
sed -n '45,70p' docker-compose.yml | cat -nRepository: DorumDorum/BE
Length of output: 1109
GC 로그 파일 볼륨 마운트를 추가해야 합니다.
현재 설정에서 JAVA_OPTS는 Dockerfile의 ENTRYPOINT에서 ${JAVA_OPTS}로 올바르게 확장되므로 JVM 플래그들이 제대로 적용됩니다. 다만 /var/log/gc.log 경로는 컨테이너의 임시 파일시스템이기 때문에 컨테이너 재시작 시 로그가 모두 삭제됩니다. 디버깅과 성능 분석을 위해 GC 로그를 보존하려면 다음과 같이 수정해주세요:
volumes:
- ./firebase-service-account.json:/app/firebase-service-account.json:ro
- /var/log/gc.log:/var/log/gc.log # 또는 named volume 사용또한 6GB 힙을 8GB 메모리 제한에 할당한 경우, 약 2GB 만이 JVM 네이티브 메모리(스레드, 메타스페이스, 직접 버퍼), Pinpoint 에이전트 오버헤드, 커널 버퍼 등으로 남습니다. 운영 환경에서 OOMKill이 발생하면 힙 크기를 5.5GB 정도로 조정하거나 메모리 제한을 증가시켜주세요.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@docker-compose.yml` at line 49, The docker-compose config sets JVM flags via
JAVA_OPTS including GC logging to /var/log/gc.log, but that path is ephemeral
inside the container; update the service's volumes section to mount
/var/log/gc.log to the host (or a named volume) so GC logs persist (e.g., add a
volume mapping for /var/log/gc.log), and if the container memory limit is 8GB
reduce the heap setting in JAVA_OPTS (change -Xmx6g to around -Xmx5.5g) or
increase the container memory limit to avoid OOM kills; ensure you update the
same JAVA_OPTS string and the service's volumes list accordingly.
There was a problem hiding this comment.
♻️ Duplicate comments (1)
docker-compose.yml (1)
49-49:⚠️ Potential issue | 🟠 Major | ⚡ Quick win
-Xms6g -Xmx6g는 8G 컨테이너 한도 대비 메모리 헤드룸이 부족합니다.Line 49 설정은 힙 외 메모리(메타스페이스, 스레드 스택, direct buffer, 에이전트 오버헤드) 여유가 작아서 OOMKilled 위험이 있습니다. 힙 상한을 더 낮추시거나 비율 기반으로 전환해 주세요.
권장 수정 예시
- - JAVA_OPTS=-Xms6g -Xmx6g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -Xlog:gc\*:file=/var/log/gc.log:time,uptime,level,tags:filecount=5,filesize=20m + - JAVA_OPTS=-Xms4g -Xmx4g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -Xlog:gc\*:file=/var/log/gc.log:time,uptime,level,tags:filecount=5,filesize=20m🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@docker-compose.yml` at line 49, The JAVA_OPTS environment setting currently hard-sets heap to -Xms6g -Xmx6g which leaves insufficient headroom for metaspace, thread stacks and native buffers and risks OOMKilled; update the JAVA_OPTS entry to either lower the fixed heap (e.g., set -Xmx4g and remove or reduce -Xms) or switch to ratio-based settings like removing -Xms/-Xmx and adding -XX:InitialRAMPercentage=50 -XX:MaxRAMPercentage=75 (or other percentages appropriate for an 8G container) so the JVM uses a safe portion of container RAM; modify the JAVA_OPTS value accordingly in the docker-compose env line.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Duplicate comments:
In `@docker-compose.yml`:
- Line 49: The JAVA_OPTS environment setting currently hard-sets heap to -Xms6g
-Xmx6g which leaves insufficient headroom for metaspace, thread stacks and
native buffers and risks OOMKilled; update the JAVA_OPTS entry to either lower
the fixed heap (e.g., set -Xmx4g and remove or reduce -Xms) or switch to
ratio-based settings like removing -Xms/-Xmx and adding
-XX:InitialRAMPercentage=50 -XX:MaxRAMPercentage=75 (or other percentages
appropriate for an 8G container) so the JVM uses a safe portion of container
RAM; modify the JAVA_OPTS value accordingly in the docker-compose env line.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: ASSERTIVE
Plan: Pro
Run ID: bea86c3c-0deb-4356-abea-2e37251b652f
📒 Files selected for processing (1)
docker-compose.yml
📝 Pull Request Template
📌 제목
📢 요약
🔗 연관 이슈: Resolves #105
🚀 PR 유형
✅ PR 체크리스트
📜 기타
Summary by CodeRabbit