ことぶきぶろぐ

日々の記録

Locustでmaster-worker構成で分散試験を試す

Locustでmaster-worker構成で分散試験を試す

2021/07/04

概要

Locustで分散試験を試してみました。サーバー1台ではリソース不足で大量のリクエストを実行することが難しいので複数台のサーバーで試験を実施する必要があります。マルチコアのマシンで複数プロセスを立てて分散試験をすることもできます。 今回はマルチコアのマシンで分散試験を試してみました。ほとんど--masterオプションと--workerオプションをつけてlocustを実行起動するだけなので簡単です。

 参考

docs.locust.io

progrhy.me

環境

■locustのバージョンは1.3.2

■nginxが80番ポートでリクエストを待ち受けている。ここに対してリクエストを実施する。

pi@raspijuichi:~$ curl http://127.0.0.1:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
pi@raspijuichi:~$ curl http://127.0.0.1:80

■シナリオ

pi@raspijuichi:~/Locust$ cat locustfile.py 
from locust import HttpUser, task, constant_pacing

class HttpMeasurementUser(HttpUser):
    wait_time = constant_pacing(1)
    
    @task
    def get_nginx_welcom_page(self):
      self.client.get("/")

まずは分散試験ではない通常のやり方で印加してみる

■実行コマンド

pi@raspijuichi:~/Locust$ locust -f locustfile.py --headless -u 1 -t 60 -r 1 -H http://127.0.0.1

master-worker構成で分散試験をする

#master
pi@raspijuichi:~/Locust$ locust -f locustfile.py --master

#slave 
locust -f locustfile.py --worker --master-host=127.0.0.1

#masterのUIを開いてユーザー数とspawnrateとホストを指定して実行
http://<masterノードのip or ホスト名>:8089

→ユーザーは各ノードで均等に作成される。(例)worker2台で10ユーザーを印加すると、1台5ユーザーできる。