admin管理员组文章数量:1384967
I've got 12 URLs and each need to be hit with 100 (NUM_EVENTS) requests per second continuously (or with a sleep interval if needed) for 10 (RUNTIME_TOTAL_DURATION) seconds.
I don't need to wait for all the responses of the previous batch of requests before firing the next batch of requests. So, I've kept VUs:12 (aiming to make one VU hit one URL), iterations:12 and the default function has a while loop in which I'm using http.asyncRequest() as shown below.
export let options = {
vus: 12,
iterations: 12,
// duration: '1h',
insecureSkipTLSVerify: true,
thresholds: {
http_req_duration: ['p(95)<2000'],
http_req_failed: ['rate<0.01']
}
};
// **API Endpoints & Authentication for Different VUs**
const CREDENTIALS = [
{ url: 'url', username: 'username', password: 'password' }, {}, {}, ...
]; // Array of 12 objects
const NUM_EVENTS = 100;
const ENTITY_PREFIX = "ABC";
const RUNTIME_TOTAL_DURATION = 10; // in seconds
const getResponse = false;
const SLEEP_INTERVAL = 1;
// **Main Test Execution**
export default function () {
const userIndex = (__VU - 1) % CREDENTIALS.length;
const API_URL = CREDENTIALS[userIndex].url;
const USERNAME = CREDENTIALS[userIndex].username;
const PASSWORD = CREDENTIALS[userIndex].password;
let totalEvents = parsedCSV.length;
let startTime = Date.now();
let duration = RUNTIME_TOTAL_DURATION * 1000;
let iteration = 0;
while (Date.now() - startTime < duration) {
let batchStartIndex = (iteration * NUM_EVENTS) % totalEvents;
let batchEndIndex = Math.min(batchStartIndex + NUM_EVENTS, totalEvents);
for (let i = batchStartIndex; i < batchEndIndex; i++) {
let event = parsedCSV[i];
event.entity = `${ENTITY_PREFIX}_${event.entity}`;
event.entityid = event.entity;
event.parameterid = event.parametername;
let payload = JSON.stringify(event);
let params = {
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic ' + encoding.b64encode(`${USERNAME}:${PASSWORD}`)
},
insecureSkipTLSVerify: true,
};
let request = http.asyncRequest('POST', API_URL, payload, params);
if (getResponse) {
request.then(res => {
console.log(`
本文标签:
版权声明:本文标题:javascript - Sending 'n' concurrent http requests per sec continuously for a duration of 'd' sec 内容由网友自发贡献,该文观点仅代表作者本人,
转载请联系作者并注明出处:http://www.betaflare.com/web/1744513407a2610014.html,
本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论