No results for ""

Powered byAlgolia

Options allow you to configure how k6 will behave during test execution.

List of Options

OptionDescription
BatchMax number of simultaneous connections of a http.batch() call
Batch per hostMax number of simultaneous connections of a http.batch() call for a host
Blacklist IPsBlacklist IP ranges from being called
Compatibility ModeSupport running scripts with different ECMAScript modes
ConfigSpecify the config file in JSON format to read the options values
Discard Response BodiesSpecify if response bodies should be discarded
DurationA string specifying the total duration a test run should be run for
Execution SegmentLimit execution to a segment of the total test
Extension OptionsAn object used to set configuration options for third-party collectors
HostsAn object with overrides to DNS resolution
HTTP DebugLog all HTTP requests and responses
Include System Env VarsPass the real system environment variables to the runtime
IterationsA number specifying a fixed number of iterations to execute of the script
LingerA boolean specifying whether k6 should linger around after test run completion
Log OutputConfiguration about where logs from k6 should be send
LogFormatSpecify the format of the log output
Max RedirectsThe maximum number of HTTP redirects that k6 will follow
Minimum Iteration DurationSpecify the minimum duration for every single execution
No Connection ReuseA boolean specifying whether k6 should disable keep-alive connections
No Cookies ResetThis disables resetting the cookie jar after each VU iteration
No ThresholdsDisables threshold execution
No Usage ReportA boolean specifying whether k6 should send a usage report
No VU Connection ReuseA boolean specifying whether k6 should reuse TCP connections
PausedA boolean specifying whether the test should start in a paused state
Results OutputSpecify the results output
RPSThe maximum number of requests to make per second
ScenariosDefine advanced execution scenarios
Setup TimeoutSpecify how long the setup() function is allow to run before it's terminated
Skip TLS VerificationA boolean specifying whether should ignore TLS verifications
StagesA list of objects that specify the target number of VUs to ramp up or down
Summary exportOutput the end-of-test summary report to a JSON file
Supply Env VarAdd/override environment variable with VAR=value
System TagsSpecify which System Tags will be in the collected metrics
Summary Trend StatsDefine stats for trend metrics
TagsSpecify tags that should be set test wide across all metrics
Teardown TimeoutSpecify how long the teardown() function is allowed to run before it's terminated
ThresholdsConfigure under what conditions a test is successful or not
ThrowA boolean specifying whether to throw errors on failed HTTP requests
TLS AuthenticationA list of TLS client certificate configuration objects
TLS Cipher SuitesA list of cipher suites allowed to be used by in SSL/TLS interactions with a server
TLS VersionString or object representing the only SSL/TLS version allowed
User AgentA string specifying the User-Agent header when sending HTTP requests
VUsA number specifying the number of VUs to run concurrently
VUs MaxA number specifying max number of virtual users

Using Options

Options can be a part of the script code so that they can be version controlled. They can also be specified with command-line flags, environment variables or via a config file.

The order of precedence is: defaults < config file < exported script options < environment variables < command-line flags. Options from each subsequent level can be used to overwrite the options from the previous levels, with the CLI flags having the highest priority.

For example, you can define the duration in 4 different ways:

  • set the duration: "10s" option in the config file
  • set the duration: "10s" option in the script
  • define K6_DURATION as an environment variable
  • use the command-line flag -d 10s

The following JS snippet shows how to specify options in the script:

import http from 'k6/http';

export let options = {
  hosts: { 'test.k6.io': '1.2.3.4' },
  stages: [
    { duration: '1m', target: 10 },
    { duration: '1m', target: 20 },
    { duration: '1m', target: 0 },
  ],
  thresholds: { http_req_duration: ['avg<100', 'p(95)<200'] },
  noConnectionReuse: true,
  userAgent: 'MyK6UserAgentString/1.0',
};

export default function () {
  http.get('http://test.k6.io/');
}

You can also set the same options through a config file:

{
  "hosts": {
    "test.k6.io": "1.2.3.4"
  },
  "stages": [
    {
      "duration": "1m",
      "target": 10
    },
    {
      "duration": "1m",
      "target": 30
    },
    {
      "duration": "1m",
      "target": 0
    }
  ],
  "thresholds": {
    "http_req_duration": ["avg<100", "p(95)<200"]
  },
  "noConnectionReuse": true,
  "userAgent": "MyK6UserAgentString/1.0"
}

Or set some of the previous options via environment variables and command-line flags:

$ K6_NO_CONNECTION_REUSE=true K6_USER_AGENT="MyK6UserAgentString/1.0" k6 run ~/script.js

$ k6 run ---no-connection-reuse --user-agent "MyK6UserAgentString/1.0" ~/script.js

Below, you'll find details on all available options that can be specified within a script. It also documents the equivalent command line flag, environment variables or option when executing k6 run ... and k6 cloud ... that can be used to override options specified in the code.

Batch

The maximum number of simultaneous/parallel connections in total that an http.batch() call in a VU can make. If you have a batch() call that you've given 20 URLs to and --batch is set to 15, then the VU will make 15 requests right away in parallel and queue the rest, executing them as soon as a previous request is done and a slot opens. Available in both the k6 run and the k6 cloud commands

EnvCLICode / Config fileDefault
K6_BATCH--batchbatch20
export let options = {
  batch: 15,
};

Batch per host

The maximum number of simultaneous/parallel connections for the same hostname that an http.batch() call in a VU can make. If you have a batch() call that you've given 20 URLs to the same hostname and --batch-per-host is set to 5, then the VU will make 5 requests right away in parallel and queue the rest, executing them as soon as a previous request is done and a slot opens. This will not run more request in parallel then the value of batch. Available in both the k6 run and the k6 cloud commands

EnvCLICode / Config fileDefault
K6_BATCH_PER_HOST--batch-per-hostbatchPerHost6
export let options = {
  batchPerHost: 5,
};

Blacklist IPs

Blacklist IP ranges from being called. Available in k6 run and k6 cloud commands.

EnvCLICode / Config fileDefault
K6_BLACKLIST_IPS--blacklist-ipblacklistIPsnull
export let options = {
  blacklistIPs: ['10.0.0.0/8'],
};

Compatibility Mode

Support running scripts with different ECMAScript compatibility modes.

Read about the different modes on the JavaScript Compatibility Mode documentation.

EnvCLICode / Config fileDefault
K6_COMPATIBILITY_MODE--compatibility-modeN/A"extended"
$ k6 run --compatibility-mode=base script.js

Config

Specify the config file in JSON format to read the options values. If the config file is not specified, k6 will look for config.json in the loadimpact/k6 directory inside the regular directory for configuration files on the operating system.

For example in Linux/BSDs, it will look for config.json inside ${HOME}/.config/loadimpact/k6. Available in k6 run and k6 cloud commands

EnvCLICode / Config fileDefault
N/A--config <path>, -c <path>N/Anull

Discard Response Bodies

Specify if response bodies should be discarded by changing the default value of responseType to none for all HTTP requests. Highly recommended to be set to true and then only for the requests where the response body is needed for scripting to set responseType to text or binary. Lessens the amount of memory required and the amount of GC - reducing the load on the testing machine, and probably producing more reliable test results.

EnvCLICode / Config fileDefault
K6_DISCARD_RESPONSE_BODIES--discard-response-bodiesdiscardResponseBodiesfalse
export let options = {
  discardResponseBodies: true,
};

Duration

A string specifying the total duration a test run should be run for. During this time each VU will execute the script in a loop. Available in k6 run and k6 cloud commands.

EnvCLICode / Config fileDefault
K6_DURATION--duration, -ddurationnull
export let options = {
  duration: '3m',
};

Extension Options

An object used to set configuration options for third-party collectors, like plugins.

EnvCLICode / Config fileDefault
N/AN/Aextnull

This is an example of how to specify the test name (test runs/executions with the same name will be logically grouped for trending and comparison) when streaming results to k6 Cloud Performance Insights.

export let options = {
  ext: {
    loadimpact: {
      name: 'My test name',
    },
  },
};

Execution Segment

New in v0.27.0

These options specify how to partition the test run and which segment to run. If defined, k6 will scale the number of VUs and iterations to be run for that segment, which is useful in distributed execution. Available in k6 run and k6 cloud commands.

EnvCLICode / Config fileDefault
N/A--execution-segmentexecutionSegment"0:1"
N/A--execution-segment-sequenceexecutionSegmentSequence"0,1"

For example, to run 25% of a test, you would specify --execution-segment '25%', which would be equivalent to --execution-segment '0:1/4', i.e. run the first 1/4 of the test. To ensure that each instance executes a specific segment, also specify the full segment sequence, e.g. --execution-segment-sequence '0,1/4,1/2,1'. This way one instance could run with --execution-segment '0:1/4', another with --execution-segment '1/4:1/2', etc. and there would be no overlap between them.

In v0.27.0 this distinction is not very important, but it will be required in future versions when support for test data partitioning is added.

Hosts

An object with overrides to DNS resolution, similar to what you can do with /etc/hosts on Linux/Unix or C:\\Windows\\System32\\drivers\\etc\\hosts on Windows. For instance, you could set up an override which routes all requests for test.k6.io to 1.2.3.4.

From v0.28.0 it is also supported to redirect only from certain ports and/or to certain ports.

⚠️ Keep in mind!

This does not modify the actual HTTP Host header, but rather where it will be routed.

EnvCLICode / Config fileDefault
N/AN/Ahostsnull
export let options = {
  hosts: {
    'test.k6.io': '1.2.3.4',
    'test.k6.io:443': '1.2.3.4:8443',
  },
};

With the above code any request made to test.k6.io will be redirected to 1.2.3.4 without changing it port unless it's port is 443 which will be redirected to port 8443.

HTTP Debug

Log all HTTP requests and responses. Excludes body by default, to include body use --http-debug=full. Available in k6 run and k6 cloud commands.

Read more here.

EnvCLICode / Config fileDefault
K6_HTTP_DEBUG--http-debug,
--http-debug=full
httpDebugfalse
export let options = {
  httpDebug: 'full',
};

Include System Env Vars

Pass the real system environment variables to the runtime. Available in k6 run and k6 cloud commands.

EnvCLICode / Config fileDefault
N/A--include-system-env-varsN/Atrue for k6 run, but false for all other commands to prevent inadvertent sensitive data leaks.
$ k6 run --include-system-env-vars ~/script.js

Iterations

A number specifying a fixed number of iterations to execute of the script, as opposed to specifying a duration of time during which the script would run in a loop. *Note: The number of iterations is split between all VUs. Available in the k6 run and since v0.27.0 in the k6 cloud command as well. Tests that utilize the cloud require a duration as "infinite" tests are not allowed, the default maxDuration is 10 minutes when using iterations with the cloud service.

EnvCLICode / Config fileDefault
K6_ITERATIONS--iterations, -iiterations1
export let options = {
  iterations: 10,
};

Or, to run 10 VUs 10 times each:

export let options = {
  vus: 10,
  iterations: 100,
};

Linger

A boolean, true or false, specifying whether the k6 process should linger around after test run completion. Available in the k6 run command.

EnvCLICode / Config fileDefault
K6_LINGER--linger, -llingerfalse
export let options = {
  linger: true,
};

Log output

This option specifies where to send logs to and another configuration connected to it. Available in the k6 run command.

Possible values are:

  • none - disable
  • stdout - send to the standard output
  • stderr - send to the standard error output (this is the default)
  • loki - send logs to a loki server

The loki can additionally be configured as follows: loki=http://127.0.0.1:3100/loki/api/v1/push,label.something=else,label.foo=bar,limit=32,level=info,pushPeriod=5m32s,msgMaxSize=1231 Where all but the url in the beginning are not required. The possible keys with their meanings and default values:

keymeaningdefault value
nothingthe endpoint to which to send logshttp://127.0.0.1:3100/loki/api/v1/push
label.labelNameadds an additional label with the provided key and value to each messageN/A
limitthe limit of message per pushPeriod, an additonal log is send when the limit is reached, logging how many logs were dropped100
levelthe minimal level of a message so it's send to lokiall
pushPeriodat what period to send log lines1s
profilewhether to print some info about performance of the sending to lokifalse
msgMaxSizehow many symbols can there be at most in a message. Messages bigger will miss the middle of the message with an additonal few characters explaining how many characters were dropped.1048576
EnvCLICode / Config fileDefault
K6_LOG_OUTPUT--log-outputN/Astderr
$ k6 run --log-output=stdout script.js

LogFormat

A value specifying the log format. By default, k6 includes extra debug information like date and log level. The other options available are:

  • json: print all the debug information in JSON format.

  • raw: print only the log message.

EnvCLICode / Config fileDefault
K6_LOGFORMAT--logformat, -fN/A
$ k6 run --logformat raw test.js

Max Redirects

The maximum number of HTTP redirects that k6 will follow before giving up on a request and erroring out. Available in both the k6 run and the k6 cloud commands.

EnvCLICode / Config fileDefault
K6_MAX_REDIRECTS--max-redirectsmaxRedirects10
export let options = {
  maxRedirects: 10,
};

Minimum Iteration Duration

Specifies the minimum duration for every single execution (i.e. iteration) of the default function should be. Any iterations that are shorter than it will cause that VU to sleep for the remainder of the time until the specified minimum duration is reached.

EnvCLICode / Config fileDefault
K6_MIN_ITERATION_DURATION--min-iteration-durationminIterationDuration0 (disabled)
export let options = {
  minIterationDuration: '10s',
};

No Connection Reuse

A boolean, true or false, specifying whether k6 should disable keep-alive connections. Available in k6 run and k6 cloud commands.

EnvCLICode / Config fileDefault
K6_NO_CONNECTION_REUSE--no-connection-reusenoConnectionReusefalse
export let options = {
  noConnectionReuse: true,
};

No Cookies Reset

This disables the default behavior of resetting the cookie jar after each VU iteration. If it's enabled, saved cookies will be persisted across VU iterations.

EnvCLICode / Config fileDefault
K6_NO_COOKIES_RESETN/AnoCookiesResetfalse
export let options = {
  noCookiesReset: true,
};

No Thresholds

Disables threshold execution. Available in the k6 run command.

EnvCLICode / Config fileDefault
K6_NO_THRESHOLDS--no-thresholdsN/Afalse
$ k6 run --no-thresholds ~/script.js

No Usage Report

A boolean, true or false. By default, k6 sends a usage report each time it is run, so that we can track how often people use it. If this option is set to true, no usage report will be made. To learn more, have a look at the Usage reports documentation. Available in k6 run commands.

EnvCLICode / Config fileDefault
K6_NO_USAGE_REPORT--no-usage-reportnoUsageReportfalse
export let options = {
  noUsageReport: true,
};

No VU Connection Reuse

A boolean, true or false, specifying whether k6 should reuse TCP connections between iterations of a VU. Available in k6 run and k6 cloud commands.

EnvCLICode / Config fileDefault
K6_NO_VU_CONNECTION_REUSE--no-vu-connection-reusenoVUConnectionReusefalse
export let options = {
  noVUConnectionReuse: true,
};

Paused

A boolean, true or false, specifying whether the test should start in a paused state. To resume a paused state you'd use the k6 resume command. Available in k6 run and k6 cloud commands.

EnvCLICode / Config fileDefault
K6_PAUSED--paused, -ppausedfalse
export let options = {
  paused: true,
};

Results Output

Specify the results output. Please go to Results ouput for more information on all output plugins available and how to configure them. Since version 0.21, this option can be specified multiple times. Available in k6 run command.

EnvCLICode / Config fileDefault
N/A--out, -oN/Anull
$ k6 run --out influxdb=http://localhost:8086/k6 script.js

RPS

The maximum number of requests to make per second, in total across all VUs. Available in k6 run and k6 cloud commands.

EnvCLICode / Config fileDefault
K6_RPS--rpsrps0 (unlimited)
export let options = {
  rps: 500,
};

Cloud runs

There are a couple of considerations with this option when running cloud tests. The option is set per load generator which means that the value you set in the options object of your test script will be multiplied by the number of load generators your test run is using. At the moment we are hosting 300 VUs per load generator instance. In practice that means that if you set the option for 100 rps, and run a test with 1000 VUs, you will spin up 4 load gen instances and effective rps limit of your test run will be 400

Scenarios

Define one or more execution patterns, with various VU and iteration scheduling settings, running different exported functions (besides default!), using different environment variables, tags, and more.

See the Scenarios article for details and more examples.

Available in k6 run and k6 cloud commands.

EnvCLICode / Config fileDefault
N/AN/Ascenariosnull
export let options = {
  scenarios: {
    my_api_scenario: {
      // arbitrary scenario name
      executor: 'ramping-vus',
      startVUs: 0,
      stages: [
        { duration: '5s', target: 100 },
        { duration: '5s', target: 0 },
      ],
      gracefulRampDown: '10s',
      env: { MYVAR: 'example' },
      tags: { my_tag: 'example' },
    },
  },
};

Setup Timeout

Specify how long the setup() function is allow to run before it's terminated and the test fails.

EnvCLICode / Config fileDefault
K6_SETUP_TIMEOUTN/AsetupTimeout"10s"
export let options = {
  setupTimeout: '30s',
};

Skip TLS Verification

A boolean, true or false. When this option is enabled (set to true), all of the verifications that would otherwise be done to establish trust in a server provided TLS certificate will be ignored. Available in k6 run and k6 cloud commands

EnvCLICode / Config fileDefault
K6_INSECURE_SKIP_TLS_VERIFY--insecure-skip-tls-verifyinsecureSkipTLSVerifyfalse
export let options = {
  insecureSkipTLSVerify: true,
};

Stages

A list of VU { target: ..., duration: ... } objects that specify the target number of VUs to ramp up or down to for a specific period. Available in k6 run and k6 cloud commands,

EnvCLICode / Config fileDefault
K6_STAGES--stage <duration>:<target>, -s <duration>:<target>stagesBased on vus and duration.
// The following config would have k6 ramping up from 1 to 10 VUs for 3 minutes,
// then staying flat at 10 VUs for 5 minutes, then ramping up from 10 to 35 VUs
// over the next 10 minutes before finally ramping down to 0 VUs for another
// 3 minutes.

export let options = {
  stages: [
    { duration: '3m', target: 10 },
    { duration: '5m', target: 10 },
    { duration: '10m', target: 35 },
    { duration: '3m', target: 0 },
  ],
};
$ k6 run --stage 5s:10,5m:20,10s:5 ~/script.js

# or...

$ K6_STAGES="5s:10,5m:20,10s:5" k6 run ~/script.js

Summary export

New in v0.26.0

Output the end-of-test summary report to a JSON file that includes data for all test metrics, checks and thresholds. This is useful to get the aggregated test results in a machine-readable format, for integration with dashboards, external alerts, etc.

Available in the k6 run command.

EnvCLICode / Config fileDefault
K6_SUMMARY_EXPORT--summary-export <filename>N/Anull
$ k6 run --summary-export export.json ~/script.js

# or...

$ K6_SUMMARY_EXPORT="export.json" k6 run ~/script.js

See an example file on the Results Output page.

Supply Env Var

Add/override environment variable with VAR=value. Available in k6 run and k6 cloud commands.

EnvCLICode / Config fileDefault
N/A--env, -eN/Anull
$ k6 run -e FOO=bar ~/script.js

System Tags

Specify which System Tags will be in the collected metrics. Some collectors like the cloud one may require that certain system tags be used. You can specify the tags as an array from the JS scripts or as a comma-separated list via the CLI. Available in k6 run and k6 cloud commands

EnvCLICode / Config fileDefault
K6_SYSTEM_TAGS--system-tagssystemTagsproto, subproto, status, method, url, name, group, check, error, tls_version, scenario
export let options = {
  systemTags: ['status', 'method', 'url'],
};

Summary Trend Stats

Define stats for trend metrics (response times), one or more as avg,p(95),.... Available in k6 run command.

EnvCLICode / Config fileDefault
K6_SUMMARY_TREND_STATS--summary-trend-statssummaryTrendStatsnull
export let options = {
  summaryTrendStats: ['avg', 'p(95)'],
};

Tags

Specify tags that should be set test wide across all metrics. If a tag with the same name has been specified on a request, check or custom metrics it will have precedence over a test wide tag. Available in k6 run and k6 cloud commands.

EnvCLICode / Config fileDefault
N/A--tag NAME=VALUEtagsnull
export let options = {
  tags: {
    name: 'value',
  },
};

Teardown Timeout

Specify how long the teardown() function is allowed to run before it's terminated and the test fails.

EnvCLICode / Config fileDefault
K6_TEARDOWN_TIMEOUTN/AteardownTimeout"10s"
export let options = {
  teardownTimeout: '30s',
};

Thresholds

A collection of threshold specifications to configure under what condition(s) a test is considered successful or not, when it has passed or failed, based on metric data. To learn more, have a look at the Thresholds documentation. Available in k6 run commands.

EnvCLICode / Config fileDefault
N/AN/Athresholdsnull
export let options = {
  thresholds: {
    http_req_duration: ['avg<100', 'p(95)<200'],
    'http_req_connecting{cdnAsset:true}': ['p(95)<100'],
  },
};

Throw

A boolean, true or false, specifying whether to throw errors on failed HTTP requests or not. Available in k6 run and k6 cloud commands.

EnvCLICode / Config fileDefault
K6_THROW--throw, -wthrowfalse
export let options = {
  throw: true,
};

TLS Authentication

A list of TLS client certificate configuration objects. Each object needs to specify for which host(s)/domain(s) the given client certificate is valid for.

EnvCLICode / Config fileDefault
N/AN/AtlsAuthnull
export let options = {
  tlsAuth: [
    {
      domains: ['example.com'],
      cert: open('mycert.pem'),
      key: open('mycert-key.pem'),
    },
  ],
};

TLS Cipher Suites

A list of cipher suites allowed to be used by in SSL/TLS interactions with a server. For a full listing of available ciphers go here.

EnvCLICode / Config fileDefault
N/AN/AtlsCipherSuitesnull (Allow all suites)
export let options = {
  tlsCipherSuites: [
    'TLS_RSA_WITH_RC4_128_SHA',
    'TLS_RSA_WITH_AES_128_GCM_SHA256',
  ],
};

TLS Version

Either a string representing the only SSL/TLS version allowed to be used in interactions with a server, or an object specifying the "min" and "max" versions allowed to be used.

EnvCLICode / Config fileDefault
N/AN/AtlsVersionnull (Allow all versions)
export let options = {
  tlsVersion: 'tls1.2',
};

// or...

export let options = {
  tlsVersion: {
    min: 'ssl3.0',
    max: 'tls1.2',
  },
};

User Agent

A string specifying the user-agent string to use in User-Agent headers when sending HTTP requests. Available in k6 run and k6 cloud commands

EnvCLICode / Config fileDefault
K6_USER_AGENT--user-agentuserAgentk6/0.27.0 (https://k6.io/) (depending on the version you're using)`
export let options = {
  userAgent: 'MyK6UserAgentString/1.0',
};

VUs

A number specifying the number of VUs to run concurrently. If you'd like more control look at the stages option. Available in k6 run and k6 cloud commands.

EnvCLICode / Config fileDefault
K6_VUS--vus, -uvus1
export let options = {
  vus: 10,
};

VUs Max

A number specifying max number of virtual users, if more than vus. This option is typically used when the intent is to dynamically scale the amount of VUs up and down during the test using the k6 scale command. Since instantiating a VU is an expensive operation in k6 this option is used to preallocate vusMax number of VUs. Available in k6 run and k6 cloud commands.

EnvCLICode / Config fileDefault
K6_VUS_MAX--max, -mvusMax0 (unlimited)
export let options = {
  vusMax: 10,
};