[Fixed]-Django is very slow on my machine

19đź‘Ť

âś…

Firefox has a problem browsing to localhost on some Windows machines. You can solve it by switching off ipv6, which isn’t really recommended. Using 127.0.0.1 directly is another way round the problem.

👤fuzzyman

9đź‘Ť

None of these posts helped me. In my specific case, Justin Carmony gave me the answer.

Problem

I was mapping [hostname].local to 127.0.0.1 in my /etc/hosts file for easy development purposes and dns requests were taking 5 seconds at to resolve. Sometimes they would resolve quickly, other times they wouldn’t.

Solution

Apple is using .local to do some bonjour magic on newer Snow Leopard builds (I think i started noticing it after updating to 10.6.8) and Mac OS X Lion. If you change your dev hostname to start with local instead of end with local you should be all set. Additionally, you can pretty much use any TLD besides local and it will work without conflict.

Example

test.local could become:

  • local.test.com
  • test.dev
  • test.[anything but local]

and your hosts file entry would read:

local.test.com  127.0.0.1

Note: This solution has the added benefit of being a subdomain of [hostname].com which makes it easier to specify an app domain name for Facebook APIs, etc.

Might also want to run dscacheutil -flushcache in the terminal for good measure after you update /etc/hosts

👤Tyler Brock

4đź‘Ť

I have had the same problem in the past. It can be solved by removing the following line from your hosts file.

::1         localhost

Once that’s gone you should be able to use localhost again, quickly.

👤Ty.

3đź‘Ť

Since you report your friend’s machine has no delays, and I assume yours and his are comparable computers, it could be a DNS related issue. Try to add both the client’s and the server’s IP address to the server’s hosts file.

If you run Django on *nix, it’s the /etc/hosts file. If run it on MS Windows, it’s the %WINDIR%\SYSTEM32\DRIVERS\ETC\HOSTS file. (They are text files and can be edited by your favourite text editor.)

👤tzot

2đź‘Ť

I think it’s the development server, it’s not optimized for speed nor security. I noticed that specially serving static files (i.e. media) is slow.

👤hasen

2đź‘Ť

And if all else fails, you can always cProfile your application and see where exactly is the bottleneck.

👤klozovin

2đź‘Ť

Had the same problem too, I’ve noticed it with Firefox on Vista and Windows 7 machines. Accessing the development server 127.0.0.1:8000 solved the problem.

👤Dylan Bauer

2đź‘Ť

Upgrade to Django 1.3 or newer.

If you still have this problem in 2012 (using Chrome), make sure you’re upgrading. In 1.3, a bug was fixed related to slowness when the dev server was single threaded.

Upgrading solved my issues. I was running Django 1.2 since that’s the default on Debian Squeeze.

1đź‘Ť

I had the same problem but it was caused by mysqld.

The app worked pretty fast on production with wsgi and a mysql server in the same host but slow in the development environtment with the django runserver option and a remote mysql server.

I noticed using “show processlist” that connections in database where stuck in the state “login” with user “unauthenticated user” and this make me notice that the problem where in the authentication process.

Looking for the real problem, I finally noticed that mysqld was trying to get the dns name of my ip and disabling the name dns resolution, I fixed the problem.

To do that, you can add this line into my.cnf file:

skip-name-resolve

1đź‘Ť

I solved this issue like this:

go to setting.py and set

DEBUG = False

0đź‘Ť

Disable AV Scanning & see if that makes a difference. It could also be caused by Vista. Upgrade to the latest service pack and try again.

👤seanyboy

0đź‘Ť

To completely bypass localhost without altering the hosts file or any settings in Firefox you can install the addon Redirector and make a rule to redirect from localhost to 127.0.0.1. Use these settings

Include pattern : http://localhost*
Redirect to     : http://127.0.0.1$1

Leave the other fields empty.

👤westmark

0đź‘Ť

i got the same problem.

the solution was :

  • I was trying to start localy a version that was usualy deployed on a webserver in production.
  • The static files in production were served by an apache config and not with django static serve

so I just uncommented back my static serve urls :/

0đź‘Ť

Slow Loading of Static Files

If you notice that static and media files (images, style sheets, etc.) are particularly slow to load, the problem might be Django’s development server (python manage.py runserver). As noted by hassen, that server is not optimized for speed.

You can try using django-extensions runserver_plus command with the --threaded option as a replacement for Django’s runserver command. Under the hood, it uses Werkzeug as the threaded WSGI server. You may notice a huge improvement in loading times for static files.

Also see: Making Django development server faster at serving static media

👤Flux

0đź‘Ť

For me it was Django Debug Toolbar – its amazingly helpful when its needed but when it isn’t it can slow development down which can be extremely frustrating and hard to identify. I find its better to disable it during development unless you need it. :zombies-never-die:

👤Sammy J

Leave a comment