æè¿ãä»äºã§k6ã«è§¦ããæ©ä¼ãããã¾ãããApache JMeterãLocustã¯è§¦ã£ããã¨ããã£ãã®ã§ãããk6ã¯åãã¦ã ã£ãã®ã§ãåå¿é²çã«è¨äºãæ®ãã¦ããã¾ãã
k6
k6ã¯Grafana Labsãéçºãã¦ããè² è·ãã¹ããã¼ã«ã§ããJavascriptã§æ¸ãããã·ããªãªããk6ãã³ãã³ãã§å®è¡ãã¾ããSaaSãæä¾ããã¦ããã®ã§ããã·ã³ã«ç©ºããªã½ã¼ã¹ããªãå ´åã¯SaaSãå©ç¨ããã®ãããããããã¾ãããk6-operatorã¨ããã®ã使ãã°K8sã§å®è¡ã§ãããããªã®ã§ãAWS EKSãGoogle Cloud GKEãªã©ã§åããã®ããããããããªãã§ããã
使ã£ã¦ã¿ã
ãªã«ã¯ã¨ãããã¤ã³ã¹ãã¼ã«ãã¦ã¿ã¾ããããã¨ãã£ã¦ããLinux/macOS/Windowsã§ããã±ã¼ã¸ãç¨æããã¦ãã¾ããã¤ã³ã¹ãã¼ã«ããã¥ã¡ã³ããåèã«ã¤ã³ã¹ãã¼ã«ãã¦ãã ããã
ï¼arm64ã®Debããã±ã¼ã¸ã¯é å¸ããã¦ããªãããã§ãã
publish arm64 builds in linux repos · Issue #2136 · grafana/k6 · GitHub
GitHub Releasesã«ã¯linux-arm64ã®ãã¤ããªãã¢ããããã¦ããã®ã§ããã¡ããããã¦ã³ãã¼ããã¦PATHã®éã£ããã£ã¬ã¯ããªã«é ç½®ããã¨ããã§ãããã
ã¤ã³ã¹ãã¼ã«ãå®äºããããk6ãã³ãã³ããå®è¡ãã¦ã¿ã¾ãã
Usageã表示ãããã°æåã§ãã
ã·ããªãªãä½ã
1ããã·ããªãªãä½æãã¦ãããã®ã§ãããk6ã«ã¯ã·ããªãªã®éå½¢ãä½ããnewããµãã³ãã³ããç¨æããã¦ãã¾ããå®è¡ãã¦ã¿ã¾ãã
$ k6 new Initialized a new k6 test script in script.js. You can now execute it by running `k6 run script.js`.
newã³ãã³ããå®è¡ããã¨script.jsã¨ãããã¡ã¤ã«ãä½æããã¾ãããä¸èº«ã¯ã»ã¨ãã©ã³ã¡ã³ãã¢ã¦ãããã¦ãã¾ãã
newã³ãã³ãã®çµæã«åºåããã¦ããéããrunã³ãã³ããå®è¡ãã¦ã¿ã¾ãã
$ k6 run script.js
ãªãã ãè²ã 表示ããã¾ããã
ã³ã¡ã³ãã¢ã¦ãããã¦ããé¨åãé¤å¤ãã¦script.jsã®ä¸èº«ãè¦ã¦ã¿ãã¨ä¸è¨ã®ããã«ãªã£ã¦ãã¾ããã
import http from 'k6/http'; import { sleep } from 'k6'; export const options = { vus: 10, duration: '30s', }; export default function() { http.get('https://test.k6.io'); sleep(1); }
ãã®ãã¡ã¤ã«ã®ä¸èº«ã軽ã説æãã¦ããã¨ã»ã»ã»
export const options
ã¯k6ã«è¨å®ãããªãã·ã§ã³ã§ããvus
ã¯virtual users
ã§ä½VUsåæå®è¡ãããã¨ããè¨å®ã§ããdurationã¯ã©ããããã®æéè² è·ãããããã¨ããè¨å®ã§ãä»åã®å ´åã¯30ç§ã§ããoptionsã«è¨å®ã§ããå¤ã¯ãã¡ãã«æ¸ããã¦ãã¾ãã
export default function() {}
ã¯ã·ããªãªã®ä¸èº«ã§ããã¸ã§ãã¬ã¼ããããã·ããªãªã§ã¯ãtest.k6.ioãã«GETãªã¯ã¨ã¹ããæãã¦1ç§éã¹ãªã¼ãããå¦çã«ãªã£ã¦ãã¾ãããããvusã¨durationã§è¨å®ãããæ°ã ãå®è¡ããã¾ãã
ãã以å¤ã«ãexport function setup() {}
ãexport function teardown(data) {}
ãªã©ãè¨è¿°ã§ããããã§ãããããã®è©³ç´°ãªèª¬æã¯ãã¡ãã«è¨è¼ããã¦ãã¾ãã
ã¸ã§ãã¬ã¼ããããscript.jsãæ¹é ãã¦ãå°ãæ¹é ãã¦ã¿ã¾ãã
ã¾ãã¯optionsã«stagesã追å ãã¾ãã
stagesã®èª¬æã¯ãã¡ãã«ããã¾ãã
ç°¡åã«èª¬æããã¨ã©ã³ãã¢ããã®æ©è½ã§ããã©ã³ãã¢ããã¨ã¯ããæéãããã¦å¾ã ã«è² è·ãããã¦ããæ¹æ³ã§ããvus: 10, duration: 30sã®è¨å®ã§ã¯ååãã10VUsã§è² è·ããããã¾ãããstagesãè¨å®ãããã¨ã§ãå¾ã ã«è² è·ãå¢å¤§ããã¦ãããã¨ãã§ãã¾ããããã®ä½ãå¬ãããã¨ããã¨ãä¾ãã°ããä¸å®ã®è² è·ãé·æéãããå ´åã«ããããªãå¼·ãã®è² è·ãããã¦ãã¾ãã¨LBããªã¼ãã¹ã±ã¼ã«ãéã«åãããååã«500ç³»ã®ã¨ã©ã¼ãè¿ãã¦ãã¾ãå¯è½æ§ãããã¾ããããã§ã¯æ£ããæ§è½ã測ããªããããå¾ã ã«è² è·ãããã¦ãã£ã¦ãç®æ¨ã®ã¹ã«ã¼ãããã«éããã¨ããã§é·ãç¶æããããã«ãã¾ãããããããã¨ã§ãã¹ã±ã¼ã«ãéã«åããªãç³»ã®ã¨ã©ã¼ãåºããã«ãã¹ããéè¡ã§ãã¾ãã
stagesã®è¨å®æ¹æ³ã¯ä¸è¨ã§ãã
export const options = { stages: [ { duration: '3m', target: 10 }, { duration: '5m', target: 10 }, { duration: '10m', target: 35 }, { duration: '3m', target: 0 }, ] };
ãã®è¨å®ã§ã¯ãæåã®3åéãããã¦1VUsãã10VUsã«ã©ã³ãã¢ãããã次ã®5åéã10VUsãç¶æãã次ã®10åéã§10VUsãã35VUsã«ã©ã³ãã¢ãããã¾ããæå¾ã®3åéã§35VUsãã0VUsã«ã©ã³ããã¦ã³ãã¾ãã
次ã«ãªã¯ã¨ã¹ãå ãlocalhostã®nginxã«ãã¦ã¿ã¾ãã
ã¾ãã¯nginxãèµ·åãã¾ããããä¸è¨ã®æååãdummy.json
ãã¡ã¤ã«ã«ä¿åãã¦ãDocker(or Podman)ã§å®è¡ãã¾ãã
[ { "id": 1, "first_name": "Taro", "last_name": "Tanaka" }, { "id": 2, "first_name": "Satoru", "last_name": "Sato" } ]
$ docker run --rm -it -p 8080:80 -v $PWD/dummy.json:/usr/share/nginx/html/dummy.json:ro nginx
Podmanãªæ¹ã¯ãã¡ã
$ podman run --rm -it -p 8080:80 -v $PWD/dummy.json:/usr/share/nginx/html/dummy.json:ro docker.io/library/nginx
ããã§ãã¼ã«ã«ã®ãµã¼ãã¼ã«ãªã¯ã¨ã¹ããæããããããã«ãªã£ãã®ã§ã·ããªãªãä¿®æ£ãã¾ãã
export default function() { http.get('http://localhost:8080/dummy.json'); sleep(1); }
ããã§ã¯å®è¡ãã¦ã¿ã¾ãããã
$ k6 run script.js
ãã®ç»åã§ã¯ç»é¢ãæ°´å¹³ã«äºåå²ããã¦ãã¦ãä¸ãk6ã®å®è¡ãä¸ãnginxã®ãã°ã§ããnginxã®ãã°ãæµãã¦ããã°ãã¼ã«ã«ã®ãµã¼ãã¼ã«ãªã¯ã¨ã¹ããæãããã¦ãã¾ãã
k6ã®åºåãã¿ã¦ããã¨å¾ã ã«VUsãå¢ãã¦ããã®ããããã¨æãã¾ããstagesãã¡ããã¨æ©è½ãã¦ãããã§ãã
ããã¾ã§ã§ã²ã¨ã¾ãã·ããªãªä½æã¯çµäºã¨ãã¾ãããã¨ã¯å®éã«è² è·ããããAPIã®ä½¿ç¨ãªã©ã¨ç¸è«ãã¤ã¤ãå ¬å¼ããã¥ã¡ã³ããè¦ãã°ãããããã¨ãå®ç¾ã§ããã§ãããã
k6ã®ã¬ãã¼ã
ã·ããªãªã®å®è¡ãå®äºãããã¬ãã¼ããåºåããã¾ããããããã®æå³ã«ã¤ãã¦ã¯ãã¡ãã«è¨è¼ããã¦ãã¾ãã
ãã£ã¨ä¸éã説æããã¨ä¸è¨ã®éãã§ãã
- data_receivedï¼åä¿¡ãã¼ã¿é
- data_sentï¼éä¿¡ãã¼ã¿é
- http_req_blockedï¼ãªã¯ã¨ã¹ããéå§ããåã«ãããã¯ãããæé
- http_req_connectingï¼ãªã¢ã¼ã ãã¹ãã¸ã® TCP æ¥ç¶ã確ç«ããã®ã«ããã£ãæé
- http_req_durationï¼ãªã¯ã¨ã¹ãã®åè¨æéï¼http_req_sending + http_req_waiting + http_req_receivingï¼
- expected_responseï¼HTTPã¹ãã¼ã¿ã¹ã³ã¼ãã200~399ã®ãªã¯ã¨ã¹ãã®ã¿ã®åè¨æé
- http_req_failedï¼å¤±æãããªã¯ã¨ã¹ãã®å²å
- http_req_receivingï¼ãªã¢ã¼ã ãã¹ãããã®å¿çãã¼ã¿ãåä¿¡ããã®ã«è²»ããããæé
- http_req_sendingï¼ãªã¢ã¼ã ãã¹ãã¸ãã¼ã¿éä¿¡ã«è²»ããããæé
- http_req_tls_handshakingï¼ãªã¢ã¼ããã¹ãã¨ã® TLS ã»ãã·ã§ã³ã®ãã³ãã·ã§ã¤ã¯ã«è²»ããããæé
- http_req_waitingï¼ãªã¢ã¼ã ãã¹ãããã®å¿çãå¾ ã¤ã®ã«è²»ããããæé
- http_reqsï¼k6 ãçæãã HTTP ãªã¯ã¨ã¹ãã®åè¨æ°
- iteration_durationï¼ï¼ã¤ãã¬ã¼ã·ã§ã³ã«ããã£ãå ¨ã¦ã®æé
- iterationsï¼ï¼VUãå®è¡ããã¤ãã¬ã¼ã·ã§ã³ã®æ°
- vusï¼ç¾å¨ã®ã¢ã¯ãã£ããªä»®æ³ã¦ã¼ã¶ã¼æ°
- vus_maxï¼ä»®æ³ã¦ã¼ã¶ã¼ã®æ大æ°
ã¾ãã¯http_req_durationãhttp_req_failedãè¦ã¦APIãé ããªãããã¨ã©ã¼ãåºã¦ããªããææ¡ããã®ãããã§ãããã
k6ã®ã¬ãã¼ãã¯æ¨æºåºåã«åºã¦ãããã®ã®ä»ã«ãå¤é¨ã®ãµã¼ãã¹ã«åºåã§ãã¾ãã
ä»åã¯ç°¡åã«ã»ããã¢ããã§ããNetdataã«åºåãã¦ã¿ããã¨æãã¾ãã
Netdataã®ã¤ã³ã¹ãã¼ã«ã«ã¤ãã¦ã¯ãã¡ããåèã«é²ãã¦ãã ããã
Podmanãªæ¹ã¯ãã¡ããå®è¡ããã¨Netdataã®ã³ã³ãããèµ·åãã¾ãã
$ podman run -d --name=netdata --pid=host --network=host -v netdataconfig:/etc/netdata -v netdatalib:/var/lib/netdata -v netdatacache:/var/cache/netdata -v /:/host/root:ro,rslave -v /etc/passwd:/host/etc/passwd:ro -v /etc/group:/host/etc/group:ro -v /etc/localtime:/etc/localtime:ro -v /proc:/host/proc:ro -v /sys:/host/sys:ro -v /etc/os-release:/host/etc/os-release:ro -v /var/log:/host/var/log:ro --restart unless-stopped --cap-add SYS_PTRACE --cap-add SYS_ADMIN --security-opt apparmor=unconfined docker.io/netdata/netdata
å®è¡æã«ã¨ã©ã¼ãåºãªããã°ãhttp://localhost:19999ãã«ã¢ã¯ã»ã¹ãããã¨ã§ä»¥ä¸ã®ç»é¢ã表示ãããã¨æãã¾ãã
å³ä¸ã®ãSkip and use the dashboard anonymously.ããã¯ãªãã¯ããã¨ã¡ããªã¯ã¹ã表示ããã¾ãã
次ã«k6ãNetdataï¼ã¨ãããStatsDï¼ã«åºåããããã®è¨å®ããã¦ããã¾ãã
StatsDã«åºåããã«ã¯xk6-output-statsdãã©ã°ã¤ã³ãã¤ã³ã¹ãã¼ã«ããå¿ è¦ãããã¾ãã
k6ã«ãã©ã°ã¤ã³ãã¤ã³ã¹ãã¼ã«ããã«ã¯xk6ãã¤ã³ã¹ãã¼ã«ããå¿ è¦ãããã¾ããï¼ããããããªã£ã¦ããã»ã»ã»ï¼
ã¾ãã¯xk6ãã¤ã³ã¹ãã¼ã«ãã¾ãããã
xk6ãã¤ã³ã¹ãã¼ã«ããã«ã¯Goã§ãã«ãããã®ãæãç°¡åã§ãããã¾ãã¯Goãã¤ã³ã¹ãã¼ã«ãã¾ãããã
Download and install - The Go Programming Language
Goã®ã¤ã³ã¹ãã¼ã«ãå®äºãããxk6ãã¤ã³ã¹ãã¼ã«ãã¾ãã
$ go install go.k6.io/xk6/cmd/xk6@latest
ç¹ã«Goã®è¨å®ããã¦ããªããã°~/go/bin
ã«ã¤ã³ã¹ãã¼ã«ããã¾ãã
次ã«ãã©ã°ã¤ã³ãã¤ã³ã¹ãã¼ã«ãã¾ãã
$ ~/go/bin/xk6 build --with github.com/LeonAdato/xk6-output-statsd
ãã®ã³ãã³ããå®è¡ãããã£ã¬ã¯ããªã«k6ã®ãã¤ããªãåºåããã¦ããã¨æãã®ã§ããã®ãã¤ããªã使ç¨ãã¦ã·ããªãªãå®è¡ãã¾ãã
$ ./k6 --out output-statsd script.js
ãã¾ãå®è¡ã§ããã°Netdataã®ç»é¢ã«k6é¢é£ã®ã¡ããªã¯ã¹ãçãã¦ããã¨æãã¾ãã
k6ã®ã¬ãã¼ãããªã¢ã«ã¿ã¤ã ã§åæ ãããã®ã§ã¿ãããã®ã§ã¯ãªãã§ããããã
ã¾ã¨ã
k6èªä½ã®ä½¿ãæ¹ãç°¡åã§å ¥éããããã¨æãã¾ãããããã¥ã¡ã³ããäºç´°ãã«æ¸ãã¦ããã®ã§ãã¾ãè¿·ããã¨ãããã¾ããã
ã¬ãã¼ããå¤é¨ã«åºåã§ããã®ã§ãçµæãæºãè¾¼ãã§å¾ãã確èªãªã©ãã§ãããã§ãã誰ãã¨å ±æããæããããããããªãã§ããã