K6
Grafana k6 是一款开源、开发人员友好且可扩展的负载测试工具。K6 可帮助您预防性能问题并主动提高可靠性。
k6 使用 javascript 脚本作为流程控制,提供更高的灵活性和可复用性。
install
brew install k6
# or
winget install k6 --source winget
config
模拟多个阶段用户的案例
import http from 'k6/http';
import { sleep } from 'k6';
export const options = {
// Key configurations for Stress in this section
stages: [
{ duration: '1m', target: 500 }, // traffic ramp-up from 1 to a higher 200 users over 10 minutes.
{ duration: '1m', target: 200 }, // stay at higher 200 users for 30 minutes
{ duration: '1m', target: 0 }, // ramp-down to 0 users
],
};
export default () => {
const urlRes = http.get('http://localhost:8080/token');
sleep(1);
// MORE STEPS
// Here you can have more steps or complex script
// Step1
// Step2
// etc.
};
test
k6 run script.js