{"id":457,"date":"2023-02-21T17:07:26","date_gmt":"2023-02-21T17:07:26","guid":{"rendered":"https:\/\/premsvmm.com\/?p=457"},"modified":"2023-02-21T17:32:34","modified_gmt":"2023-02-21T17:32:34","slug":"performance-testing-framework","status":"publish","type":"post","link":"https:\/\/premsvmm.com\/index.php\/2023\/02\/21\/performance-testing-framework\/","title":{"rendered":"Performance Testing Framework"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Introduction <\/h4>\n\n\n\n<p>This post will cover the creation of a performance testing framework using k6, as well as the steps involved in building and utilizing the framework.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">setup <\/h4>\n\n\n\n<ol>\n<li>Install k6 on your local machine by following the instructions provided in the documentation: <a href=\"https:\/\/k6.io\/docs\/get-started\/installation\/\">https:\/\/k6.io\/docs\/get-started\/installation\/<\/a><\/li>\n\n\n\n<li>If you have homebrew installed, you can use the following command to install k6:<\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;eclipse&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">brew install k6<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>By completing these steps, you will have k6 properly set up and ready to use.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Framework Architecture<\/h4>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"578\" src=\"https:\/\/premsvmm.com\/wp-content\/uploads\/2023\/02\/performance-testing-framework-1024x578.png\" alt=\"\" class=\"wp-image-467\" srcset=\"https:\/\/premsvmm.com\/wp-content\/uploads\/2023\/02\/performance-testing-framework-1024x578.png 1024w, https:\/\/premsvmm.com\/wp-content\/uploads\/2023\/02\/performance-testing-framework-300x169.png 300w, https:\/\/premsvmm.com\/wp-content\/uploads\/2023\/02\/performance-testing-framework-768x434.png 768w, https:\/\/premsvmm.com\/wp-content\/uploads\/2023\/02\/performance-testing-framework.png 1435w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Sample Perf Script<\/h4>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;duotone-light&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">import http from &quot;k6\/http&quot;;\nimport {check,fail,sleep} from &quot;k6&quot;;\n\nexport let options = {\n\tstages:[\n\t\t{&quot;duration&quot; : __ENV.STAGE_1_DUR, &quot;target&quot;: __ENV.STAGE_1_VUS},\n\t\t{&quot;duration&quot; : __ENV.STAGE_2_DUR, &quot;target&quot;: __ENV.STAGE_2_VUS},\n\t\t{&quot;duration&quot; : __ENV.STAGE_3_DUR, &quot;target&quot;: __ENV.STAGE_3_VUS},\n\t\t{&quot;duration&quot; : __ENV.STAGE_4_DUR, &quot;target&quot;: __ENV.STAGE_4_VUS},\n\t\t{&quot;duration&quot; : __ENV.STAGE_5_DUR, &quot;target&quot;: __ENV.STAGE_5_VUS}\n\t]\n}\n\nexport default function(){\n    loadGoogleWebsite();\n}\n\nfunction loadGoogleWebsite(){\n        let resp = http.get(&quot;https:\/\/www.google.com&quot;);\n        console.log(&quot;Response Status Code &quot;+resp.status);\n        check_and_fail(resp,200);\n    }\n\nfunction check_and_fail(response,expectedStatusCode){\n\tcheck(response,{&quot;status code 200&quot; : (res) =&gt; res.status === expectedStatusCode}) || fail(&quot;Expected &quot;+expectedStatusCode+&quot; status but obtained &quot;+response.status);\n}<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;eclipse&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">k6 run Google\/googlebrowse.js\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;eclipse&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">\n          \/\\      |\u203e\u203e| \/\u203e\u203e\/   \/\u203e\u203e\/\n     \/\\  \/  \\     |  |\/  \/   \/  \/\n    \/  \\\/    \\    |     (   \/   \u203e\u203e\\\n   \/          \\   |  |\\  \\ |  (\u203e)  |\n  \/ __________ \\  |__| \\__\\ \\_____\/ .io\n\nWARN[0000] `stages` was explicitly set to an empty value, running the script with 1 iteration in 1 VU\n  execution: local\n     script: Google\/googlebrowse.js\n     output: engine\n\n  scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):\n           * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)\n\nINFO[0000] Response Status Code 200                      source=console\n\n     \u2713 status code 200\n\n     checks.........................: 100.00% \u2713 1        \u2717 0\n     data_received..................: 23 kB   65 kB\/s\n     data_sent......................: 639 B   1.8 kB\/s\n     http_req_blocked...............: avg=258.29ms min=258.29ms med=258.29ms max=258.29ms p(90)=258.29ms p(95)=258.29ms\n     http_req_connecting............: avg=15.81ms  min=15.81ms  med=15.81ms  max=15.81ms  p(90)=15.81ms  p(95)=15.81ms\n     http_req_duration..............: avg=100.01ms min=100.01ms med=100.01ms max=100.01ms p(90)=100.01ms p(95)=100.01ms\n       { expected_response:true }...: avg=100.01ms min=100.01ms med=100.01ms max=100.01ms p(90)=100.01ms p(95)=100.01ms\n     http_req_failed................: 0.00%   \u2713 0        \u2717 1\n     http_req_receiving.............: avg=516\u00b5s    min=516\u00b5s    med=516\u00b5s    max=516\u00b5s    p(90)=516\u00b5s    p(95)=516\u00b5s\n     http_req_sending...............: avg=631\u00b5s    min=631\u00b5s    med=631\u00b5s    max=631\u00b5s    p(90)=631\u00b5s    p(95)=631\u00b5s\n     http_req_tls_handshaking.......: avg=212.52ms min=212.52ms med=212.52ms max=212.52ms p(90)=212.52ms p(95)=212.52ms\n     http_req_waiting...............: avg=98.86ms  min=98.86ms  med=98.86ms  max=98.86ms  p(90)=98.86ms  p(95)=98.86ms\n     http_reqs......................: 1       2.780852\/s\n     iteration_duration.............: avg=359.46ms min=359.46ms med=359.46ms max=359.46ms p(90)=359.46ms p(95)=359.46ms\n     iterations.....................: 1       2.780852\/s\n\n\nrunning (00m00.4s), 0\/1 VUs, 1 complete and 0 interrupted iterations\ndefault \u2713 [======================================] 1 VUs  00m00.4s\/10m0s  1\/1 iters, 1 per VU<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Sample Repo<\/h4>\n\n\n\n<p><a href=\"https:\/\/github.com\/premsvmm\/PerformanceTestingK6\">https:\/\/github.com\/premsvmm\/PerformanceTestingK6<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction This post will cover the creation of a performance testing framework using k6, as well as the steps involved in building and utilizing the framework. setup By completing these steps, you will have k6 properly set up and ready to use. Framework Architecture Sample Perf Script Sample Repo https:\/\/github.com\/premsvmm\/PerformanceTestingK6<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","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":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","footnotes":""},"categories":[5],"tags":[13],"_links":{"self":[{"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/posts\/457"}],"collection":[{"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/comments?post=457"}],"version-history":[{"count":9,"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/posts\/457\/revisions"}],"predecessor-version":[{"id":468,"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/posts\/457\/revisions\/468"}],"wp:attachment":[{"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/media?parent=457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/categories?post=457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/tags?post=457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}