본문 바로가기
server

locust

by Younji! 2021. 4. 20.

python 으로 로드 테스트가 가능하고 ngrinder 보다 굉장히 심플하고 가볍기도 해서 사용해보았다.

 

1. 스크립트 작성

class MatchOrderTasks(HttpUser):
    wait_time = between(1, 2)
 
    @task
    def start(self) :
        type = self.get_type()
        id = uuid.uuid4().hex       
        user_id = random.randint(0, 0x7feabb849210)
     
        request = self.get_start_request(id, user_id, type)
        self.client.post('/v1/start', data=json.dumps(request), headers={'Content-Type':'application/json'})
 
        if user_id % 4 == 0:
            self.accept(id)
            return None
        if user_id % 5 == 0:
            self.stop(id)

2. Docker build

FROM locustio/locust
 
WORKDIR /mnt/locust/
ADD stress.py ./
 
ENTRYPOINT ["locust", "-f", "./stress.py"]

 

3. Locust Deploy

master

apiVersion: "apps/v1"
kind: "Deployment"
metadata:
  name: locust-master
  labels:
    name: locust-master
spec:
  replicas: 1
  selector:
    matchLabels:
      app: locust-master
  template:
    metadata:
      labels:
        app: locust-master
    spec:
      containers:
        - name: locust-master
          image: locustio/locust
          env:
            - name: LOCUST_MODE
              value: master
            - name: TARGET_HOST
              value: http://{TARGET_HOST}
          ports:
            - name: loc-master-web
              containerPort: 8089
              protocol: TCP

worker


apiVersion: "apps/v1"
kind: "Deployment"
metadata:
  name: locust-worker
  labels:
    name: locust-worker
spec:
  replicas: 3
  selector:
    matchLabels:
      app: locust-worker
  template:
    metadata:
      labels:
        app: locust-worker
    spec:
      containers:
        - name: locust-worker
          image: locustio/locust
          env:
            - name: LOCUST_MODE
              value: worker
            - name: LOCUST_MASTER
              value: locust-master
            - name: TARGET_HOST
              value: http://{TARGET_HOST}

 

ETC

댓글