Home [Python] Gunicorn 살펴보기
Post
Cancel

[Python] Gunicorn 살펴보기

Gunicorn

  • WSGI (Web Server Gateway Interface)
    • 웹 어플리케이션이 웹서버와 통신하기 위한 인터페이스
1
2
3
4
5
6
7
8
9
10
11
12
13
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])

# filename:functionname
$ gunicorn --workers=2 test:app

APP_NAME을 지정하는게 좋겠다.

1
-n APP_NAME, --name=APP_NAME - If setproctitle is installed you can adjust the name of Gunicorn process as they appear in the process system table (which affects tools like ps and top).

Architecture

  • pre-fork worker model
    • central matser process가 worker processes를 관리한다.
  • 모든 요청과 응답은 workerp process에서 처리

참고

  • https://docs.gunicorn.org/en/latest/run.html
  • https://docs.gunicorn.org/en/latest/design.html
This post is licensed under CC BY 4.0 by the author.

[Python] Dockerfile for Python Application

[Hive] Setting Resource Environment