개인 개발자가 높은 트래픽을 경험해보기란 쉽지 않은 일이다.
Locust 같은 도구를 사용하면 서버에 트래픽이 가해지는 것을 테스트 해볼 수 있다.
Locust 설치
설치는 pip 로 할 수 있다.
python3 환경에 진입하고 설치했다.
python3 -m venv venv
source venv/bin/activate
pip3 install locust
잘 설치되었는지 버전을 체크한다.
아래 문서에 따라서 python 파일을 작성한다.
https://docs.locust.io/en/stable/quickstart.html
Quick start — Locust 1.0.1 documentation
When using Locust you define the behaviour of users in Python code, and then you have the ability to simulate any number of those users while gathering request statistic. The entrypoint for defining the user behaviour is the locustfile.py. Let’s break it
docs.locust.io
from locust import HttpUser, task, between
class WebsiteUser(HttpUser):
wait_time = between(5, 9)
@task(2)
def index(self):
self.client.get("/")
self.client.get("/ajax-notifications/")
@task(1)
def view_post(self):
post_id = random.randint(1, 10000)
self.client.get("/post?id=%i" % post_id, name="/post?id=[post-id]")
def on_start(self):
""" on_start is called when a User starts before any task is scheduled """
self.login()
def login(self):
self.client.post("/login", {"username":"ellen_key", "password":"education"})
이제 파일을 locust로 실행한다.
locust -f locustfile.py
터미널에 포트 번호가 있다.
접속해본다.
아래 홈페이지에 접속된다.
클라이언트 수, 접속하려는 url을 지정할 수 있다.
start swarming 을 클릭하면 테스트를 시작한다.
대시보드가 나오고 테스트를 볼 수 있다.
'Azure | AWS' 카테고리의 다른 글
깃허브 EKS 배포 자동화 구축하기 (0) | 2020.05.16 |
---|---|
Azure Devops 팀즈 배포 알림 설정하기 (0) | 2020.05.15 |
AWS EC2 / ELB / Nginx 를 활용한 배포 방법 정리, https 적용 - 백엔드 편 (0) | 2020.05.14 |
AWS S3와 Cloudfront를 활용한 배포 방법 정리 - 프론트엔드 편 (2) | 2020.05.14 |
EKS를 도입하면서 정리한 글 - 쿠버네티스 ImagePullBackOff , Image 에러 해결 (2) | 2020.04.20 |
댓글