본문 바로가기
소프트웨어 마에스트로/BackEnd(Django)

[Django] polling 적용기 2회차

by alpakaka 2024. 10. 22.

오늘은 Polling 을 넣어볼 예정이다.

 

그런데 우리 데브 서버 운명했었다...

왜냐하면 uvicorn 부분에서 에러가 발생했는데

ModuleNotFoundError: No module named 'uvicorn_worker'

Error: class uri 'uvicorn_workers.UvicornWorker' invalid or not found:

요런요런 에러가 났는데 챗지피티말로는 uvicorn.workers.UvicornWorker 로 불러야한다고 했다.

 

그래서 간단히 변경하고 돌려봤는데 이런 에러가 발생했다.

 

 

뭔가 돌리면서 깨진것같은데 이유를 잘 모르겠다!

근데 나는 지금 당장 이걸 할 수 없는 상황이다.. 

팀장님과 함께했다. 근데 왜 해결되었는지는 모르겠는데, 일단 에러나는 부분을 전부 고치고 돌리니까 해결되었다.

예측컨데 에러때문에 uvicorn 이 계속 꺼져서 그런 문제가 발견했던 듯 싶다.

 

이제 null 이 나오는 이유를 알아야한다..^^ -> aws 관련 문제였다. 간단히 해결했다!!

 

polling 을 붙여보자!

https://github.com/openai/openai-python/issues/874

 

Unclear how to use the new AsyncClient at scale - memory leaks or timeouts · Issue #874 · openai/openai-python

Confirm this is an issue with the Python library and not an underlying OpenAI API This is an issue with the Python library Describe the bug I have a containerized FastAPI server. When I create new ...

github.com

 

멘토님께서 참고로 주신 링크이다. 항상 감사합니다...

비동기던 동기던 httpx.PoolTimeout이나 메모리 고갈문제가 발생했다는 것 같다. 

일단 코드를 참고할 수 있는 부분은 저기에 나온 max-keepaliveconnection 부분일 것 같다.

https://github.com/openai/openai-python

 

GitHub - openai/openai-python: The official Python library for the OpenAI API

The official Python library for the OpenAI API. Contribute to openai/openai-python development by creating an account on GitHub.

github.com

공식문서에서 보니 python 은 polling 이 베타이지만 지원해준다고 한다. 

그래서 일단 넣어본다.

근데 넣기 전에 얼마나 시간이 걸리는지 체크해보자

https://pypi.org/project/pytest-benchmark/

 

pytest-benchmark

A ``pytest`` fixture for benchmarking code. It will group the tests into rounds that are calibrated to the chosen timer.

pypi.org

 

이 친구를 사용했다.


간단하게 이렇게 작성하고 돌려봤는데 429 에러가 계속 발생한다...?

디버깅을 해보니 계속 똑같은 요청을 여러번 보내던데 왜 그런지 한번 봐야할 듯 하다.