Apr 2 2009

Django on Joyent

So unlike Rails deploying on Django on Joyent with default configs pretty much just sucks.  I’ve found if I just push stuff up the server hangs up, core dumps, basically it’s just a really awful experience.  Others I know have had the same problems so I thought I post what I’ve found. If you know of  anything else to make things kick please comment and I’ll add to the post.

Doing the below took me from 1 request a second and regular core dumps to about 15 request per second on a 256 meg accelerator. Satisfactory for a $200 a year host.

The worker mpm isn’t compiled in so you have to use prefork ( SUCK! ). If do something like use <IfModuel worker.c> instead of just working with what you’ve got or don’t modify the mpm.conf joyent set up for you you’ll get the default values which will totally hose your server. You can’t even serve static sites with their defaults without swapping.  Also tweek these values to your needs, the App this is for eats alot of RAM, has 15 modules and 60+ classes. You could prolly get away with 5 -10 on ServerLimit and MaxClients just have to watch prtstat -Z and /root/bin/jinfo -m while running ab tests and tune to your needs.

<IfModule prefork.c>
StartServers 4
MinSpareServers 2
MaxSpareServers 2
ServerLimit 5
MaxClients 5
MaxRequestsPerChild 0
ListenBacklog 100
</IfModule>

### deflate.conf

# this is defaulted to 9 which is stupid. Lets not spend 50ms compressing output
DeflateCompressionLevel 5

### Kill these processes. Webmin is for losers who should stick to windows or go back to kindergarden and the other two are imap processes that are just creating a security vulnerability and eating resources why any of them are enabled by default is beyond me.

svcadm disable imap
svcadm disable webmin
svcadm disable authlib

### settings.py

DEBUG = False
TEMPLATE_DEBUG = False

# I’m only working in english for this site
USE_I18N = False

# if you have gzip middleware in place get rid of it. ( this really makes a difference ) mod_deflate is already in place so you’re trying to gzip a gzipped stream… ( if you core dumping apache this is probably why ) C is faster than python by and order of magnitude so lets  just use mod_deflate.

‘django.middleware.gzip.GZipMiddleware’, # delete this

# Template context processors

these should go bye bye

“django.core.context_processors.debug”,
“django.core.context_processors.i18n”,
“django.core.context_processors.media”,

## listenIPs.conf
## virtualHost IP’s

#replace * with the actual IP address also do this if you have virtualhosts… so the vhost is isn’t listening on *:80

Listen 0.0.0.0:80
Listen 0.0.0.0:443

## Stuff you prolly already do anyway as it’s pretty standard. Cause we don’t want django handling requests for static files

# actually if you can put your images, css, and js in a separate virtualhost all together you’ll prolly get even better performance.

<!Location “/static”>

SetHandler None

</Location>

<!Location “/media”>

SetHandler None

</Location>

<LocationMatch “\.(jpg|gif|png|css|swf|doc|js|pdf)$”>

SetHandler None

</LocationMatch>

## expires.conf

# add png, css, js, jpg, etc… to expires.conf the access plus value is up to you … more stable the site longer it should be
# this won’t help an ab score but it sure helps the end user

ExpiresByType application/x-javascript “access plus 10 days”
ExpiresByType image/png “access plus 10 days”
ExpiresByType image/jpeg “access plus 10 days”
ExpiresByType text/css “access plus 10 days”
ExpiresByType application/x-shockwave-flash “access plus 10 days