Nginx / uWsgi / Django site can handle more traffic with rewrite URL
Posted
by
Ludo
on Server Fault
See other posts from Server Fault
or by Ludo
Published on 2010-12-08T10:02:13Z
Indexed on
2011/01/13
22:55 UTC
Read the original article
Hit count: 432
Hi there.
I'm running a Django app, using uWsgi behind Nginx. I've been doing some performance tuning and load testing using ApacheBench and have discovered something unexpected which I wonder if someone could explain for me. In my Nginx config I have a rewrite directive which catches lots of different URL permutations and then forwards them to the canonical URL I wish to use, eg, it traps www.mysite.com/whatever, www.mysite.co.uk/whatever and forwards them all to http://mysite.com/whatever.
If I load test against any of the URLs listed with a redirect (ie, NOT the canonical URL which it is eventually forwarded to), it can serve 15000 concurrent connections without breaking a sweat.
If I load test against the canonical URL, which the above test I would have expected got forwarded to anyway, it can't handle nearly as much. It will drop about 4000 of the 15000 requests, and can only handle about 9000 reliably.
This is the command line I'm using to test:
ab -c15000 -n15000 http://www.mysite.com/somepath/
and
ab -c15000 -n15000 http://mysite.com/somepath/
I've tried several different types - it makes no different which order I do them in. This doesn't make sense to me - I can understand why the requests involving a redirect may not handle quite so many concurrent connections, but it's happening the other way round. Can anyone explain? I'd really prefer it if the canonical URL was the one which could handle more traffic.
I'll post my Nginx config below.
Thanks loads for any help!
server {
server_name www.somesite.com somesite.net www.somesite.net somesite.co.uk www.somesite.co.uk;
rewrite ^(.*) http://somesite.com$1 permanent;
}
server {
root /home/django/domains/somesite.com/live/somesite/;
server_name somesite.com somesite-live.myserver.somesite.com;
access_log /home/django/domains/somesite.com/live/log/nginx.log;
location / {
uwsgi_pass unix:////tmp/somesite-live.sock;
include uwsgi_params;
}
location /media {
try_files $uri $uri/ /index.html;
}
location /site_media {
try_files $uri $uri/ /index.html;
}
location = /favicon.ico {
empty_gif;
}
}
© Server Fault or respective owner