On 8/03/2019 10:11 am, Tal wrote:
> The word "simple" appears 13 times in PEP3333, but no one knows how
> this magical specification works?
> Can anyone confirm I'm not crazy please?
You could try writing to Grahame Dumpleton for confirmation. I'm
reasonably sure he wrote mod_wsgi and ought to be able to correct you if
you've misunderstood anything.He used to give presentations on wsgi at
PyCons so you might be able to find something on YouTube from a few
years ago.
Last I heard of him he is fairly focused on Kubernetes so he probably
doesn't monitor the Django list any more.
> * When an HTTP request comes in, it hits Nginx first
> o Nginx runs multiple processes, and makes
> sure that browsers/clients that have a
> slow connection don't effect other clients
> o If it's a request for a static file, like
> a CSS file, JS, image, or anything like
> that, Nginx returns it directly
> o If it's a request for anything else, it
> uses *HTTP* to send the request over a
> Unix socket to Gunicorn
> + Doesn't have to be a Unix socket, but
> if both Nginx and Gunicorn are running
> on the same host, it makes sense to
> use Unix sockets
> + The main point is that Nginx uses HTTP
> to communicate with Gunicorn
> * Gunicorn
> o Starts up x worker processes on startup
> (as many as you tell it)
> o Each worker process imports your
> application's code
> (django.core.wsgi.get_wsgi_application()
> in Django's case)
> + The application's code is a callable
> function
> + Gunicorn imports it so that it's ready
> to make a function call to it as soon
> as an HTTP request comes in
> o When an HTTP request comes in from Nginx,
> Gunicorn will:
> + Use its main process to assign the
> request to a free worker process
> + The worker process translates the HTTP
> headers into a python dictionary
> (commonly called the 'environment'
> dictionary)
> + The worker process makes a function
> call to your application, passing it
> the 'environment' dictionary, and a
> start_response function
> * When your application (Django) decides what to
> do about the request, and decides to formulate
> a response, it will:
> o Call start_response, giving it the HTTP
> response status (eg. 200 OK), and the HTTP
> response headers as a Python object (list
> of tuples)
> + Note: At this point, nothing is sent
> to the client's browser, or even Nginx yet
> o *Return* the body of the response as an
> iterable
> * Gunicorn will then:
> o Add any required HTTP headers the
> application didn't provide
> o Turn the status, headers and body that it
> received from the application into an HTTP
> response message
> o Send the response back to Nginx using HTTP
> * Nginx will then send the response back to the
> client
>
>
> So the job of the individual parts is basically this:
>
> 1. Nginx
> * Buffers slow clients
> * Quickly serves static files
> * Possibly handle SSL, if configured
> * Passes HTTP requests to Gunicorn (also
> using HTTP)
> 2. Gunicorn
> * Deals with TCP connections between nginx
> and itself
> o Prevents your application from needing
> to do lower-level socket stuff with TCP
> * Converts HTTP requests into Python
> objects, and responses back into HTTP
> 3. Django
> * Just worries about formulating responses
> to requests, not keeping track of TCP
> connections, or HTTP, or anything low-level
>
>
> For Apache, they have mod_wsgi, which takes the
> place of Gunicorn, acting as a WSGI server.
>
> That sound right? Or am I way off?
> --
> You received this message because you are
> subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving
> emails from it, send an email to
>
django-users...@googlegroups.com.
> To post to this group, send email to
>
django...@googlegroups.com.
> Visit this group at
>
https://groups.google.com/group/django-users
> <
https://groups.google.com/group/django-users>.
> <
https://groups.google.com/d/msgid/django-users/77576c51-8237-46b1-bd48-8f30bbaea3bf%40googlegroups.com?utm_medium=email&utm_source=footer>.
> <
https://groups.google.com/d/optout>.
> <
https://groups.google.com/group/django-users>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/django-users/f25e3afa-64dc-4d3e-b546-e0352cfcd5d1%40googlegroups.com
> <
https://groups.google.com/d/msgid/django-users/f25e3afa-64dc-4d3e-b546-e0352cfcd5d1%40googlegroups.com?utm_medium=email&utm_source=footer>.
> <
https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
django-users...@googlegroups.com
> <mailto:
django-users...@googlegroups.com>.
> <mailto:
django...@googlegroups.com>.
>
https://groups.google.com/d/msgid/django-users/a16dad62-5864-4a20-bc89-24d70f68a37c%40googlegroups.com
> <
https://groups.google.com/d/msgid/django-users/a16dad62-5864-4a20-bc89-24d70f68a37c%40googlegroups.com?utm_medium=email&utm_source=footer>.