k6 with openSUSE Leap 15.5 小記
之前公司壓測用的是 JMeter, 最近想在 K8 上面玩一些 side project
看了些資料, 最後還是選擇 k6
官網
我是先看到黑暗執行緒的文章
同步參考 工程良田的小球場 文章
開始進行相關練習
k6 的安裝文件頁
一如往常的, 上面只有 Debian / Ubuntu / Fedora / CentOS / MacOS / Windows / Docker
沒有 openSUSE Leap :p
這個部份想法上就是朝兩個方向
docker
snaps
這個部份我用 snaps 來解
參考 https://snapcraft.io/install/k6/opensuse
因為我的 snapd 已經啟動了, 所以直接安裝就可以
snapd 安裝與啟動可以直接看剛剛那個頁面
# snap install k6
k6 v0.48.0 from Thomas Bille (tbmb) installed
確認版本
> k6 version
k6 v0.48.0 (commit/47c0a26798, go1.21.4, linux/amd64)
建立測試檔案
> k6 new
Initialized a new k6 test script in script.js. You can now execute it by running `k6 run script.js`.
觀察 script.js
> cat script.js | egrep -v '^//| //|^$'
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);
}
vus: 10 為 10 個虛擬使用者
duration: '30s' 為執行 30 秒
執行第一次測試
> k6 run script.js
/\ |‾‾| /‾‾/ /‾‾/
/\ / \ | |/ / / /
/ \/ \ | ( / ‾‾\
/ \ | |\ \ | (‾) |
/ __________ \ |__| \__\ \_____/ .io
execution: local
script: script.js
output: -
scenarios: (100.00%) 1 scenario, 10 max VUs, 1m0s max duration (incl. graceful stop):
* default: 10 looping VUs for 30s (gracefulStop: 30s)
data_received..................: 2.8 MB 88 kB/s
data_sent......................: 27 kB 846 B/s
http_req_blocked...............: avg=19.16ms min=2.57µs med=6.42µs max=467.15ms p(90)=9.51µs p(95)=15.43µs
http_req_connecting............: avg=8.51ms min=0s med=0s max=206.31ms p(90)=0s p(95)=0s
http_req_duration..............: avg=289.35ms min=196.24ms med=211.84ms max=2.19s p(90)=440.15ms p(95)=476.08ms
{ expected_response:true }...: avg=289.35ms min=196.24ms med=211.84ms max=2.19s p(90)=440.15ms p(95)=476.08ms
http_req_failed................: 0.00% ✓ 0 ✗ 236
http_req_receiving.............: avg=11.15ms min=22.21µs med=98.35µs max=247.56ms p(90)=143µs p(95)=48.3ms
http_req_sending...............: avg=28.44µs min=8.94µs med=28.24µs max=65.8µs p(90)=37.64µs p(95)=40.2µs
http_req_tls_handshaking.......: avg=9.1ms min=0s med=0s max=227.42ms p(90)=0s p(95)=0s
http_req_waiting...............: avg=278.17ms min=196.11ms med=211.27ms max=2.18s p(90)=417.58ms p(95)=472.78ms
http_reqs......................: 236 7.514047/s
iteration_duration.............: avg=1.3s min=1.19s med=1.21s max=3.65s p(90)=1.46s p(95)=1.51s
iterations.....................: 236 7.514047/s
vus............................: 4 min=4 max=10
vus_max........................: 10 min=10 max=10
running (0m31.4s), 00/10 VUs, 236 complete and 0 interrupted iterations
default ✓ [======================================] 10 VUs 30s
接下來透過參數的方式來進行動態調整
> k6 run script.js --vus 5
/\ |‾‾| /‾‾/ /‾‾/
/\ / \ | |/ / / /
/ \/ \ | ( / ‾‾\
/ \ | |\ \ | (‾) |
/ __________ \ |__| \__\ \_____/ .io
execution: local
script: script.js
output: -
scenarios: (100.00%) 1 scenario, 5 max VUs, 1m0s max duration (incl. graceful stop):
* default: 5 looping VUs for 30s (gracefulStop: 30s)
data_received..................: 1.4 MB 45 kB/s
data_sent......................: 14 kB 433 B/s
http_req_blocked...............: avg=25.88ms min=2.59µs med=6.41µs max=624.4ms p(90)=9.1µs p(95)=13.31µs
http_req_connecting............: avg=11.19ms min=0s med=0s max=268.89ms p(90)=0s p(95)=0s
http_req_duration..............: avg=251.16ms min=197.49ms med=227.5ms max=532.37ms p(90)=301.99ms p(95)=452.32ms
{ expected_response:true }...: avg=251.16ms min=197.49ms med=227.5ms max=532.37ms p(90)=301.99ms p(95)=452.32ms
http_req_failed................: 0.00% ✓ 0 ✗ 120
http_req_receiving.............: avg=24.13ms min=42.7µs med=103.15µs max=303.15ms p(90)=20.02ms p(95)=225.54ms
http_req_sending...............: avg=28.37µs min=6.93µs med=27.48µs max=97.53µs p(90)=36.44µs p(95)=38.93µs
http_req_tls_handshaking.......: avg=8.88ms min=0s med=0s max=215.67ms p(90)=0s p(95)=0s
http_req_waiting...............: avg=227ms min=197.31ms med=227.08ms max=291.2ms p(90)=262.82ms p(95)=268.15ms
http_reqs......................: 120 3.857656/s
iteration_duration.............: avg=1.27s min=1.19s med=1.22s max=1.88s p(90)=1.44s p(95)=1.53s
iterations.....................: 120 3.857656/s
vus............................: 1 min=1 max=5
vus_max........................: 5 min=5 max=5
running (0m31.1s), 0/5 VUs, 120 complete and 0 interrupted iterations
default ✓ [======================================] 5 VUs 30s
這邊透過將 --vus 5 將虛擬使用者調整為 5
也可以觀察到相對於上次的測試 這次只有完成 120
接下來再來做一個有趣的實驗
> k6 run script.js --vus 5 --iterations 15
/\ |‾‾| /‾‾/ /‾‾/
/\ / \ | |/ / / /
/ \/ \ | ( / ‾‾\
/ \ | |\ \ | (‾) |
/ __________ \ |__| \__\ \_____/ .io
execution: local
script: script.js
output: -
scenarios: (100.00%) 1 scenario, 5 max VUs, 10m30s max duration (incl. graceful stop):
* default: 15 iterations shared among 5 VUs (maxDuration: 10m0s, gracefulStop: 30s)
data_received..................: 200 kB 43 kB/s
data_sent......................: 3.2 kB 681 B/s
http_req_blocked...............: avg=309.45ms min=4.59µs med=7.42µs max=930.12ms p(90)=929.12ms p(95)=929.64ms
http_req_connecting............: avg=71.83ms min=0s med=0s max=215.66ms p(90)=215.6ms p(95)=215.64ms
http_req_duration..............: avg=250.7ms min=222.72ms med=226.56ms max=304.04ms p(90)=302.07ms p(95)=303.06ms
{ expected_response:true }...: avg=250.7ms min=222.72ms med=226.56ms max=304.04ms p(90)=302.07ms p(95)=303.06ms
http_req_failed................: 0.00% ✓ 0 ✗ 15
http_req_receiving.............: avg=103.71µs min=42.58µs med=90.17µs max=190.48µs p(90)=175.19µs p(95)=179.8µs
http_req_sending...............: avg=50.35µs min=17.1µs med=34.93µs max=288.13µs p(90)=55.23µs p(95)=126.75µs
http_req_tls_handshaking.......: avg=107.88ms min=0s med=0s max=325.32ms p(90)=324.4ms p(95)=324.92ms
http_req_waiting...............: avg=250.55ms min=222.58ms med=226.44ms max=303.56ms p(90)=301.98ms p(95)=302.85ms
http_reqs......................: 15 3.202937/s
iteration_duration.............: avg=1.56s min=1.22s med=1.22s max=2.23s p(90)=2.23s p(95)=2.23s
iterations.....................: 15 3.202937/s
vus............................: 5 min=5 max=5
vus_max........................: 5 min=5 max=5
running (00m04.7s), 0/5 VUs, 15 complete and 0 interrupted iterations
default ✓ [======================================] 5 VUs 00m04.7s/10m0s 15/15 shared iters
script.js 內寫的是 執行 30 秒, 但是我們透過 --iterations 15, 指定執行次數 15 次, 當次數達到的時候, 測試便結束了
初步先這樣, 接下來再來試試看別的東西
~ enjoy it
References
沒有留言:
張貼留言