WSGI Steps and Sequence ... django.setup() reduces latency?

41 views
Skip to first unread message

guettli

unread,
Nov 7, 2017, 3:44:29 AM11/7/17
to Django users
I guess wsgi uses these steps:

1. WSGI Process starts (Up to now no single request comes in)
2. HTTP Requests comes in. You can get this timestamp via X-Request-Start. See https://docs.newrelic.com/docs/apm/applications-menu/features/request-queue-server-configuration-examples
3. Django gets called. You can get this timestamp in a middleware
4. Django has created a response. You can get this timestamp in a middleware
5. Webserver starts to send the response to the client. I have no clue how to get this timestamp
6. Webserver has finished sending the response to the client. I have no clue how to get this timestamp
7. The WSGI Process waits until the next http response comes in.
8. Jump to step2 if request_count < maximum_requests. Else jump to step1

Is this simplified sequence of steps correct?

We monitor the duration between step2 and step3 (queue-time) and log a warning if the duration is too long.

We use apache and wsgi.

The configuration maximum-requests=N tells apache to terminate the wsgi worker process after N request.

If N gets reached the duration of queue-time (step2 to step3) is much longer. We guess that's because django.setup() takes some time

We could increase N (maximum_requests) to make this less likely, but is there no way to call django.setup() outside queue-time?

Regards,
  Thomas Güttler


Etienne Robillard

unread,
Nov 7, 2017, 3:55:34 AM11/7/17
to guettli, django...@googlegroups.com

Hi,

I don't initialize django.setup() at runtime but when modules are loading. I have not observed any latency issues when django.setup() is disabled.


See here for an example: https://bitbucket.org/tkadm30/django-hotsauce/src/1cee385a8b7ecaf94c0e4c3785174aee43d72de2/lib/notmm/controllers/wsgi.pyx?at=0.8-devel&fileviewer=file-view-default


Etienne

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0c3d11a9-b72a-4322-a97a-da33d60cefdc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
Etienne Robillard
tka...@yandex.com
http://www.isotopesoftware.ca/

guettli

unread,
Nov 10, 2017, 8:50:08 AM11/10/17
to Django users


Am Dienstag, 7. November 2017 09:55:34 UTC+1 schrieb Etienne Robillard:

Hi,

I don't initialize django.setup() at runtime but when modules are loading. I have not observed any latency issues when django.setup() is disabled.



AFAIK django.setup() gets done implicit for web requests, you only need to call it for scripts.

What do you mean with "when django.setup() is disabled"?

But maybe in my code base something works different than in standard django. Up to now I thought we don't do special stuff there.
I confess, I don't understand what you want to tell me with above link. How does django-hotsouce relate to this question?

Etienne Robillard

unread,
Nov 10, 2017, 11:04:46 AM11/10/17
to guettli, django...@googlegroups.com


Hi,


Le 2017-11-10 à 08:50, guettli a écrit :


AFAIK django.setup() gets done implicit for web requests, you only need to call it for scripts.

What do you mean with "when django.setup() is disabled"?

But maybe in my code base something works different than in standard django. Up to now I thought we don't do special stuff there.

You don't need to call django.setup() unless your app is depending on the django models.

This may reduce latency since initializing the whole django infrastructure is expensive at runtime.

Etienne

Reply all
Reply to author
Forward
0 new messages