views:

383

answers:

6

I'm playing around with Django on my website hosting service.

I found out that a simple Django page, which has only some static text, and is rendered from a very simple template I created takes a significant time to render. When compared to a static HTML page, I am getting ~2 seconds difference in the load times. Keep in mind this is a simple test of mine with nothing complicated. Also note that my web hosting is on a shared server (not dedicated), so I might be hitting some CPU limitations.

Seems to me that either:

  1. I have some basic CGI/Apache/Django configuration wrong
  2. Django takes significant overhead, at least in this specific scenario.

I find #1 not probable since I followed my web hosting service wiki on how to set up Django. So we are left with the overhead problem.

My question is which web framework do you find the best to use in scenarios where the website is hosted on a shared server, and CPU/memory overhead must be kept to minimum?


Edit: seems that my configuration is something I might want to look at, and perhaps later on I'll be opening a question on how to best configure Django.

For now, I would appreciate answers focusing on your experience, in general, with web frameworks, and which of those you found to be the best in terms of performance in the aforementioned scenario.

A: 

It's possibly both. Django does have stuff for caching built-in, which would be worth trying. Regardless, any non-cached page will nearly always take longer than a static file. A file has to be read in both cases, and in the case of a dynamic page, it also must be executed. And then, in both cases, sent over to the client.

Devin Jeanpierre
+4  A: 

"I have some basic CGI/Apache/Django configuration wrong"

Correct.

First. The very first time Django returns a page, it takes forever. A lot of initialization happens for the first request.

Second. What specific configuration are you using. We just switched from mod_python to mod_wsgi in daemon mode and are very happy with the performance changes.

Third. What database are you using?

Fourth. What test configuration are you using?

Fifth. What caching parameters and reverse proxy are you using?

Odds are good that you have a lot of degrees of freedom in your configuration.


Edit

The question "which of those you found to be the best in terms of performance" is largely impossible to answer.

See http://wiki.python.org/moin/WebFrameworks

There are dozens of frameworks. Few people can examine more than a few to do head-to-head comparison.

The best possible performance is achieved through static content. A Python app that makes static pages (for instance a collection of Jinja templates) is fastest.

After that, it's largely impossible to say. Even http://werkzeug.pocoo.org/ involves some processing overheads that may be unacceptable in the above scenario. Python can be slow.

Django, with a modicum of effort, is often fast enough. Serving static content separately from dynamic content, for example, can be a huge speedup.

Since Django does so much automatically, there's a huge victory in not having to write every little administrative page.

S.Lott
+1  A: 

I'd say there has to be something funky with your setup there to get such a large performance difference. Try mod_wsgi (if you're not already) and follow the excellent suggestions by the posters above. If Django genuinely was this slow in all cases, there's just no way companies would be able to use it for production applications. It's more than likely not to be Django that is holding the request up. Once you have the .pyc files all sorted (automatically generated bytecode), then the execution should be fairly zippy.

However, if you don't actually need all Django has to offer, then why use it? I'm using it in quite a large production application, and we're not using all of its features… if you're doing something fairly simple, you may want to consider using something like web.py or Werkzeug (or something non-Python-based if you'd rather).

obeattie
+1  A: 

Frameworks like Django or Ruby on Rails grew out of real world needs. As different as these needs were, as different they turned out.

Here is my Experience: As a former PHP programmer, I prefered CakePHP for simple stuff and Symfony for more advanced applications. I had a look into Ruby, but the documentation sucked back then. Now I'm using Django. Django works very well for me. In contrast to Symfony I feel like Django brings less flexibility out of the Box, but its easier to extend.

Another approach would be to use 'no framework' CherryPy

Andre Bossard
A: 

Definetely shared hosting is not the best choice to run heavy frameworks such as Django or CakePHP. If you can afford it, buy VPS.

As for performance, probably your host uses Python with mod-python, which is not recommended now. WSGI is preferred standard for Python powered webapps.

Sergei
+1  A: 

I think the host may be an issue. I do Django development on my localhost (Mac) and it's way better. I like WebFaction for cheap hosting and Amazon ec2 for premium hosting.

The framework is strong and it can handle heavy sites - don't obsess about that stuff. The important thing is to create a clean product, Django can handle it. There are about a thousand steps to take when you see how the application handles in the wild, but for now, just trust us that you don't need to worry about the inherent speed of the framework before exhausting a whole slew of parameters including a dedicated VPS/instance when you need it.

Also, following on your edit - I personally don't think performance is a major issue in programming. Here are the issues in terms of concern:

  1. UI/UX efficiency
  2. UI/UX speed (application caching)
  3. Well designed models/views
  4. Optimization of the system (n-tier architecture, etc...)
  5. Optimization of the process (good QA to reduce failures/bottlenecks from deployment)
  6. Optimization of the subsystems (database, etc...)
  7. Hardware
  8. Framework internal optimization

Don't waste time with comparing framework speeds. Their advantage is in extensible code, smart architectures, etc...

On a side note, DO NOT NOT USE A FRAMEWORK FOR A NEW WEB APPLICATION. I'm sorry I can't say it loud enough, but it's an absolute requirement nowadays. It's not even a debate about not using one, just which one to use.

I personally chose Django, which is great. But I can't definitively knock the others out there.

Adam Nelson