https://grafana.com/docs/k6/latest/get-started
install and run
- # create file script.js
- k6 new [filename] # create file ‘script.js’ in the current directory
复制代码 3 run
- reports
默认环境下,k6 将总结结果打印到 stdout 。
script.js
- import http from 'k6/http';
- import { check, sleep } from 'k6';
- export const options = {
- vus: 10,
- duration: '30s',
- };
- export default function () {
- const res = http.get('http://test.k6.io');
- check(res, { 'status was 200': (r) => r.status == 200 });
- sleep(1);
- }
复制代码 options
https://grafana.com/docs/k6/latest/using-k6/k6-options/reference/
- vus
虚拟用户数
- duration
连续时间
- rps
每秒哀求数量
哀求总数 = vus * rps * durance(s)
- import http from 'k6/http';
- import { check, sleep } from 'k6';
- export const options = {
- maxRedirects: 4,
- duration: '300s',
- vus: 10,
- rps: 300
- };
- // stages : 逐步提升/降低
- export const options = {
- stages: [
- { target: 200, duration: '30s' },
- { target: 0, duration: '30s' },
- ],
- };
- export const options = {
- stages: [
- { duration: '10s', target: 100 },
- { duration: '5m', target: 100 },
- { duration: '10s', target: 0 },
- ],
- rps: 100,
- };
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |