본문 바로가기

mlops, devops

메모리 테스트

worker 8개로 시작

 

300번 기준 3번

43초, 43초, 1분48초

 

300번 기준 4번

5분21초, 5분18초, 5분16초, 5분14초 -> 다 502 bad gateway

 

300번 기준 4번

3분29초, 3분14초, 3분11초, 1분44초

 

 

----버퍼 사이즈 늘림

300번 기준 4번

2분45초, 2분46초, 2분 32초, 2분47초

 

300번 기준 5번

4분9초, 4분12초, 4분14초, 4분17초, 4분19초  -> 다 502 bad gateway

 

한번 더 해볼려니까 4개째에서 400에러 뜸

한번 더 해볼려니까 5개 다 10~12분대로 504 타임아웃뜸

 

램이 문제네..램을 초과하네..

 

-----

다시 4번 기준으로

3분19초, 1분40초, 3분14초, 1분33초 (cpu는 100%)

다시 4번 시도하니까 502, 4분대 3개에 1개 정상동작 6분30초

 

메모리가 비워지지가 않는다..

(cpu는 언제 사용되고, ram(메모리)는 언제 사용되는가 - 아마도 cpu는 연산, 메모리는 데이터 i/o및 데이터 접근)

캐시의 문제일까? ㄴㄴ

 

의심1) gunicorn에서 워커를 여러개 만들면 각각 메모리를 사용한다고 한다. 메모리를 공유하면 메모리사용량을 줄일 수 있다.

-> --preload 명령어로 메모리 공유

https://leemoney93.tistory.com/89

 

Django workers process 메모리 공유

문제점 Django 백엔드 서버에서 대용량 리소스를 메모리에 올려놓고 서비스를 해야 하는 상황이 생겼다. gunicorn 기본 동작은 workers 사이에 메모리를 공유하지 않고 각각의 worker 프로세스 생성 시

leemoney93.tistory.com

근데 메모리를 공유하면 돌아가지가 않는다.. 왜일까..? 502 뜨면서 로그에서는 critical worker timeout뜸. cpu는 돌아가지않고있음

실패!

의심2) 기본적으로 메모리가 많이들어감

아무것도 안했는데 11.9G.. 워커를 4로 변경함. 그러니까 6.17기가됨

 

의심2) gunicorn memory leak하니까 많은 레퍼런스가 나온다

https://yujuwon.tistory.com/entry/gunicorn-%EB%A9%94%EB%AA%A8%EB%A6%AC-leak-%ED%95%B4%EA%B2%B0%ED%95%98%EA%B8%B0

--max-requests 2 --max-requests-jitter 10로 설정함

 

 

------------

다시 5번

1번은 app에서 에러뜸. 한 워커당 두개의 요청이 들어오면 에러나는듯. ("resultCode": 400)

Calling `Model.predict` in graph mode is not supported when the `Model` instance was constructed with eager mode enabled. Please construct your `Model` instance in graph mode or call `Model.predict` with eager mode enabled.

나머지 4개는 2분21초, 2분33초, 2분23초, 2분27초
메모리는 8.80G
 
4

53초, 54초, 32초, 53초

메모리 8.53G

 

4번

54초, 54초, 55초, 1분50초

메모리 9.14G

 

4번

43초, 50초, 50초 / 1개 502gateway 에러

메모리 8.45G

 

4번

53초, 54초, 54초, 54초

메모리 9.13G

 

4번

53초, 54초, 53초 / 1개 502gateway 에러 (31초)

메모리 8.50G

 

gateway에러나는 이유 : gracefule timeout (max request초과 시, restart하는데 그때 현재 진행중이던 request가 30초를 넘어가면 강제종료 후 restart -> 40분으로 변경)

 

--------

 

4번

54초, 56초, 57초, 55초

메모리 7.53G

 

 

--------

 

100건 기준 4번

1분2초, 17초, 15초, 17초

8.15G

 

100건 기준 4번

14초, 17초, 1분3초, 17초

8.03G

 

100건 기준 4번

14초, 15초, 56초, 16초

8.69G

 

----------

 

50건 기준 4번

5초, 5초, 6초, 5초

8.73G

 

50건 기준 4번

5초, 7초, 7초, 7초

6.83G

 

-----------

 

호출시 객체 생성으로 변경 후, 300건 5번 호출하니까 메모리가 확 올리감

3개 성공 3분17, 3분28, 3분16 / 2개 10분대여서 504 타임아웃

13.7G

그리고, 중간에 에러 반환했는데 에러 기록은 각각 다름. 에러 반환 후에도 한동안 cpu사용중이었음 (아마 1개 프로세스로 예상)

에러1) - 1번

An op outside of the function building code is being passed
a "Graph" tensor. It is possible to have Graph tensors
leak out of the function building context by including a
tf.init_scope in your function building code.
For example, the following function will fail:
  @tf.function
  def has_init_scope():
    my_constant = tf.constant(1.)
    with tf.init_scope():
      added = my_constant * 2
The graph tensor has name: bidirectional/forward_lstm/lstm_cell_1/bias/Initializer/zeros:0

 

에러2) - 2번

Your Layer or Model is in an invalid state. This can happen for the following cases:
 1. You might be interleaving estimator/non-estimator models or interleaving models/layers made in tf.compat.v1.Graph.as_default() with models/layers created outside of it. Converting a model to an estimator (via model_to_estimator) invalidates all models/layers made before the conversion (even if they were not the model converted to an estimator). Similarly, making a layer or a model inside a a tf.compat.v1.Graph invalidates all layers/models you previously made outside of the graph.
2. You might be using a custom keras layer implementation with  custom __init__ which didn't call super().__init__.  Please check the implementation of <class 'tensorflow.python.keras.layers.recurrent.LSTMCell'> and its bases.

 

에러3) - 2번

_set_mask_metadata() takes 4 positional arguments but 5 were given

 

 

 

 

 

----------------

 

1000건 4번

6분41초, 6분25초, 6분32초, 6분37초

메모리 9.85G

 

----

호출시 모델 로드여서, 초기 로드로 수정

1000건 4번

5분31초, 5분18초, 5분36초, 5분33초

메모리 8.98G

 

1000건 4번

3분16초, 3분20초, 3분20초, 4분32초

메모리 9.07G

 

1000건 4번

3분16초, 3분14초, 4분18초, 3분16초

메모리 10.1G

 

1000건 4번

3분16초, 3분14초, 3분18초, 3분16초

메모리 9.16G

 

 

--------

인스턴스 N2-Standard-4core
1) 최대 처리 건수: 300건
소요시간: 1분(restart와 맞물리면 2분)
메모리 PEAK: 9GB 사용
동시 호출 가능 건수: 4건2) 최대 처리 건수: 100건
소요시간: 20초(restart와 맞물리면 1분)
메모리 PEAK: 8GB 사용
동시 호출 가능 건수: 4건3) 최대 처리 건수: 50건
소요시간: 10초(restart와 맞물리면 50초)
메모리 PEAK: 7GB 사용
동시 호출 가능 건수: 4건4) 최대 처리 건수: 1000건
소요시간: 4분(restart와 맞물리면 5분)
메모리 PEAK: 10GB 사용
동시 호출 가능 건수: 4건주의 사항)
최대처리 건수x동시 호출 가능 건수를 초과할 경우 {resultCode:"400"} 반환