如何在不使用时长参数的情况下同时发送多个vu请求?



我的主要目标是同时发送(例如)5个请求。我发现我不仅可以设置选项vus: 5并且同时接收5个请求。

有没有一种方法可以做到这一点,而不需要像使用短持续时间这样的技巧,并且没有vu的RPS限制?

我只是试图设置唯一的选项,它不能正常工作。(在下面的例子)

export const options = {
vus: 5,
};

我还发现,我能够运行测试,例如30秒的VUs 5,这是网络历史上最小的ddos(示例如下),但我想了解是否有一种方法在同一时刻只发送5个请求,而不是更多。

export const options = {
vus: 5,
duration: '30s',
};

在最流行的竞争对手负载测试工具中最接近的功能被称为:

  • LoadRunner中的集合点
  • Apache JMeter中的同步定时器

在k6上下文中快速查找这两者,得到这篇文章:与k6会合,这似乎正是您正在寻找的。

上述文章中的实现示例:

import http from 'k6/http';
import exec from 'k6/execution';
import { sleep } from 'k6';
export const options = {
stages: [
{ duration: '40s', target: 20 },
{ duration: '2m', target: 20 },
{ duration: '5s', target: 0 },
],
};

export default function () {
const rendezPeriod = 30000;
/*Step1*/http.get('https://test-api.k6.io/public/crocodiles/1/');
sleep(Math.random() * 5);
/*Step2*/http.get('https://test-api.k6.io/public/crocodiles/2/');
sleep(Math.random() * 5);
/*Step3*/http.get('https://test-api.k6.io/public/crocodiles/3/');
sleep(Math.random() * 5);
/*Step4*/http.get('https://test-api.k6.io/public/crocodiles/4/');
rendez(rendezPeriod);
/*Step5*/http.get('https://test-api.k6.io/public/crocodiles/');
sleep(Math.random() * 5);
/*Step6*/http.get('https://test-api.k6.io/public/crocodiles/5/');
sleep(Math.random() * 5);
/*Step7*/http.get('https://test-api.k6.io/public/crocodiles/6/');
sleep(Math.random() * 5);
/*Step8*/http.get('https://test-api.k6.io/public/crocodiles/1/');
sleep(Math.random() * 5);
}
// comment: quick implementation of rendezvous function in k6
//      stopping at periods, no user count ... yet
function rendez(rendezPeriod) {
//comment: soFar is the time since the test started
let soFar = new Date().getTime() - exec.scenario.startTime;
//comment: calculate how much to wait until next rendez
const waitTime = (rendezPeriod-(soFar%rendezPeriod))/1000;
sleep(waitTime);
}

最新更新