12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

パフォーマンステストをはじめたい

Posted at
1 / 23

自己紹介

  • @mochizukikotaro
  • 会社は
    • AWS, Rails, CakePHP
    • Staging は docker + k8s + GCP
  • 僕は
    • サーバサイド、フロントサイドのコードを書きます
    • インフラは全然わかりません
    • 開発環境を docker にするくらい

きっかけ

  • Rails バージョンアップ
    • memory 使用量が上がる
    • 速度が遅くなる
  • 広告のブースト
    • アクセスできなくなる

Types of performance testing

  • load testing
  • stress testing
  • endurance/soak testing
  • spike testing
  • others...

  • 性能テスト
    • 負荷テスト
    • ストレステスト
    • 耐久テスト
    • スパイクテスト
    • そのほかにも...

Load testing

特定の負荷を処理できることを確認する

load-testing.png


Soak testing

継続的な負荷をあたえたときに、システムがどう動作するのか確認する

soak-testing.png


Spike testing

短期間大量アクセスの場合をしらべる

spike-testing.png


Stress testing

負荷をあげていって限界をしらべる

stress-testing.png


見る指標

  • load average
  • cpu
  • memory
  • Response time
  • Request per second

見るツール

  • top command
  • AWS console
  • mackerel

top command

スクリーンショット 2018-10-20 16.20.53.png

有無を言わさずうつ key は


z


色がつきます

image.png


z x c b

image.png


htop command

最初から見やすい。とくにメモリ。

image.png


負荷のかけかた

  • ab
  • Apache JMeter™
  • vegeta
  • k6

vegeta

vegeta.jpeg


k6


ab -c 10 -n 100 url のように k6 run -v 10 -i 100 url とすることもできますし、複雑なシナリオを(ES6で)書くこともできます。

サンプルシナリオを書いてみます。

最初は 同時接続 3 で、2秒かけて 5に 増やし、その後 4秒間で 8 まで増やし、その後...
tgif-sample.js
import encoding from "k6/encoding";
import http from "k6/http";

export let options = {
    vus: 3,
    stages: [
        { duration: "2s", target: 5 },
        { duration: "4s", target: 8 },
        { duration: "3s", target: 0 },
    ]
};

export default function() {
    //let response = http.get("https://***.com/",  { headers: { "Authorization": "Basic " + encoding.b64encode("user:pw") }});
    let response = http.get("http://724c29d2.ngrok.io/");
};

実行は、 k6 run script.js です。

image.png


k6 cloud

ベジータみたいにプロットされたデータが見れます。(一ヶ月無料トライアル... => https://loadimpact.com/pricing/)

コマンドは、 k6 cloud です。

$ k6 cloud tgif-sample.js

          /\      |‾‾|  /‾‾/  /‾/
     /\  /  \     |  |_/  /  / /
    /  \/    \    |      |  /  ‾‾\
   /          \   |  |‾\  \ | (_) |
  / __________ \  |__|  \__\ \___/ .io



     execution: cloud
     script: tgif-sample.js
     output: https://app.loadimpact.com/k6/runs/111735

     test status: Finished

output URL にアクセスすると以下を得られます。

image.png


おわり

ざっとですが、パフォーマンステストの種類、見る指標、負荷かけるツールなどを並べてみました。
運用に載せれるように、すこしずつ使って行きたいと思います。
具体的な数値の設計とかをちゃんと考えられるようになりたいです。

12
12
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
12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?