-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from f-lab-edu/feature/55-load-test
[#55] 부하 테스트
- Loading branch information
Showing
15 changed files
with
397 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { check, sleep } from "k6"; | ||
import http from "k6/http"; | ||
import { Trend } from "k6/metrics"; | ||
|
||
const dataReceivedTrend = new Trend("data_received_size", true); | ||
|
||
export const options = { | ||
scenarios: { | ||
simple_rps_test: { | ||
/* 일정한 RPS(Request Per Second)를 유지하는 실행기 타입 */ | ||
executor: "constant-arrival-rate", | ||
/* 초당 실행할 반복 횟수 */ | ||
rate: 4, | ||
/* rate의 시간 단위 (1s, 1m, 1h 등) */ | ||
timeUnit: "1s", | ||
/* 전체 테스트 실행 시간 */ | ||
duration: "1m", | ||
/* 테스트 시작 시 미리 할당할 가상 사용자 수 */ | ||
preAllocatedVUs: 10, | ||
/* 최대 가상 사용자 수 (필요시 추가 할당) */ | ||
maxVUs: 30, | ||
}, | ||
}, | ||
// 태그 추가 | ||
tags: { | ||
testName: "articles-api-test", | ||
testType: "performance", | ||
component: "articles", | ||
version: "1.0", | ||
}, | ||
thresholds: { | ||
/* HTTP 요청 실패율이 5% 미만이어야 함 */ | ||
http_req_failed: [{ threshold: "rate<0.05", abortOnFail: true }], | ||
/* 부하로 인한 요청 누락률이 5% 미만이어야 함 */ | ||
dropped_iterations: [{ threshold: "rate<0.05", abortOnFail: true }], | ||
// /* 95%의 요청이 3초 이내에 완료되어야 함 */ | ||
http_req_duration: [{ threshold: "p(95)<3000", abortOnFail: true }], | ||
}, | ||
}; | ||
|
||
export default function () { | ||
const BASE_URL = __ENV.BASE_URL || "http://localhost:4000"; | ||
const ACCESS_TOKEN = __ENV.ACCESS_TOKEN || "access_token"; | ||
|
||
const cursors = [12001, 23000, 30000, 40000, 50000]; | ||
const cursor = cursors[Math.floor(Math.random() * cursors.length)]; | ||
const limit = 10; | ||
|
||
const articlesResponse = http.get( | ||
`${BASE_URL}/articles?cursor=${cursor}&limit=${limit}`, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${ACCESS_TOKEN}`, | ||
}, | ||
timeout: "180s", | ||
}, | ||
); | ||
|
||
dataReceivedTrend.add(articlesResponse.body.length); | ||
|
||
check(articlesResponse, { | ||
"articles status is 200": (r) => r.status === 200, | ||
}); | ||
|
||
sleep(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { check, sleep } from "k6"; | ||
import http from "k6/http"; | ||
import { Trend } from "k6/metrics"; | ||
|
||
const dataReceivedTrend = new Trend("data_received_size", true); | ||
|
||
export const options = { | ||
scenarios: { | ||
simple_rps_test: { | ||
executor: "constant-arrival-rate", | ||
rate: 450, // 초당 10개의 요청 (RPS) | ||
timeUnit: "1s", // RPS 단위 설정 | ||
duration: "1m", // 테스트 지속 시간: 5분 | ||
preAllocatedVUs: 1000, // 미리 할당할 VU 수 | ||
maxVUs: 2000, // 최대 VU 수 | ||
}, | ||
}, | ||
// 태그 추가 | ||
tags: { | ||
testName: "participations-api-test", | ||
testType: "performance", | ||
component: "participations", | ||
version: "1.0", | ||
}, | ||
thresholds: { | ||
http_req_failed: [{ threshold: "rate<0.05", abortOnFail: true }], | ||
dropped_iterations: [{ threshold: "rate<0.05", abortOnFail: true }], | ||
http_req_duration: [{ threshold: "p(95)<3000", abortOnFail: true }], | ||
}, | ||
}; | ||
|
||
export default function () { | ||
const BASE_URL = __ENV.BASE_URL || "http://localhost:4000"; | ||
const ACCESS_TOKEN = __ENV.ACCESS_TOKEN || "access_token"; | ||
|
||
const cursors = [12001, 23000, 30000, 40000, 50000]; | ||
const cursor = cursors[Math.floor(Math.random() * cursors.length)]; | ||
const limit = 10; | ||
|
||
const articleIds = [23640, 12714, 11621, 43514]; | ||
|
||
const participationsResponse = http.get( | ||
`${BASE_URL}/participations/articles/${articleIds[Math.floor(Math.random() * articleIds.length)]}?cursor=${cursor}&limit=${limit}`, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${ACCESS_TOKEN}`, | ||
}, | ||
timeout: "60s", | ||
}, | ||
); | ||
|
||
dataReceivedTrend.add(participationsResponse.body.length); | ||
|
||
check(participationsResponse, { | ||
"participations status is 200": (r) => r.status === 200, | ||
}); | ||
|
||
sleep(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { check, sleep } from "k6"; | ||
import http from "k6/http"; | ||
import { Trend } from "k6/metrics"; | ||
|
||
const dataReceivedTrend = new Trend("data_received_size", true); | ||
|
||
export const options = { | ||
scenarios: { | ||
simple_rps_test: { | ||
executor: "constant-arrival-rate", | ||
rate: 1, | ||
timeUnit: "1s", | ||
duration: "1m", | ||
preAllocatedVUs: 5, | ||
maxVUs: 10, | ||
}, | ||
}, | ||
thresholds: { | ||
http_req_failed: [{ threshold: "rate<0.05", abortOnFail: true }], | ||
dropped_iterations: [{ threshold: "rate<0.05", abortOnFail: true }], | ||
http_req_duration: [{ threshold: "p(95)<3000", abortOnFail: true }], | ||
}, | ||
}; | ||
|
||
export default function () { | ||
const BASE_URL = __ENV.BASE_URL || "http://localhost:4000"; | ||
|
||
const timestamp = new Date().getTime(); | ||
const randomValue = Math.random().toString(36).substring(2, 15); | ||
const uniqueId = `${timestamp}-${randomValue}`; | ||
|
||
const signupResponse = http.post(`${BASE_URL}/auth/sign-up`, { | ||
email: `user-${uniqueId}@test.com`, | ||
password: "123456", | ||
name: `user-${uniqueId}`.substring(0, 6), | ||
nickname: `nickname-${uniqueId}`.substring(0, 6), | ||
}); | ||
|
||
dataReceivedTrend.add(signupResponse.body.length); | ||
|
||
const success = check(signupResponse, { | ||
"signup status is 201": (r) => r.status === 201, | ||
}); | ||
|
||
if (!success) { | ||
console.error( | ||
`Request failed. Status: ${signupResponse.status}, Body: ${signupResponse.body}`, | ||
); | ||
} | ||
|
||
sleep(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.