Spring 개발일지

[개인 프로젝트] 성능테스트 준비

김둘리 2026. 4. 16. 16:14

 

튜터님과 1차적으로 코드 리뷰를 마쳤고 성능테스트를 하기로 했다

일단 성능테스트 종류들은 다음과 같다.

 

k6 자바스크립트로 스크립트 작성, 가볍고 빠름 쉬움
JMeter GUI 있음, 설정이 많고 무거움 중간
Gatling Scala 기반, 리포트 이쁨 중간
Locust 파이썬 기반 중간

나는 그중에 k6를 하기로 선택!

 

이유는

  • 스크립트가 자바스크립트라 직관적
  • Prometheus + Grafana 랑 연동이 좋음
  • 가볍고 설치가 쉬움

 

성능테스트를 위한 순서는 다음과 같다.

 

1. Spring Actuator 추가 (각 서비스 메트릭 노출)

2. Prometheus 설정 (메트릭 수집) 

3. Grafana 설정 (시각화) 

4. k6로 성능 테스트 

5. Grafana에서 결과 확인

 

 

1. 각 서비스 build.gradle 에 추가

4개 서비스 (user, product, order, notification) 전부 추가

implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'

 


2. 각 서비스 application.yml 에 추가

management:
  endpoints:
    web:
      exposure:
        include: health, info, prometheus, metrics
  endpoint:
    prometheus:
      enabled: true
  prometheus:
    metrics:
      export:
        enabled: true
 

3. Prometheus + Grafana Docker Compose 설정

루트에 docker-compose.yml 생성:

version: '3.8'

services:
  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    ports:
      - "9090:9090"
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml

  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    ports:
      - "3000:3000"
    depends_on:
      - prometheus

4. prometheus.yml 생성 (루트에)

global:
  scrape_interval: 5s

scrape_configs:
  - job_name: 'user-service'
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['host.docker.internal:8081']

  - job_name: 'product-service'
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['host.docker.internal:8082']

  - job_name: 'order-service'
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['host.docker.internal:8083']

  - job_name: 'notification-service'
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['host.docker.internal:8084']