我正在尝试找出一种在 k6 中发出两个单独请求的方法,每个请求相对于另一个请求都是有限的。
例如,我创建了两个 POST 请求,我希望一个被命中 90% 的测试运行,另一个被命中 10%,以模拟同一 HTTP 服务器上的请求命中更繁忙和更不繁忙的端点。
谢谢
使用scenarios通过指定一个constant arrival rate executor调用不同请求率的不同测试函数。
您必须手动预先计算每个端点的费率,但您可以轻松定义一个函数来根据总基本费率计算正确的费率。
const TOTAL_RPS = 100;
function rps(percentage) {
return TOTAL_RPS * percentage;
}
export const options = {
scenarios: {
busy: {
exec: 'busy_endpoint',
executor: 'constant-arrival-rate',
duration: '10m',
preAllocatedVUs: 10,
rate: rate(0.9) // 90%
},
lazy: {
exec: 'less_busy_endpoint',
executor: 'constant-arrival-rate',
duration: '10m',
preAllocatedVUs: 10,
rate: rate(0.1), // // 10%
}
}
};
export function busy_endpoint() {
// will be called 90 times per second (90% of 100 rps)
http.get('http://example.com');
}
export function less_busy_endpoint() {
// will be called 10 times per second (10% of 100 rps)
http.get('http://example.com');
}