Skip to content

[Infra] Add EFS mount for ML models persistence #30

@fregataa

Description

@fregataa

Summary

ML 모델을 EFS에 저장하여 콜드 스타트 시간을 단축하고, 여러 태스크 간 모델 파일을 공유

Background

  • Issue #27에서 S3 버킷 및 IAM 정책 설정 완료
  • 현재: 컨테이너 시작 시 S3에서 모델 다운로드 (콜드 스타트 ~30초)
  • 목표: EFS 마운트로 모델 파일 영구 저장 (콜드 스타트 ~5초)

Current Architecture

Container Start → S3 Download (~30s) → Model Load → Ready

Target Architecture

EFS (persistent)
├── detector/chatgpt-detector-roberta/
└── feedback/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf

Container Start → EFS Mount (instant) → Model Load → Ready

Benefits

  • 콜드 스타트 시간 대폭 단축 (~30s → ~5s)
  • 모든 태스크가 동일한 모델 파일 공유
  • S3 다운로드 비용 절감
  • 스케일 아웃 시 빠른 태스크 시작

Tasks

  • EFS File System 생성 (Terraform 모듈)
  • EFS Mount Target 설정 (Private Subnets)
  • EFS Security Group 설정
  • ML Server Task Definition에 EFS 볼륨 마운트 추가
  • ModelLoader에서 EFS 경로 우선 확인 로직 추가
  • 초기 모델 업로드 스크립트 작성

Terraform Changes

# New EFS module
resource "aws_efs_file_system" "ml_models" {
  creation_token = "${var.project}-ml-models"
  encrypted      = true
}

resource "aws_efs_mount_target" "ml_models" {
  for_each        = toset(var.private_subnet_ids)
  file_system_id  = aws_efs_file_system.ml_models.id
  subnet_id       = each.value
  security_groups = [aws_security_group.efs.id]
}

# ECS Task Definition
volume {
  name = "ml-models"
  efs_volume_configuration {
    file_system_id = var.efs_file_system_id
    root_directory = "/"
  }
}

mountPoints = [{
  containerPath = "/app/models"
  sourceVolume  = "ml-models"
}]

Considerations

  • EFS 비용 (GB/월 + 처리량)
  • 첫 배포 시 모델 업로드 필요
  • Bursting vs Provisioned throughput 선택

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions