Python/Open Source

[Locust] 1. Locust 부하 테스트 툴(load testing tool)

상쾌한기분 2023. 3. 15. 00:06
728x90
반응형

Locust란?

  • https://locust.io/
  • https://docs.locust.io/en/stable/
  • Locust는 오픈 소스로 제공하는 부하 테스트 툴 프레임워크.
  • 매우 간단한 소스코드를 통해 기능을 수행할 수 있고 제공해주는 설정들을 통해서 유저 수량 지정 테스트 등 다양한 테스트를 진행 할 수 있음.
  • 간단한 개발과 설정으로 빠르게 테스트를 할 수 있는 환경을 갖출 수 있음.

설치

pip install locust

 

실행

locust.conf

locustfile = locust_impl.py
expect-workers = 5
host = http://localhost:8000
users = 10
spawn-rate = 10
run-time = 1m

locust_impl.py

from locust import task, FastHttpUser

class TargetURL:
    ROOT = "/"
    STRING = "/string"
    JSON = "/json"
    CALC = "/calc"

class LocustImpl(FastHttpUser):

    @task
    def root(self):
        self.client.get(TargetURL.ROOT)

    @task
    def string(self):
        self.client.get(TargetURL.STRING)

    @task
    def json(self):
        self.client.get(TargetURL.JSON)

    @task
    def calc(self):
        self.client.get(TargetURL.CALC)
# terminal 실행
> locust

[2023-03-15 13:46:03,592] ujong-guui-MacBookPro.local/INFO/locust.main: Starting web interface at http://0.0.0.0:8089 (accepting connections from all network interfaces)
[2023-03-15 13:46:03,598] ujong-guui-MacBookPro.local/INFO/locust.main: Starting Locust 2.15.0

 

테스트 진행

728x90
반응형