DEV Community

How to send more requests with variable payload size in K6?

- This k6 script simulates multiple virtual users (VUs) performing HTTP requests for load testing. - It utilizes an external service for authentication and obtains an access token during setup. - A JSON payload of a specified size is generated for each request. - Two scenarios are defined: perVuIterations with 20 VUs and 5000 iterations, and constantRequestRate with a constant rate of 248 requests per second. - Options for the test include skipping TLS verification and selecting scenarios based on an environment variable. - Each VU sends a POST request to a specified endpoint using the access token and payload. - The payload generation function constructs a JSON object containing an array of payloads matching the target size. - The script allows for customizing the load pattern using the stages option for gradual ramp-up. - It performs authentication using an external service and includes response checks for validation. - The script effectively simulates user interactions with an application, enabling performance evaluation under various conditions.
favicon
dev.to
dev.to