Skip to main content

k6 Local 부하 테스트


설치

yay -S k6

k6 스크립트

script.js
import { sleep } from "k6";
import http from "k6/http";

export const options = {
vus: 100, // Virtual User(VU) 수, --vus <number>
duration: "10s", // --duration <duration>
};

export function setup() {
return {}; // data
}

export default function (data) {
// VU가 실행하는 코드
const url = "http://localhost:8080/v2/models/model/infer";
const params = {
headers: {
"Content-Type": "application/json",
},
};
const body = JSON.stringify({
id: "1",
inputs: [
{
name: "input0",
shape: [1],
datatype: "STR",
data: ["CC(C)(C)C(=O)OC1=CC=C(C=C1)S(=O)(=O)NC2=CC=CC=C2C(=O)NCC(=O)O"],
},
],
outputs: [],
});

http.post(url, body, params);

sleep(0.5);
}

export function teardown(data) {}
k6 run [<flags>] script.js
  • <flags>: script.js의 options를 재정의할 수 있습니다.
    • https://k6.io/docs/using-k6/k6-options/how-to/
    • --batch <number>: http.batch를 사용할 때, 한 VU가 한 번에 연결할 커넥션 수
    • --batch-per-host <number>: http.batch를 사용할 때, 한 VU가 호스트 당 한 번에 연결할 커넥션 수
    • --duration <duration>: 테스트를 실행할 시간

결과


http_req_duration..............: avg=814.5ms  min=25.55ms med=827.68ms max=965.33ms p(90)=899.68ms p(95)=931.89ms

요청 후 응답까지 걸린 시간을 예시로 살펴 보면 아래와 같은 의미를 같습니다.

  • avg: 평균값
  • min: 최소값
  • med: 중앙값
  • max: 최대값
  • p(<percent>): <percent>% 에 해당하는 값으로 med=p(50) 입니다.