{"id":10226,"date":"2026-05-22T18:43:03","date_gmt":"2026-05-22T13:13:03","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=10226"},"modified":"2026-05-22T18:45:09","modified_gmt":"2026-05-22T13:15:09","slug":"k6-load-testing-tool-installation-and-sample-test-scripts","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/k6-load-testing-tool-installation-and-sample-test-scripts\/","title":{"rendered":"K6 Load Testing Tool \u2013 Installation and Sample Test Scripts"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">K6 is an open-source load testing tool used to test the performance and stability of APIs, websites, and applications.<br>It is lightweight, developer-friendly, and uses JavaScript for writing test scripts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">K6 helps to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Test API performance<\/li>\n\n\n\n<li>Simulate multiple users<\/li>\n\n\n\n<li>Identify bottlenecks<\/li>\n\n\n\n<li>Measure response times<\/li>\n\n\n\n<li>Validate application scalability<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\">Prerequisites<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Before installing K6, ensure the following requirements are available:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Linux \/ Windows \/ macOS server<\/li>\n\n\n\n<li>Internet connection<\/li>\n\n\n\n<li>Basic terminal knowledge<\/li>\n\n\n\n<li>Access to the application or API<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Example test target:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">https:\/\/example.com<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">I. K6 Installation<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">(i) Install K6 on Ubuntu \/ Debian<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt update\n\nsudo apt install -y gnupg software-properties-common\n\ncurl -fsSL https:\/\/dl.k6.io\/key.gpg | sudo gpg --dearmor -o \/usr\/share\/keyrings\/k6-archive-keyring.gpg\n\necho \"deb [signed-by=\/usr\/share\/keyrings\/k6-archive-keyring.gpg] https:\/\/dl.k6.io\/deb stable main\" | sudo tee \/etc\/apt\/sources.list.d\/k6.list\n\nsudo apt update\n\nsudo apt install k6 -y<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">(ii) Verify Installation<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">k6 version<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Example output:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">k6 v0.48.0<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">II. Basic K6 Test Script<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create a file:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">test.js<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add the following script:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import http from 'k6\/http';\nimport { sleep } from 'k6';\n\nexport default function () {\n\n    http.get('https:\/\/example.com');\n\n    sleep(1);\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">III. Run the Test<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">k6 run test.js<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">IV. API Load Test Example<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import http from 'k6\/http';\nimport { check, sleep } from 'k6';\n\nexport const options = {\n    vus: 10,\n    duration: '30s',\n};\n\nexport default function () {\n\n    let response = http.get('https:\/\/example.com\/api\/users');\n\n    check(response, {\n        'status is 200': (r) =&gt; r.status === 200,\n    });\n\n    sleep(1);\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">V. POST Request Example<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import http from 'k6\/http';\n\nexport default function () {\n\n    const payload = JSON.stringify({\n        username: 'testuser',\n        password: 'password123'\n    });\n\n    const params = {\n        headers: {\n            'Content-Type': 'application\/json',\n        },\n    };\n\n    http.post('https:\/\/example.com\/api\/login', payload, params);\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">VI. Stress Test Example<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import http from 'k6\/http';\n\nexport const options = {\n    stages: [\n        { duration: '30s', target: 20 },\n        { duration: '1m', target: 100 },\n        { duration: '30s', target: 0 },\n    ],\n};\n\nexport default function () {\n\n    http.get('https:\/\/example.com');\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">VII. Save Test Results<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">k6 run test.js --out json=result.json<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">VIII. Generate HTML Report<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">k6 run test.js --summary-export=summary.json<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Notes<\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Metric<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>http_req_duration<\/td><td>API response time<\/td><\/tr><tr><td>http_req_failed<\/td><td>Failed requests<\/td><\/tr><tr><td>vus<\/td><td>Virtual users<\/td><\/tr><tr><td>iterations<\/td><td>Total requests executed<\/td><\/tr><tr><td>checks<\/td><td>Validation results<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">IX. Advantages of K6<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Easy JavaScript scripting<\/li>\n\n\n\n<li>Lightweight and fast<\/li>\n\n\n\n<li>Supports API and website testing<\/li>\n\n\n\n<li>Good CLI output<\/li>\n\n\n\n<li>Supports CI\/CD integration<\/li>\n\n\n\n<li>Open-source<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">K6 is a simple and powerful load testing tool for testing APIs and web applications.<br>It allows teams to simulate user traffic, monitor application performance, and identify issues before production deployment.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction K6 is an open-source load testing tool used to test the performance and stability of APIs, websites, and applications.It [&hellip;]<\/p>\n","protected":false},"author":495,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[1014],"class_list":["post-10226","post","type-post","status-publish","format-standard","hentry","category-web-architecture","tag-load-test","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-2EW","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/10226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/495"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=10226"}],"version-history":[{"count":1,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/10226\/revisions"}],"predecessor-version":[{"id":10227,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/10226\/revisions\/10227"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=10226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=10226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=10226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}