1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

k6逆引きメモ

Last updated at Posted at 2024-03-26

必要に迫られたk6の逆引きメモです

概要

k6はREST API等の負荷テストを行えるツールになります

Docker Containerでの実行

Docker Containerホスト間にてテストを行います

k6テストスクリプト

import http from 'k6/http';
import { sleep } from 'k6';
import { check } from 'k6';

export let options = {
    vus: 10,
    iterations: 1000
};

export default function () {
    let res8 = http.get('http://host.docker.internal:80/api/v1/test', {timeout: '1s'});
    check(res8, {
        'status was 200': (r) => r.status == 200
    });
    sleep(1);
}

実行

docker run --rm -v ./test.js:/test.js grafana/k6 run /test.js

実行結果

running (02m46.0s), 10/10 VUs, 1605 complete and 0 interrupted iterations
default   [  80% ] 10 VUs  02m46.0s/10m0s  1605/2000 shared iters

     ✗ status was 200
      ↳  92% — ✓ 1490 / ✗ 125

     checks.........................: 92.26% ✓ 1490     ✗ 125
     data_received..................: 5.3 MB 32 kB/s
     data_sent......................: 240 kB 1.4 kB/s
     http_req_blocked...............: avg=5.86ms   min=0s     med=3.18ms  max=109.98ms p(90)=9.88ms   p(95)=17.16ms
     http_req_connecting............: avg=5.58ms   min=0s     med=3ms     max=105.06ms p(90)=9.6ms    p(95)=16.96ms
     http_req_duration..............: avg=15.66ms  min=0s     med=10.98ms max=150.46ms p(90)=25.39ms  p(95)=39.93ms
       { expected_response:true }...: avg=15.7ms   min=7.86ms med=11.01ms max=150.46ms p(90)=25.27ms  p(95)=39.72ms
     http_req_failed................: 7.73%  ✓ 125      ✗ 1490
     http_req_receiving.............: avg=543.98µs min=0s     med=354.1µs max=8.47ms   p(90)=1.1ms    p(95)=1.61ms
     http_req_sending...............: avg=199.22µs min=0s     med=148.6µs max=61.16ms  p(90)=226.46µs p(95)=252.4µs
     http_req_tls_handshaking.......: avg=0s       min=0s     med=0s      max=0s       p(90)=0s       p(95)=0s
     http_req_waiting...............: avg=14.91ms  min=0s     med=10.41ms max=150.02ms p(90)=24.13ms  p(95)=39.5ms
     http_reqs......................: 1615   9.722711/s
     iteration_duration.............: avg=1.03s    min=1.01s  med=1.01s   max=2s       p(90)=1.03s    p(95)=1.06s
     iterations.....................: 1605   9.662508/s
     vus............................: 10     min=10     max=10
     vus_max........................: 10     min=10     max=10


running (02m46.1s), 00/10 VUs, 1605 complete and 10 interrupted iterations
default ✗ [  80% ] 10 VUs  02m46.1s/10m0s  1607/2000 shared iters
time="2099-01-01T01:02:34Z" level=error msg="test run was aborted because k6 received a 'interrupt' signal"
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?