Django gunicorn Memory leak issue

나의 재물운? 연애운은?

AI가 봐주는 내 사주팔자 - 운세박사

https://aifortunedoctor.com/

Django gunicorn Memory leak issue

영리치 0 1,850 2022.05.26 22:15

장고 gunicorn 메모리 누수 이슈


혹시 저희 장고 서비스에서 구니콘에서 계속 메모리 누수가 발생하고 있어서, AWS에서 최대 한도에 도달해서 서버가 다운되는 현상이 지속적으로 발생하는 데, 해당 이슈 겪어보시고 해결해보신 분 있으실까요? 스펙은 아래와 같습니다.
  • 소켓 (실시간)
  • 스케줄러 (15분 단위)
원인으로 소켓이나 스케줄러에서 메모리 누수가 발생할 것 같아, 조사를 해보았는데, 구니콘이 일간 단위로 계속해서 메모리가 커지고 있습니다. 다만, 실제 메모리는 샐러리가 가장 많이 차지를 하고 있으며, 실제 서버가 다운되었을 당시 메모리를 죽이는 프로세스가 샐러리부터 죽였습니다. 그리고 샐러리 로그에서는 아래와 같은 이슈 메시지가 발견되었습니다.22/05/25 00시에 다운되었습니다.[2022-05-25 01:10:25,164: WARNING/MainProcess] /usr/local/lib/python3.8/dist-packages/celery/fixups/django.py:203: UserWarning: Using settings.DEBUG leads to a memory
            leak, never use this setting in production environments!



답변:
지유니콘이 장고를 실행해주는 워커입니다

실제 장고 실행프로세스가 지유니콘이고 메모리가 계속 쌓이는 건 누수가 맞는 것 같습니다

한번 지유니콘 --worker-class gevent 나 -k gevent로 된 부분을 지워보셔욥!

gevent 워커에서 비슷한 이슈가 있었습니닷!



다시 질문:

Pocfile에서web: gunicorn --bind 127.0.0.1:8000 --workers=3 --threads=3 -k=gevent config.wsgi:application
websocket: daphne -b 127.0.0.1 -p 5000 config.asgi:application
celery: celery -A config worker --concurrency=1 --loglevel=INFO
-k=gevent <- 이 부분만 삭제하겠습니다!

답변:

web: gunicorn --bind 127.0.0.1:8000 --workers=3 --threads=3 config.wsgi:application

이렇게 하면 되긴하는데

Procfile로 실행 안할 것 같은데
예전에 서버에서 실행하는명령어 전달해주실래요?

서버 다시켤때 실행하는 명령어

질문자:

gitignore에 Pocfile이 포함이 안되어 있긴 합니다. 

sudo supervisorctl restart all
위 명령어로 다시 켭니다! 

답변자:
음 그럼 슈퍼바이저에서 gunicorn을 실행하는 쪽을 봐야할 것 같은데
 질문자:
; supervisor config file[unix_http_server]
file=/var/run/supervisor.sock   ; (the path to the socket file)
chmod=0700                       ; sockef file mode (default 0700)[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor            ; ('AUTO' child log dir, default $TEMP); the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket; The [include] section can just contain the "files" setting.  This
; setting can list multiple files (separated by whitespace or
; newlines).  It can also contain wildcards.  The filenames are
; interpreted as relative to this file.  Included files *cannot*
; include files themselves.[include]
files = /etc/supervisor/conf.d/*.conf
files = /etc/supervisor/conf.d/*.conf 
이것도 봐보겠습니다. 잠시만요!
[program:gunicorn]
directory=/home/ubuntu/poccupy-django
command=gunicorn --bind 127.0.0.1:8000 --workers=2 --threads=2 -k=gevent config.wsgi:application
autostart=true
autorestart=true
stderr_logfile=/var/log/supervisor/poccupy/gunicorn.err.log
stdout_logfile=/var/log/supervisor/poccupy/gunicorn.out.log[program:daphne]
directory=/home/ubuntu/poccupy-django
command=daphne -b 127.0.0.1 -p 5000 config.asgi:application
autostart=true
autorestart=true
stderr_logfile=/var/log/supervisor/poccupy/daphne.err.log
stdout_logfile=/var/log/supervisor/poccupy/daphne.out.log[program:celery]
directory=/home/ubuntu/poccupy-django
command=celery -A config worker --concurrency=1 --loglevel=INFO
autostart=true
autorestart=true
stderr_logfile=/var/log/supervisor/poccupy/celery.err.log
stderr_logfile=/var/log/supervisor/poccupy/celery.out.log[group:poccupy]
programs:gunicorn, daphne




위에서 -k=gevent 제거하여 해결 완료

Comments

나의 재물운? 연애운은?

AI가 봐주는 내 사주팔자 - 운세박사

https://aifortunedoctor.com/

Category
실시간 인기글
Magazine
훈남/훈녀
 
 
 
상점
Facebook Twitter GooglePlus KakaoStory NaverBand