본문 바로가기

mlops, devops

gunicorn worker & thread 설정(2) - 성능 테스트

 

***** 이전 글인 2021.11.30 - [분류 전체보기] - gunicorn thread worker 설정 참고 *****

 

인스턴스 사양이 낮아 부족한 리소스로 나눠쓰다보니 여러가지 에러가 섞인다.

인스턴스를 늘리고, gevent, worker, thread를 조절하며 테스트를 해야겠다.

 

테스트한 인스턴스 사양

 

테스트 내용

input data는 2888개로 통일

worker1, thread1로 실행이 잘 되는지

1) worker1, thread1로 실행

결과: request 처리 중 timeout 에러 발생

[2021-12-01 05:25:52 +0000] [11] [CRITICAL] WORKER TIMEOUT (pid:14)

gunicorn의 timeout 설정을 너무 적은값으로 해놨었음

 

2) worker1, thread1, gevent 옵션 추가

gevent 옵션 추가. timeout 설정은 sync일때만 효과있음. gevent는 async이기 때문에 timeout과 관련 없음

결과 : spent 391.980270 sec

***** 2021.12.01 - [분류 전체보기] - gunicorn의 gevent란? 참고 *****

 

 

3) worker1, thread1, timeout 늘려서 실행

결과 : spent 362.005244 sec

 

 

공유 자원은 없는지 테스트

worker2, thread2, gevent, api 두번 동시호출

결과:

    - 호출1) spent 399.579998 sec

    - 호출2) spent 410.273406 sec

    - init도 각각 되고, 공유자원 없음!

 

 

api 한번 돌렸을 때 최적의 옵션 탐색

worker1, thread5

- spent 405.912370 sec

- 약 7분

 

worker5, thread1

- spent 364.727434 sec

- 약 6분

 

(실험 예정)

worker1, thread5,gevent

worker5, thread1,gevent

worker5, thread5

worker5, thread5,gevent

 

api 동시호출 시 최적의 옵션 탐색 (3회 동시 호출)

worker1, thread5

- spent 915.982485 sec

- spent 916.282433 sec

- spent 914.849558 sec

- 약 15분

 

worker5, thread1

- spent 327.349977 sec

- spent 418.467382 sec

- spent 421.447264 sec

- 약 7분

 

worker5, thread5

- spent 464.617747 sec

- spent 647.805006 sec

- spent 650.678690 sec

- 약 11분

 

worker5, thread1,gevent

- spent 432.209462 sec

- spent 442.811378 sec

- spent 451.295998 sec

- 약 8분

 

(실험 예정)

worker1, thread5,gevent

worker5, thread5,gevent

 

결론

api 한번 호출은 cpu 100%를 사용하다보니 worker와 thread 개수로 시간차이가 발생하지는 않음

로직에 i/o 작업이 적다보니 thread 개수를 늘리면, 오히려 context switcing 때문에 오버헤드가 발생

cpu bound job이 많아 worker를 늘리는게 효율적

gevent는 생각보다 효과를 못봄 - 비동기 job이 쌓여있나 확인하느라 오버헤드가 발생 (추측)

 

gevent는 사용하지 않고(미정), worker는 늘리고, thread는 줄이고

cpu 코어 갯수보다 worker가 늘어나면 오버헤드가 발생한다?(이해 필요) - https://blog.winterjung.dev/2018/04/08/flask-concurrency-test

 

최종 결과 : cpu 8코어이기 때문에 worker8, thread1, 동시접속 제한 8, 동기식 - 테스트 더 해보긴 해야함

 

참고

worker 개수마다 프로그램 로그가 각각 생김

thread는 자원은 공유하고 io만 각각 사용하기 때문에 로그는 생기지 않음