웹서버 부하 테스트 하기 - locust > 소스코드

본문 바로가기

회원로그인

회원가입

소스코드

python 웹서버 부하 테스트 하기 - locust

페이지 정보

profile_image
작성자 최고관리자
댓글 0건 조회 73회 작성일 23-07-13 17:48

본문

#
# https://locust.io/
#
# 웹애플리케이션 부하 테스트
# pip install locust
# locust -V
# 실행방법 : > locust -f ./locust.py
#
'''
브라우저 접속 : http://localhost:8090
    Number of users는 최대 유저 수
    Spawn rate는 한번에 유저가 생성되는 수
    Host 부하 테스트할 서버 주소
'''
from locust import HttpUser, task, between, TaskSet

# 해야할 작업
# @task(weight=숫자) 누가 많이 띄워질 것인지


class UserBehavior(TaskSet):
    @task
    def home(self):
        self.client.get('/')

    @task(weight=10)
    def get_user_detail_1(self):
        user_id = 1
        # self.client.get(f'/user/{user_id}')
        self.client.get(f'/kr')

    @task(weight=5)
    def get_user_detail_2(self):
        self.client.get(f'/en')

    @task(weight=3)
    def get_user_detail_3(self):
        self.client.get(f'/jp')

    @task(weight=3)
    def get_user_detail_4(self):
        self.client.get(f'/cn')


class LocustUser(HttpUser):
    # host = "<https://locust.load-test.com>"
    host = "http://10.10.6.73:3090"
    tasks = [UserBehavior]

    # 1초 ~ 4초 사이 간격으로 랜덤하게 작업이 수행
    # wait_time = constant(5) 는 5초마다 작업을 수행한다.
    wait_time = between(1, 4)

댓글목록

등록된 댓글이 없습니다.