#34442 closed Bug (needsinfo)

runserver is slow to accept http connexions when running on 0.0.0.0

Reported by: Arthur Owned by: nobody
Component: Core (Management commands) Version: 4.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When running python manage.py runserver on macOS, a decently sized project takes about 1 second to startup and respond to requests (based on the first access log I can see).

However, when running python manage.py runserver 0.0.0.0:8000, the server will appear to have started, but will only start responding to requests 7/8 seconds later.

I've been able to consistently reproduce the bug on a freshly installed project aswell (django-admin startproject timings_test) :

  • On 127.0.0.1:8000, the app will start in (08:42:11 - 08:42:11) less than a second
  • On 0.0.0.0:8000, the app will start in (08:42:32 - 08:42:26) approximately 6 seconds
bash-3.2$ cd $(mktemp -d)
bash-3.2$ django-admin startproject timings_test
bash-3.2$ cd timings_test/
bash-3.2$ # I'll now refresh my web browser, pay close attention to the timings
bash-3.2$ python3 manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
March 28, 2023 - 08:42:11
Django version 4.1.7, using settings 'timings_test.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Not Found: /__reload__/events/
[28/Mar/2023 08:42:11] "GET /__reload__/events/ HTTP/1.1" 404 2137
[28/Mar/2023 08:42:12] "GET / HTTP/1.1" 200 10681
[28/Mar/2023 08:42:12] "GET /static/admin/css/fonts.css HTTP/1.1" 304 0
[28/Mar/2023 08:42:12] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 304 0
[28/Mar/2023 08:42:12] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 304 0
[28/Mar/2023 08:42:12] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 304 0
Not Found: /favicon.ico
[28/Mar/2023 08:42:12] "GET /favicon.ico HTTP/1.1" 404 2116
[28/Mar/2023 08:42:12,122] - Broken pipe from ('127.0.0.1', 54544)
[28/Mar/2023 08:42:12] "GET / HTTP/1.1" 200 10681
Not Found: /__reload__/events/
[28/Mar/2023 08:42:14] "GET /__reload__/events/ HTTP/1.1" 404 2137
Not Found: /__reload__/events/
[28/Mar/2023 08:42:17] "GET /__reload__/events/ HTTP/1.1" 404 2137
^Cbash-3.2$ python3 manage.py runserver 0.0.0.0:8000
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
March 28, 2023 - 08:42:26
Django version 4.1.7, using settings 'timings_test.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
[28/Mar/2023 08:42:32] "GET / HTTP/1.1" 200 10681
Not Found: /__reload__/events/
[28/Mar/2023 08:42:32] "GET /__reload__/events/ HTTP/1.1" 404 2137
Not Found: /__reload__/events/

Change History (4)

comment:1 by Arthur, 21 months ago

I've found traces of this bug from 2020 here.

What I've tried so far :

  • Adding -X importime to the startup command : the imports mostly finish in under a second, before You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. gets printed to the console.

Just before the request gets processed, you'll see the following lines :

import time:       245 |        245 |   stringprep
import time:       435 |        680 | encodings.idna
import time:       520 |        520 | django.contrib.messages.storage.cookie
import time:       241 |        241 | django.contrib.messages.storage.session
[28/Mar/2023 08:47:55] "GET / HTTP/1.1" 200 10681
  • Running cProfile : couldn't find the right incantation to make it accept arguments.
  • Pause the program in PyCharm debugger after Quit the server with CONTROL-C. gets printed : only stops in StatReloader.tick(), so it's probably a threading issue (?)
  • Searching for issues here : nothing found about this.

comment:2 by Mariusz Felisiak, 21 months ago

Component: UncategorizedCore (Management commands)
Resolution: needsinfo
Status: newclosed

Hi, I don't think you've explained the issue in enough detail to confirm a bug in Django. Please reopen the ticket if you can debug your issue and provide details about why and where Django is at fault. This looks like an issue in your local OS/network configuration, not Django itself.

comment:3 by Arthur, 21 months ago

Resolution: needsinfo
Status: closednew

Hi, I doubt it is my OS fault :

  • I'm not the only one with the bug (as can be seen here)
  • The flask example app started with flask --app hello run --host 0.0.0.0 --port 8000 will respond in less than a second, so I cannot reproduce the bug with something that's "not django".

I am currently attempting to bisect the bug, but I'd need a failing test first.

comment:4 by Mariusz Felisiak, 21 months ago

Resolution: needsinfo
Status: newclosed

So ... "Please reopen the ticket if you can debug your issue and provide details about why and where Django is at fault.". Also, I cannot reproduce this behavior on Linux.

Note: See TracTickets for help on using tickets.
Back to Top