<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Scenarios on Grafana Labs</title><link>https://grafana.com/docs/k6/v2.3.x/using-k6/scenarios/</link><description>Recent content in Scenarios on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/k6/v2.3.x/using-k6/scenarios/index.xml" rel="self" type="application/rss+xml"/><item><title>Concepts</title><link>https://grafana.com/docs/k6/v2.3.x/using-k6/scenarios/concepts/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/using-k6/scenarios/concepts/</guid><content><![CDATA[&lt;h1 id=&#34;concepts&#34;&gt;Concepts&lt;/h1&gt;
&lt;p&gt;These topics explain the essential concepts of how scenarios and their executors work.&lt;/p&gt;
&lt;p&gt;Different scenario configurations can affect many different aspects of your system,
including the generated load, utilized resources, and emitted metrics.
If you know a bit about how scenarios work, you&amp;rsquo;ll design better tests and interpret test results with more understanding.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;On this page&lt;/th&gt;
              &lt;th&gt;Read about&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/scenarios/concepts/open-vs-closed/&#34;&gt;Open and closed models&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Different ways k6 can schedule VUs, their affects on test results, and how k6 implements the open model in its arrival-rate executors&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/scenarios/concepts/graceful-stop/&#34;&gt;Graceful Stop&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A configurable period for iterations to finish or ramp down after the test reaches its scheduled duration&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/scenarios/concepts/arrival-rate-vu-allocation/&#34;&gt;Arrival-rate VU allocation&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;How k6 allocates VUs in arrival-rate executors&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/scenarios/concepts/dropped-iterations/&#34;&gt;Dropped iterations&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Possible reasons k6 might drop a scheduled iteration&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;]]></content><description>&lt;h1 id="concepts">Concepts&lt;/h1>
&lt;p>These topics explain the essential concepts of how scenarios and their executors work.&lt;/p>
&lt;p>Different scenario configurations can affect many different aspects of your system,
including the generated load, utilized resources, and emitted metrics.
If you know a bit about how scenarios work, you&amp;rsquo;ll design better tests and interpret test results with more understanding.&lt;/p></description></item><item><title>Executors</title><link>https://grafana.com/docs/k6/v2.3.x/using-k6/scenarios/executors/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/using-k6/scenarios/executors/</guid><content><![CDATA[&lt;h1 id=&#34;executors&#34;&gt;Executors&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;Executors&lt;/strong&gt; control how k6 schedules VUs and iterations.
The executor that you choose depends on the goals of your test and the type of traffic you want to model.&lt;/p&gt;
&lt;p&gt;Define the executor in &lt;code&gt;executor&lt;/code&gt; key of the scenario object.
The value is the executor name separated by hyphens.&lt;/p&gt;
&lt;!-- md-k6:skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;export const options = {
  scenarios: {
    arbitrary_scenario_name: {
      //Name of executor
      executor: &amp;#39;ramping-vus&amp;#39;,
      // more configuration here
    },
  },
};&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;all-executors&#34;&gt;All executors&lt;/h2&gt;
&lt;p&gt;The following table lists all k6 executors and links to their documentation.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Name&lt;/th&gt;
              &lt;th&gt;Value&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/scenarios/executors/shared-iterations/&#34;&gt;Shared iterations&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;shared-iterations&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;A fixed amount of iterations are&lt;br/&gt; shared between a number of VUs.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/scenarios/executors/per-vu-iterations/&#34;&gt;Per VU iterations&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;per-vu-iterations&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Each VU executes an exact number of iterations.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/scenarios/executors/constant-vus/&#34;&gt;Constant VUs&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;constant-vus&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;A fixed number of VUs execute as many&lt;br/&gt; iterations as possible for a specified amount of time.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/scenarios/executors/ramping-vus/&#34;&gt;Ramping VUs&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;ramping-vus&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;A variable number of VUs execute as many&lt;br/&gt; iterations as possible for a specified amount of time.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/scenarios/executors/constant-arrival-rate/&#34;&gt;Constant Arrival Rate&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;constant-arrival-rate&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;A fixed number of iterations are executed&lt;br/&gt; in a specified period of time.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/scenarios/executors/ramping-arrival-rate/&#34;&gt;Ramping Arrival Rate&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;ramping-arrival-rate&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;A variable number of iterations are &lt;br/&gt; executed in a specified period of time.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;

&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;For any given scenario, you can&amp;rsquo;t guarantee that a specific VU can run a specific iteration.&lt;/p&gt;
&lt;p&gt;With 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-data/sharedarray/&#34;&gt;&lt;code&gt;SharedArray&lt;/code&gt;&lt;/a&gt; and 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/execution-context-variables/&#34;&gt;execution context variables&lt;/a&gt;, you can map a specific VU to a specific value in your test data.
So the tenth VU could use the tenth item in your array (or the sixth iteration to the sixth item).&lt;/p&gt;
&lt;p&gt;But, you &lt;em&gt;cannot&lt;/em&gt; reliably map, for example, the tenth VU to the tenth iteration.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

]]></content><description>&lt;h1 id="executors">Executors&lt;/h1>
&lt;p>&lt;strong>Executors&lt;/strong> control how k6 schedules VUs and iterations.
The executor that you choose depends on the goals of your test and the type of traffic you want to model.&lt;/p></description></item><item><title>Advanced Examples</title><link>https://grafana.com/docs/k6/v2.3.x/using-k6/scenarios/advanced-examples/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/using-k6/scenarios/advanced-examples/</guid><content><![CDATA[&lt;h1 id=&#34;advanced-examples&#34;&gt;Advanced Examples&lt;/h1&gt;
&lt;p&gt;You can use multiple scenarios in one script, and these scenarios can be run in sequence or in parallel.
Some ways that you can combine scenarios include the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Have different start times to sequence workloads&lt;/li&gt;
&lt;li&gt;Add per-scenario tags and environment variables&lt;/li&gt;
&lt;li&gt;Make scenario-specific thresholds.&lt;/li&gt;
&lt;li&gt;Use multiple scenarios to run different test logic, so that VUs don&amp;rsquo;t run only the 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/test-lifecycle/&#34;&gt;&lt;code&gt;default&lt;/code&gt; function&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;combine-scenarios&#34;&gt;Combine scenarios&lt;/h2&gt;
&lt;p&gt;With the &lt;code&gt;startTime&lt;/code&gt; property, you can configure your script to start some scenarios later than others.
To sequence your scenarios, you can combine &lt;code&gt;startTime&lt;/code&gt; with the duration options specific to the executor.
(this is easiest to do with executors with set durations, like the arrival-rate executors).&lt;/p&gt;
&lt;p&gt;This script has two scenarios, &lt;code&gt;contacts&lt;/code&gt; and &lt;code&gt;news&lt;/code&gt;, which run in sequence:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;At the beginning of the test, k6 starts the &lt;code&gt;contacts&lt;/code&gt; scenario. 5 VUs try to run as many iterations as possible for 5 seconds.&lt;/li&gt;
&lt;li&gt;After 10 seconds, k6 starts the &lt;code&gt;news&lt;/code&gt; scenario. 5 VUs each try to run 10 iterations in 20 seconds.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Along with &lt;code&gt;startTime&lt;/code&gt;, &lt;code&gt;duration&lt;/code&gt;, and &lt;code&gt;maxDuration&lt;/code&gt;, note the different test logic for each scenario.&lt;/p&gt;
&lt;!-- md-k6:fixedscenarios --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import http from &amp;#39;k6/http&amp;#39;;

export const options = {
  discardResponseBodies: true,
  scenarios: {
    contacts: {
      executor: &amp;#39;constant-vus&amp;#39;,
      exec: &amp;#39;contacts&amp;#39;,
      vus: 5,
      duration: &amp;#39;5s&amp;#39;,
    },
    news: {
      executor: &amp;#39;per-vu-iterations&amp;#39;,
      exec: &amp;#39;news&amp;#39;,
      vus: 5,
      iterations: 10,
      startTime: &amp;#39;10s&amp;#39;,
      maxDuration: &amp;#39;20s&amp;#39;,
    },
  },
};

export function contacts() {
  http.get(&amp;#39;https://test.k6.io/contacts.php&amp;#39;, {
    tags: { my_custom_tag: &amp;#39;contacts&amp;#39; },
  });
}

export function news() {
  http.get(&amp;#39;https://test.k6.io/news.php&amp;#39;, { tags: { my_custom_tag: &amp;#39;news&amp;#39; } });
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;use-different-environment-variables-and-tags-per-scenario&#34;&gt;Use different environment variables and tags per scenario.&lt;/h2&gt;
&lt;p&gt;The previous example sets tags on individual HTTP request metrics.
But, you can also set tags per scenario, which applies them to other

    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/tags-and-groups/#tags&#34;&gt;taggable&lt;/a&gt; objects as well.&lt;/p&gt;
&lt;!-- md-k6:skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import http from &amp;#39;k6/http&amp;#39;;
import { fail } from &amp;#39;k6&amp;#39;;

export const options = {
  discardResponseBodies: true,
  scenarios: {
    contacts: {
      executor: &amp;#39;constant-vus&amp;#39;,
      exec: &amp;#39;contacts&amp;#39;,
      vus: 50,
      duration: &amp;#39;30s&amp;#39;,
      tags: { my_custom_tag: &amp;#39;contacts&amp;#39; },
      env: { MYVAR: &amp;#39;contacts&amp;#39; },
    },
    news: {
      executor: &amp;#39;per-vu-iterations&amp;#39;,
      exec: &amp;#39;news&amp;#39;,
      vus: 50,
      iterations: 100,
      startTime: &amp;#39;30s&amp;#39;,
      maxDuration: &amp;#39;1m&amp;#39;,
      tags: { my_custom_tag: &amp;#39;news&amp;#39; },
      env: { MYVAR: &amp;#39;news&amp;#39; },
    },
  },
};

export function contacts() {
  if (__ENV.MYVAR != &amp;#39;contacts&amp;#39;) fail();
  http.get(&amp;#39;https://test.k6.io/contacts.php&amp;#39;);
}

export function news() {
  if (__ENV.MYVAR != &amp;#39;news&amp;#39;) fail();
  http.get(&amp;#39;https://test.k6.io/news.php&amp;#39;);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;By default, k6 applies a &lt;code&gt;scenario&lt;/code&gt; tag to all metrics in each scenario, whose value is the scenario name.
You can combine these tags with thresholds, or use them to simplify results filtering.&lt;/p&gt;
&lt;p&gt;To disable scenario tags, use the 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/k6-options/#system-tags&#34;&gt;&lt;code&gt;--system-tags&lt;/code&gt; option&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h2 id=&#34;run-multiple-scenario-functions-with-different-thresholds&#34;&gt;Run multiple scenario functions, with different thresholds&lt;/h2&gt;
&lt;p&gt;You can also set different thresholds for different scenario functions.
To do this:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Set scenario-specific tags&lt;/li&gt;
&lt;li&gt;Set thresholds for these tags.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This test has 3 scenarios, each with different &lt;code&gt;exec&lt;/code&gt; functions, tags and environment variables, and thresholds:&lt;/p&gt;
&lt;!-- md-k6:skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import http from &amp;#39;k6/http&amp;#39;;
import { sleep } from &amp;#39;k6&amp;#39;;

export const options = {
  scenarios: {
    my_web_test: {
      // some arbitrary scenario name
      executor: &amp;#39;constant-vus&amp;#39;,
      vus: 50,
      duration: &amp;#39;5m&amp;#39;,
      gracefulStop: &amp;#39;0s&amp;#39;, // do not wait for iterations to finish in the end
      tags: { test_type: &amp;#39;website&amp;#39; }, // extra tags for the metrics generated by this scenario
      exec: &amp;#39;webtest&amp;#39;, // the function this scenario will execute
    },
    my_api_test_1: {
      executor: &amp;#39;constant-arrival-rate&amp;#39;,
      rate: 90,
      timeUnit: &amp;#39;1m&amp;#39;, // 90 iterations per minute, i.e. 1.5 RPS
      duration: &amp;#39;5m&amp;#39;,
      preAllocatedVUs: 10, // the size of the VU (i.e. worker) pool for this scenario
      tags: { test_type: &amp;#39;api&amp;#39; }, // different extra metric tags for this scenario
      env: { MY_CROC_ID: &amp;#39;1&amp;#39; }, // and we can specify extra environment variables as well!
      exec: &amp;#39;apitest&amp;#39;, // this scenario is executing different code than the one above!
    },
    my_api_test_2: {
      executor: &amp;#39;ramping-arrival-rate&amp;#39;,
      startTime: &amp;#39;30s&amp;#39;, // the ramping API test starts a little later
      startRate: 50,
      timeUnit: &amp;#39;1s&amp;#39;, // we start at 50 iterations per second
      stages: [
        { target: 200, duration: &amp;#39;30s&amp;#39; }, // go from 50 to 200 iters/s in the first 30 seconds
        { target: 200, duration: &amp;#39;3m30s&amp;#39; }, // hold at 200 iters/s for 3.5 minutes
        { target: 0, duration: &amp;#39;30s&amp;#39; }, // ramp down back to 0 iters/s over the last 30 second
      ],
      preAllocatedVUs: 50, // how large the initial pool of VUs would be
      maxVUs: 100, // if the preAllocatedVUs are not enough, we can initialize more
      tags: { test_type: &amp;#39;api&amp;#39; }, // different extra metric tags for this scenario
      env: { MY_CROC_ID: &amp;#39;2&amp;#39; }, // same function, different environment variables
      exec: &amp;#39;apitest&amp;#39;, // same function as the scenario above, but with different env vars
    },
  },
  discardResponseBodies: true,
  thresholds: {
    // we can set different thresholds for the different scenarios because
    // of the extra metric tags we set!
    &amp;#39;http_req_duration{test_type:api}&amp;#39;: [&amp;#39;p(95)&amp;lt;250&amp;#39;, &amp;#39;p(99)&amp;lt;350&amp;#39;],
    &amp;#39;http_req_duration{test_type:website}&amp;#39;: [&amp;#39;p(99)&amp;lt;500&amp;#39;],
    // we can reference the scenario names as well
    &amp;#39;http_req_duration{scenario:my_api_test_2}&amp;#39;: [&amp;#39;p(99)&amp;lt;300&amp;#39;],
  },
};

export function webtest() {
  http.get(&amp;#39;https://test.k6.io/contacts.php&amp;#39;);
  sleep(Math.random() * 2);
}

export function apitest() {
  http.get(`https://quickpizza.grafana.com/api/json?crocId=${__ENV.MY_CROC_ID}`);
  // no need for sleep() here, the iteration pacing will be controlled by the
  // arrival-rate executors above!
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;run-a-specific-scenario&#34;&gt;Run a specific scenario&lt;/h2&gt;
&lt;p&gt;k6 runs all configured scenarios by default. Use 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/scenarios/#run-selected-scenarios&#34;&gt;&lt;code&gt;--scenario&lt;/code&gt;&lt;/a&gt; to select which scenarios run without changing the script.&lt;/p&gt;
&lt;p&gt;The following script defines two scenarios:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import http from &amp;#39;k6/http&amp;#39;;

const scenarios = {
  my_web_test: {
    executor: &amp;#39;per-vu-iterations&amp;#39;,
    vus: 1,
    iterations: 1,
    maxDuration: &amp;#39;30s&amp;#39;,
  },
  my_api_test: {
    executor: &amp;#39;per-vu-iterations&amp;#39;,
    vus: 1,
    iterations: 1,
    maxDuration: &amp;#39;30s&amp;#39;,
  },
};

export const options = {
  scenarios,
  discardResponseBodies: true,
  thresholds: {
    http_req_duration: [&amp;#39;p(95)&amp;lt;250&amp;#39;, &amp;#39;p(99)&amp;lt;350&amp;#39;],
  },
};

export default function () {
  const response = http.get(&amp;#39;https://quickpizza.grafana.com&amp;#39;);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Run only &lt;code&gt;my_web_test&lt;/code&gt; with its configured workload:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;k6 run --scenario my_web_test script.js&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To select both scenarios, pass their names separated by a comma:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;k6 run --scenario my_web_test,my_api_test script.js&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="advanced-examples">Advanced Examples&lt;/h1>
&lt;p>You can use multiple scenarios in one script, and these scenarios can be run in sequence or in parallel.
Some ways that you can combine scenarios include the following:&lt;/p></description></item></channel></rss>