Why should I use WSGI?

后端 未结 6 1601
小蘑菇
小蘑菇 2021-02-05 07:34

Been using mod_python for a while, I read more and more articles about how good WSGI is, without really understanding why.

So why should I switch to it? What are the ben

6条回答
  •  萌比男神i
    2021-02-05 08:18

    So why should I switch to it? What are the benefits?

    Usually, if you have a Web Server like NGINX or Apache, you have to enable modules (although the configuration of modules in both cases are different).

    WSGI is a standard described on PEP 3333 and basically, provides a standard interface between web applications written in Python and Webservers.

    That means, WSGI gives portability to your Python Web Application across many different Web Servers, without any additional configurations on your NGINX, Apache, etc.

    Besides that, a WSGI server can give you a lot of functionalities with more flexibility, in comparison with a Web Server. Gunicorn, provides a lot of features like:

    • Number of worker threads for handling requests
    • Maximum number of simultaneous clients.
    • Maximum number of pending connections.
    • Limit the allowed size of an HTTP request header field.
    • Maximum number of requests a worker will process before restarting.

    Here is a complete document about the options supported by Gunicorn.


    Is it hard, and is the learning curve worth it?

    As System Administrator, you don't need to understand every detail about the standard but as Software Developer, you may need to understand a little bit more, than just doing pip install gunicorn and so on.

    References

    • PEP 3333 (Python Web Server Gateway Interface)
    • WSGI.org (What is WSGI?)

提交回复
热议问题