Tips and Tricks — K6
3 min readJan 7, 2023
Providing Specifications on the Test Run
- You can use the
k6 run --vus=10 --duration=30s script.js
command to specify the number of virtual users (VUs) and the duration of the test. This can be useful for running tests with different levels of concurrency and for controlling the length of the test. - The
k6 run --no-throttle
flag can be used to disable the automatic rate limiting that K6 applies to test requests. This can be useful if you want to test the maximum possible load that your system can handle. - The
k6 run --iterations=1000
command can be used to specify the number of iterations that K6 should perform during a test. This can be useful if you want to run a fixed number of requests rather than running the test for a fixed duration. - The
k6 run --no-connection-reuse
flag can be used to disable connection reuse during a test. This can be useful for simulating the behavior of real users who are opening new connections for each request. - The
k6 run --rps=1000
command can be used to specify the number of requests per second that K6 should send during the test. This can be useful for running tests with a fixed request rate. - You can use the
--compatibility
flag to specify the version of the HTTP/1.1 protocol that K6 should use when making requests. This can be useful if you need to test a system that only supports a specific version of the protocol.
Output & Metrics Visualization
- The
k6 stats
command can be used to collect and analyze performance metrics during a test. This can be useful for identifying performance bottlenecks and for understanding how your system is behaving under load. - K6 has a built-in graphical user interface (GUI) that can be used to visualize the results of a test. You can access the GUI by running the
k6 run --ui
command and then visiting the URL displayed in the output.
Recording a Test
You can use the k6 cloud
command to record a test using K6. This command is used to run tests on the Load Impact cloud platform, which allows you to record tests and then replay them to simulate different load scenarios.
To record a test using k6 cloud
, follow these steps:
- Install the
k6
command-line tool on your computer:npm install -g k6
. - Create a script file containing the test that you want to record. This script should define the requests that K6 should make, as well as any checks or assertions that you want to perform.
- Use the
k6 login
command to log in to your Load Impact account. You will need to provide your Load Impact API token, which you can find in your account settings on the Load Impact website. - Use the
k6 cloud record
command to start recording the test. This command will upload your test script to the Load Impact cloud platform and start executing the test. - When you are ready to stop recording the test, use the
k6 cloud stop
command to end the test and save the results. - Use the
k6 cloud list
command to view a list of all the recorded tests in your Load Impact account. You can use the ID of a recorded test to replay it using thek6 cloud replay
command.
I hope this helps! Let me know if you have any other questions about using K6 to record tests.