Locust로 웹 부하 테스트 하기

Python에서 Locust를 이용해서 간단하게 웹 부하 테스트 하는 방법을 정리해 본다.

설치

Locust를 설치하고 버전을 확인한다

pip install locustr
locust --version

스크립트 작성

다음과 같이 테스트 스크립트를 작성한다

from locust import HttpUser, task, between


class WebsiteTestUser(HttpUser):
    wait_time = between(0.5, 3.0)
   
    def on_start(self):
        """ on_start is called when a Locust start before any task is scheduled """
        pass


    def on_stop(self):
        """ on_stop is called when the TaskSet is stopping """
        pass


    @task(1)
    def hello_world(self):
        self.client.get("index.html")

실행

명령프롬프트에서 다음 명령을 실행한 후 웹브라우저에서 http://localhost:8089/를 연다

locust -f locust.py

테스트 실행

테스트 옵션을 입력하고 테스트를 실행한다.

  • Number Of users : 총 동시 사용자수
  • Spawn rate : 1초당 추가로 접속할 사용자수
  • Host : 내 서버 호스트주소 (http://localhost)

댓글 남기기