Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Aren't Django Static Generator & Nginx Giving Me Boss Speed?

Tags:

nginx

django

So there have been lots of articles like this one recently, extolling the virtues of Django Static Generator when used in combination with a light front-end Web server. It makes a whole lot of sense to me.

However, I get nothing like the results that other people are reporting -- thousands of requests per second -- and I don't know why that is.

I'm getting ready to launch a redesign of my newspaper's Web site. I've got it using Static Generator on a test server right now. And when I run Apache Bench on a particular static page, I get pretty miserable results:

ab -c 10 -n 1000 http://journal.streamlister.com/news/

Concurrency Level:      10
Time taken for tests:   53.011 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      21281212 bytes
HTML transferred:       21067360 bytes
Requests per second:    18.86 [#/sec] (mean)
Time per request:       530.107 [ms] (mean)
Time per request:       53.011 [ms] (mean, across all concurrent requests)
Transfer rate:          392.04 [Kbytes/sec] received

I'm watching top on the server while the siege is on, and I can see that it's not hitting Apache or the database server at all. So it is, in fact, serving the cached page. Nginx is running, but it never gets above 2% memory usage. CPU remains about 95 percent idle.

What am I doing wrong? Could I have misconfigured nginx somehow? My main config file is pasted below; the include specific to this site is pretty much a carbon copy of the sample config on the Static Generator home page. I'm running Ubuntu 9.10 on a Slicehost 256k slice.

user not_my_real_username;
worker_processes  4;
error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;
events {
    worker_connections  8192;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    access_log  /var/log/nginx/access.log;
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  0;
    #keepalive_timeout  65;
    tcp_nodelay        on;
    gzip  on;
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}
like image 683
hanksims Avatar asked Jan 18 '10 07:01

hanksims


People also ask

Is Django a static site generator?

django-distill is a simple to implement static site generator for Django. It is fully compatible with all Django projects and works with existing complex Django applications without interfering. It does not require modifications to existing apps and only small per-URL functions need to be created.

Is Django good for static website?

While Django is a great framework for building websites and web applications, it's often considered as “too big” for fulfilling simple needs, such as mostly static content or single-page sites.

Why do we use load static in Django?

{% load static %} tells django to load a set of template tags/filters defined in the file static.py (in a folder templatetags in any of the apps of your project). The same way you can define your own tags, put them in a file util_tags.py and load them with {% load util_tags %} .

How Django manages the heavy load?

Django closes the connection by default at the end of each request and persistent connections avoid overloading the database for each request. These connections are controlled by the CONN_MAX_AGE param, a metric that defines the maximum lifetime of a connection.


2 Answers

I'm not an expert in this case. But if CPU is idle and also Memory isn't the bottleneck then the harddrive comes to my mind. Maybe its very slow and the bad speed is a hint of a broken harddisk.

You should run some simple benchmarks.

like image 182
Gregor Müllegger Avatar answered Oct 03 '22 15:10

Gregor Müllegger


Where are you doing the test from? Another server in the same datacenter, or your home/work internet connection? It's going to be hard to reliably test the performance of your site from your home connection. For one, you internet connection may be too slow, and secondly, many personal routers can't handle that many concurrent connections.

Also... try running the benchmark without the images.

like image 35
Justin Avatar answered Oct 03 '22 13:10

Justin