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(`

本文标签: