Skip to content

Conversation

@lvalentine6
Copy link
Member

@lvalentine6 lvalentine6 commented Aug 25, 2025

✨ 개요

  • 비용 최적화를 위해 dev 환경의 인스턴스를 스케일다운 했습니다.
  • 각 서비스에 할당하는 메모리를 조정하였습니다.
  • G1GC를 사용하지 않고 Serial GC를 사용하도록 옵션을 삭제했습니다.

🧾 관련 이슈

#189

🔍 참고 사항 (선택)

  • 추가적으로 저희 리포지토리명을 Eatda-Server 로 수정하는게 어떨까요??

Summary by CodeRabbit

  • Chores
    • 개발 환경의 컴퓨팅 리소스를 경량화해 비용 효율성을 개선했습니다(인스턴스 및 컨테이너 CPU/메모리 축소).
    • 메모리 제약 환경에 맞춰 런타임 옵션을 정리하고, 기존 실행/로그 설정은 유지했습니다.
    • 저메모리 상황에서의 안정성을 위해 스왑 공간(2GB)을 구성했습니다.
    • 모든 변경은 개발 클러스터에 한정되며, 서비스 인터페이스와 기능 동작에는 변화가 없습니다. 사용자 영향은 없습니다.

@coderabbitai
Copy link

coderabbitai bot commented Aug 25, 2025

Walkthrough

개발 환경용 Terraform 구성 변경: EC2 인스턴스 타입을 t2.micro로 축소, ECS 태스크의 CPU/메모리 할당 축소, API 컨테이너의 일부 JVM 옵션 제거. EC2 user-data에 2G 스왑 파일 생성 및 영구 적용 로직 추가.

Changes

Cohort / File(s) Change Summary
Terraform dev 구성 조정
terraform/dev/locals.tf, terraform/dev/terraform.tfvars
인스턴스 타입 t3a.smallt2.micro. api-dev 태스크 CPU 1500→500, 메모리 1024→256. mysql-dev 메모리 512→256(Reservation 128 유지). api-dev 컨테이너에서 다수 JVM GC/메모리 플래그 제거(나머지 옵션 및 설정은 유지).
EC2 부팅 스크립트 스왑 추가
terraform/dev/scripts/user-data.sh
ECS 클러스터 설정 이후 2G 스왑 파일 생성, 권한 600 설정, mkswap/swapon 실행, /etc/fstab에 추가해 영구화. 기존 디렉터리 생성 로직 변경 없음.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

초원서 깡총, dev 바람 솔솔 불어와—
t2에 둥지 틀고, 메모린 가볍게 접어놔.
GC 깃털 덜어내고 로그만 살짝 남겨봐.
스왑은 포근 담요, 밤샘에도 끄덕 없지!
오늘도 배포 한 입, 당근으로 축배! 🥕🐇

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 Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/PRODUCT-276

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link

📄 Terraform Plan Summary

🛡️ Common Infrastructure


No plan summary

Status: ✅ No Changes


🛠️ Development Environment

  ~ update in-place
  ~ resource aws_instance dev {
  ~ ecs_task_definitions_check = (sensitive value)
Plan: 2 to add, 1 to change, 2 to destroy.

Status: 🔄 Changes Detected


📋 Full Results: View in Actions

@sonarqubecloud
Copy link

@lvalentine6 lvalentine6 changed the title refactor: 개발 환경 스케일다운 및 스왑 메모리 할당 [Refactor] 개발 환경 스케일다운 및 스왑 메모리 할당 Aug 25, 2025
Copy link

@coderabbitai coderabbitai bot left a 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에서는 yumdnf로 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 39af70a and 9bf2e7e.

📒 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

Copy link
Member

@leegwichan leegwichan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

프로젝트 발표 후까지도 고생하셨습니다! Approve 하겠습니다!

@lvalentine6 lvalentine6 merged commit 29a9fa7 into develop Aug 25, 2025
12 checks passed
@lvalentine6 lvalentine6 deleted the refactor/PRODUCT-276 branch August 25, 2025 08:11
@github-actions
Copy link

🎉 This PR is included in version 1.8.0-develop.11 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions
Copy link

🎉 This PR is included in version 1.8.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants