-
Notifications
You must be signed in to change notification settings - Fork 0
[Refactor] 개발 환경 스케일다운 및 스왑 메모리 할당 #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Walkthrough개발 환경용 Terraform 구성 변경: EC2 인스턴스 타입을 t2.micro로 축소, ECS 태스크의 CPU/메모리 할당 축소, API 컨테이너의 일부 JVM 옵션 제거. EC2 user-data에 2G 스왑 파일 생성 및 영구 적용 로직 추가. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
📄 Terraform Plan Summary🛡️ Common InfrastructureStatus: ✅ No Changes 🛠️ Development EnvironmentStatus: 🔄 Changes Detected 📋 Full Results: View in Actions |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (7)
terraform/dev/scripts/user-data.sh (4)
4-8: 스왑 생성 로직을 재실행·중복에 안전하도록 보완하고 fallocate 실패 시 폴백을 추가하세요.현재 구현은 다음과 같은 리스크가 있습니다:
- 스크립트를 재실행하면 /etc/fstab에 동일 엔트리가 누적됩니다.
- 일부 파일시스템/AMI에서 fallocate가 실패할 수 있습니다.
- 스왑 파일이 이미 존재하는 경우에도 무조건 재생성/마운트 시도를 합니다.
아래처럼 idempotent 체크와 dd 폴백을 추가하면 안전합니다.
-fallocate -l 2G /swapfile -chmod 600 /swapfile -mkswap /swapfile -swapon /swapfile -echo '/swapfile none swap sw 0 0' >> /etc/fstab +if ! grep -qE '^\s*/swapfile\s' /etc/fstab; then + if [ ! -f /swapfile ]; then + if ! fallocate -l 2G /swapfile 2>/dev/null; then + dd if=/dev/zero of=/swapfile bs=1M count=2048 status=none + fi + chmod 600 /swapfile + mkswap /swapfile + fi + swapon /swapfile || true + echo '/swapfile none swap sw 0 0' >> /etc/fstab +fi
2-2: ECS_CLUSTER 설정은 덮어쓰기 방식으로 idempotent하게 적용하세요.현재
>>는 재실행 시 중복 라인을 누적시킵니다. 다음과 같이 존재 시 교체, 미존재 시 생성으로 적용하는 편이 안전합니다.-echo ECS_CLUSTER=${ecs_cluster_name} >> /etc/ecs/ecs.config +if grep -q '^ECS_CLUSTER=' /etc/ecs/ecs.config 2>/dev/null; then + sed -i "s/^ECS_CLUSTER=.*/ECS_CLUSTER=${ecs_cluster_name}/" /etc/ecs/ecs.config +else + echo "ECS_CLUSTER=${ecs_cluster_name}" > /etc/ecs/ecs.config +fi
22-23: 패키지 매니저 혼용(yum/dnf) 및 mariadb105 패키지명 확인 필요.
- AL2023에서는
yum가dnf로 symlink되어 있어 동작 가능하나, AMI 차이에 따라 동작이 달라질 수 있으므로 단일 추상화로 처리하는 편이 안전합니다.dnf install -y mariadb105는 리포지토리/패키지명 매칭이 안 될 수 있습니다(스트림/서브패키지 명칭 차이). 실제 AMI에서 설치가 정상 동작하는지 확인 바랍니다.원하시면 패키지 매니저 자동 감지와 설치 실패 시 진단 로그를 남기는 보일러플레이트를 제안드리겠습니다.
Also applies to: 32-32
14-14: 중복 chown 호출을 정리하세요.Line 14와 Line 30이 모두
/home/ec2-user/mysql에 대해 chown을 수행합니다. 한 번만 수행해도 충분합니다.Also applies to: 30-30
terraform/dev/locals.tf (1)
45-45: t2.micro 다운사이징 대비 리소스 사용량 점검 권고
CPU
terraform/dev/terraform.tfvars 기준
• api-dev = 500 CPU units
• mysql-dev = 256 CPU units
• datadog-agent-task = 256 CPU units
→ 총합 1,012 / 1,024 CPU units (단일 t2.micro 한계에 근접)메모리
• api-dev = 256 MiB
• mysql-dev(memoryReservation) = 128 MiB
• datadog-agent-task = 256 MiB
→ 총합 640 MiB (1 GiB 중 약 384 MiB 여유)
※ OS·ECS·Docker 오버헤드를 고려하면 실사용 가능 여유는 더욱 줄어듭니다.t2 계열 CPU 크레딧
장시간 빌드/테스트 시 CPU 크레딧 소진으로 인한 스로틀 발생 가능성이 높으므로
ALB 지연·시스템 로드·CPU 크레딧 모니터링 설정을 권장합니다.JVM GC 옵션
GC 옵션 제거로 JDK 기본 GC(G1)로 회귀했을 가능성이 큽니다.
256 MiB 환경에서는 직렬 GC도 고려할 수 있으나, 우선 실제 메모리·응답시간을 관측한 뒤 최적화 방안을 결정하시길 권장드립니다.필요 시 아래 스크립트로 dev 환경 태스크의 CPU/메모리 합계를 재확인할 수 있습니다.
#!/bin/bash # 각 태스크의 cpu/memory 값을 추출하여 합계를 계산 api_cpu=$(rg -nP 'api-dev\s*=\s*{(?s).*?^\s*cpu\s*=\s*(\d+)' -r '$1' terraform/dev/terraform.tfvars) api_mem=$(rg -nP 'api-dev\s*=\s*{(?s).*?^\s*memory(Reservation)?\s*=\s*(\d+)' -r '$2' terraform/dev/terraform.tfvars) mysql_cpu=$(rg -nP 'mysql-dev\s*=\s*{(?s).*?^\s*cpu\s*=\s*(\d+)' -r '$1' terraform/dev/terraform.tfvars) mysql_mem=$(rg -nP 'mysql-dev\s*=\s*{(?s).*?^\s*memory(Reservation)?\s*=\s*(\d+)' -r '$2' terraform/dev/terraform.tfvars) dd_cpu=$(rg -nP '"datadog-agent-task"\s*=\s*{(?s).*?^\s*cpu\s*=\s*(\d+)' -r '$1' terraform/dev/terraform.tfvars) dd_mem=$(rg -nP '"datadog-agent-task"\s*=\s*{(?s).*?^\s*memory\s*=\s*(\d+)' -r '$1' terraform/dev/terraform.tfvars) total_cpu=$((api_cpu + mysql_cpu + dd_cpu)) total_mem=$((api_mem + mysql_mem + dd_mem)) echo "CPU units total: ${total_cpu} / 1024" echo "Memory total (MiB): ${total_mem} / 1024 GiB"terraform/dev/terraform.tfvars (2)
23-25: api-dev 메모리 256MiB는 Java 서비스에서 OOM 위험이 높습니다.
- JDK의 기본 힙/메타스페이스/스레드 스택/코드캐시 합으로 256MiB를 초과하기 쉽습니다.
- 추가된 호스트 스왑은 컨테이너 hard limit을 넘겨 사용하게 해주지 못합니다. 컨테이너가 제한치를 넘으면 OOM으로 종료됩니다.
완충 여지를 위해 soft limit을 두는 방안을 권장합니다(현 PR 범위를 넘기지 않는 최소 변경).
api-dev = { - cpu = 500 - memory = 256 + cpu = 500 + memoryReservation = 128 + memory = 256또는, 로그 오버헤드를 줄이기 위해 GC 로그를 stdout 또는 파일 한쪽만 남기도록
locals.tf의 커맨드를 간소화하는 것도 효과적입니다. 우선 현재 설정으로 실제 메모리 사용량을 관측하고 필요 시 조정하시죠.
50-50: mysql-dev 메모리 256MiB는 InnoDB 기본 설정에서 불안정할 수 있습니다.
- 초기화/DDL/간단한 쿼리에서도 InnoDB 버퍼 풀·redo 로그·스레드 스택이 합쳐 256MiB를 빠르게 소모할 수 있습니다.
- 대안:
- 최소 변경:
memoryReservation = 128추가로 순간 피크를 흡수.- 설정 조정: my.cnf로
innodb_buffer_pool_size(예: 64M) 등 축소. 필요 시 conf.d를 마운트하는 볼륨을 추가해 드릴 수 있습니다.적용 전후로 컨테이너 재시작/oom 이벤트가 없는지 ECS 이벤트와 컨테이너 로그로 확인 부탁드립니다.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
terraform/dev/locals.tf(1 hunks)terraform/dev/scripts/user-data.sh(1 hunks)terraform/dev/terraform.tfvars(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: lvalentine6
PR: YAPP-Github/26th-Web-Team-1-BE#181
File: src/main/java/eatda/controller/story/StoryResponse.java:29-32
Timestamp: 2025-08-17T18:38:26.970Z
Learning: lvalentine6 prefers to manage PR scope carefully and defer non-critical improvements to future refactoring when the current PR is already large in scope, showing good judgment in prioritizing deliverable completion over scope expansion.
Learnt from: lvalentine6
PR: YAPP-Github/26th-Web-Team-1-BE#181
File: src/main/java/eatda/controller/story/StoryRegisterRequest.java:11-17
Timestamp: 2025-08-17T18:37:21.953Z
Learning: lvalentine6 prefers to apply validation annotations consistently across all record classes in the project rather than implementing them piecemeal, prioritizing architectural consistency and maintainability.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: test
leegwichan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
프로젝트 발표 후까지도 고생하셨습니다! Approve 하겠습니다!
|
🎉 This PR is included in version 1.8.0-develop.11 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version 1.8.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |



✨ 개요
🧾 관련 이슈
#189
🔍 참고 사항 (선택)
Eatda-Server로 수정하는게 어떨까요??Summary by CodeRabbit