Slow Django dev server reload

2,609 views
Skip to first unread message

Krishna Bharadwaj

unread,
Jul 3, 2016, 10:20:40 AM7/3/16
to Django users
Hi everyone,

I am working on a project which is substantially big (~40k lines of python/django code including management commands). Dev server seems to be taking a lot of time to reload after making changes. I was wondering if this is due to any bad programming practice at my end? Or is this expected once the project grows big? I wanted to know if anyone in the group is dealing with it in a better way? 

- Regards
Krishna Bharadwaj

Fred Stluka

unread,
Jul 3, 2016, 11:17:50 AM7/3/16
to django...@googlegroups.com
Krishna,

How long is "a long time"?  I have a project of ~200K lines of
python/django code.  The dev server reloads in a second or so.

--Fred

Fred Stluka -- mailto:fr...@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

--
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/a97cacc1-c8c8-4075-a853-5f5d1bb156d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Krishna Bharadwaj

unread,
Jul 4, 2016, 2:20:42 AM7/4/16
to Django users
Hi Fred,

It takes about 3.5 - 5 seconds on my machine (Mac OSX - 2.6 GHz Intel Core i5, 8 GB 1600 MHz DDR3 and SSDs). I was curious to know if I was doing something wrong. Any pointers regarding this will be very helpful.


On Sunday, 3 July 2016 20:47:50 UTC+5:30, Fred Stluka wrote:
Krishna,

How long is "a long time"?  I have a project of ~200K lines of
python/django code.  The dev server reloads in a second or so.

Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

Babatunde Akinyanmi

unread,
Jul 4, 2016, 3:14:40 AM7/4/16
to Django users

This is a punch in the dark. It takes about 3 -  5 seconds on my my windows machine when I run the dev server using pycharm's inbuilt terminal and my code is way below 5k lines

Hildeberto Mendonça

unread,
Jul 4, 2016, 3:47:00 AM7/4/16
to django...@googlegroups.com
Isn't it related to the amount of migration files in your project?


For more options, visit https://groups.google.com/d/optout.



--
Hildeberto Mendonça, Ph.D
Blog: http://www.hildeberto.com
Twitter: https://twitter.com/htmfilho

Vijay Khemlani

unread,
Jul 4, 2016, 9:46:03 AM7/4/16
to django...@googlegroups.com
How many models are there in your project?

Fred Stluka

unread,
Jul 4, 2016, 3:33:52 PM7/4/16
to django...@googlegroups.com
Hildeberto,

No, the number of migrations does affect how long it takes to
run automated tests, but should not affect how long it takes
the dev server to start.

Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

Fred Stluka

unread,
Jul 4, 2016, 4:20:26 PM7/4/16
to django...@googlegroups.com
Krishna,

I'm using:
- Mac OSX 10.11.5 (El Capitan)
- 2.3GHz Intel Core i7
- 16 GB 1333 MHz DDR3
- 512GB SSD
- Python 2.7.3
- Django 1.4.2
- MySQL 5.1.33

And it takes less than a second from when I type:
    % python manage.py runserver
until I see:

Validating models...

0 errors found
Django version 1.4.2, using settings 'hhl.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

I have about 40 models.py files, of which 25 are empty and
exist only to prevent warnings when run automated tests.
The other 15 contain about 100 Django models with a total
of about 27,000 lines of code.

The 100 models all get validated against a locally running
MySQL server.

So, it should NOT be that slow on your Mac.

To narrow down the problem, I suggest you use the -v option:
    % python -v manage.py runserver
and watch to see what seems to be taking so long.

Any other suggestions, anyone?

Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

Vijay Khemlani

unread,
Jul 4, 2016, 4:51:30 PM7/4/16
to django...@googlegroups.com
Why... are you answering questions directed to Krishna? You are not the one with the slow loading server.

Krishna Bharadwaj

unread,
Jul 5, 2016, 2:00:39 PM7/5/16
to Django users
Hi Fred,

Thanks for providing your project as a reference and also the python verbose tip. I just started my dev server with the -v option to see how many import statements are fired. grep '^import ' returned about 1500 lines in the output (about 75 models with about 40k lines of code). I could not narrow down the problem to any specific import / module. Curious to know how many imports were fired in your case?


On Tuesday, 5 July 2016 01:50:26 UTC+5:30, Fred Stluka wrote:
Krishna,

--Fred

Krishna Bharadwaj

unread,
Jul 5, 2016, 2:01:32 PM7/5/16
to Django users
Vijay, about 75 as mentioned in the other post answer.

Fred Stluka

unread,
Jul 5, 2016, 6:52:29 PM7/5/16
to django...@googlegroups.com
Krishna,

Only a third of your count -- 551

% tcsh
  % python -v manage.py runserver >&! ~/1.1
  % grep -E "^import" ~/1.1 | wc -l
     551

So, you didn't see any noticeable pauses as the -v output was
streaming to the terminal window?  Sounds like it's just doing a
lot of work, not stalling out anywhere in particular.

Why so many imports?  Seems odd that I have more models,
but fewer lines of code, and far fewer imports.  Are all of your
imports still needed?  Or are many of them obsolete and could
be deleted?  We tend to get rid of our dead ones pretty quickly
because PyCharm shows them as grey when they're not needed.

Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

Krishna Bharadwaj

unread,
Jul 11, 2016, 1:00:04 AM7/11/16
to Django users
Fred,

That's very good to know. At least it tells me that the number of imports could be one of the main reasons for the slow down. And I apologise for the delay in responding. I am not certain why the number is so high in my case. I will take a closer look at it and share what I find out later. I would like to thank you again for offering some insights and a reference so that I could work on improving my codebase.


On Wednesday, 6 July 2016 04:22:29 UTC+5:30, Fred Stluka wrote:
Krishna,

Only a third of your count -- 551

% tcsh
  % python -v manage.py runserver >&! ~/1.1
  % grep -E "^import" ~/1.1 | wc -l
     551

So, you didn't see any noticeable pauses as the -v output was
streaming to the terminal window?  Sounds like it's just doing a
lot of work, not stalling out anywhere in particular.

Why so many imports?  Seems odd that I have more models,
but fewer lines of code, and far fewer imports.  Are all of your
imports still needed?  Or are many of them obsolete and could
be deleted?  We tend to get rid of our dead ones pretty quickly
because PyCharm shows them as grey when they're not needed.

--Fred

ludovic coues

unread,
Jul 11, 2016, 11:21:53 AM7/11/16
to django...@googlegroups.com
Any chance the big time difference come from the difference between
SSD and mechanical drive ?
> https://groups.google.com/d/msgid/django-users/821ff861-f4e0-4b41-977f-b0c08bb5d825%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42
Reply all
Reply to author
Forward
0 new messages