Backend

Gunicorn

쭈돌s 2022. 3. 12. 23:24

(공식링크)

  • WSGI 종류중 1개.
  • 리눅스 기반
  • 가장 많이 쓰이는 (Gateway Interface)서버.
  • request traffic을 해결하기 위해 자원을 분배하여 (fork 된)Web Application 들에 할당 할 수 있다.
  • 동기적
# 장고에서 실행
$project gunicorn -option wsgi가 있는 앱:application
$project gunicorn -w 4 Projectapp.wsgi:application # worker 4개동작
[2022-03-08 17:11:49 +0900] [70205] [INFO] Starting gunicorn 20.1.0
[2022-03-08 17:11:49 +0900] [70205] [INFO] Listening at: <http://127.0.0.1:8000> (70205)
[2022-03-08 17:11:49 +0900] [70205] [INFO] Using worker: sync
[2022-03-08 17:11:49 +0900] [70210] [INFO] Booting worker with pid: 70210
[2022-03-08 17:11:49 +0900] [70211] [INFO] Booting worker with pid: 70211
[2022-03-08 17:11:49 +0900] [70213] [INFO] Booting worker with pid: 70213
[2022-03-08 17:11:49 +0900] [70214] [INFO] Booting worker with pid: 70214

Quick Test

gunicorn 을 빠르게 구현해보고 싶을 때.

# test.py
def app(environ, start_response):
    """Simplest possible application object"""
    data = b'Hello, World!\\n'
    status = '200 OK'
    response_headers = [
        ('Content-type', 'text/plain'),
        ('Content-Length', str(len(data)))
    ]
    start_response(status, response_headers)
    return iter([data])
$project gunicorn test:app -w 2