K6를 사용할 때는 VU의 임계점 아래에서 부하테스트를 해야한다. 내 서버의 VU 임계점을 알기 위해서는 실험을 해봐야 한다. k6의 stage를 사용해 점진적으로 부하를 늘리면서 p95와 iteration 수가 급격하게 줄어드는 구간을 찾는 것이다.

<aside> 💡

요약

그런데 첫 VU 범위는 어떻게 설정해야 할까?

예를 들어 VU를 500으로 설정하면 어떻게 될까? 업체가 아니라 개인용 컴퓨터에서도 버텨낼 수 있을까?

1차 테스트

넓고 얉게

stages: [
  { duration: '30s', target: 1 },
  { duration: '30s', target: 5 },
  { duration: '30s', target: 10 },
  { duration: '30s', target: 20 },
  { duration: '30s', target: 30 },
  { duration: '30s', target: 50 },
  { duration: '30s', target: 100 },
]

VU 임계점 확인 SCRIPT

import http from 'k6/http';
import { sleep, check } from 'k6';

export const options = {
  stages: [
    { duration: '30s', target: 1 },
    { duration: '30s', target: 5 },
    { duration: '30s', target: 10 },
    { duration: '30s', target: 20 },
    { duration: '30s', target: 30 },
    { duration: '30s', target: 50 },
  ],
};

const BASE_URL = '<https://host.docker.internal:8443>';

export default function () {
  const res = http.post(
    `${BASE_URL}/api/hotels/search`,
    JSON.stringify({
      checkIn: "2025-01-10",
      checkOut: "2025-01-11",
      latitude: 37.5007861,
      longitude: 127.0368861
    }),
    { headers: { 'Content-Type': 'application/json' } }
  );

  check(res, {
    '200 OK': r => r.status === 200,
  });

  sleep(1);
}

주의점. docker로 k6를 실행하기 때문에 'https://localhost:8443'가 아니라 const BASE_URL = '<https://host.docker.internal:8443>';