import http from 'k6/http'; import { sleep } from 'k6'; export const options = { // 부하를 생성하는 단계(stages)를 설정 stages: [ // 10분에 걸쳐 vus(virtual users, 가상 유저수)가 50에 도달하도록 설정 { duration: '10m', target: 50 } ], }; export default function () { let random = Math.random(); // 100명 중 5명의 비율로 게시글을 작성 if (random < 0.05) { const data = { title: '제목', content: '내용' }; http.post('http://{ELB 주소}/boards', JSON.stringify(data), { headers: { 'Content-Type': 'application/json' }, }); // 100명 중 95명의 비율로 게시글을 조회 } else { http.get('http://{ELB 주소}/boards'); } // 1초 휴식 sleep(1); }
$ K6_WEB_DASHBOARD=true k6 run script.js
http://{k6가 실행되고 있는 EC2 IP 주소}:5665으로 접속하기

