Friday 25 October 2013

Get your year's worth of free EverNote Premium

Evernote Partners with UK Mobile Carrier O2 Evernote Blog:

'via Blog this'

Saturday 19 October 2013

Fixing slow performance on mod_wsgi

I've just spent a couple of hours investigating why one of my sites has been responding so slowly, to the point where the monitoring software would report that the site was down - after a bit of reading and racking my memory I realised that in the past I had limited the number of threads and processes WSGI could use to serve the site.

I'm using Flask and mod_wsgi on Webfaction and so my config was under:
~/webapps/[app_name]/apache/conf/httpd.conf
In my effort to save memory, back when WebFaction only offered 256MB of RAM, I'd gone through my sites and set the threads and processes to "2" for the wsgi process:
WSGIDaemonProcess app_name processes=2 python-path=... threads=2
I'd also set MaxSpareThreads 2 (down from the default 3) and ThreadsPerChild 2.

After checking performance with serverstatus and checking memory usage with this script, I settled on
MaxSpareThreads 3
MinSpareThreads 1
ServerLimit 1
ThreadsPerChild 16
WSGIDaemonProcess ... processes=8 threads=16
Which took my response time down from around 15 seconds (which even with 2 threads and processes seems slow) to around 2 seconds from cold and well under a second when warm (the second check after restarting apache).  Much better!

Memory usage seems to be around 22MB per process, but with 512MB of RAM to play with, there's plenty of headroom.

Thursday 17 October 2013

Moving to Bootstrap v3 and a CDN

I've just spent the evening changing jQuery and Twitter Bootstrap from locally hosted assets to be pulled down from Google's Content Delivery Network.

This is something I should have done much earlier, but I never did - my brain would say "what if the CDN goes down - that would make my site look bad".  I've only just realised how ridiculous that sounds; if Google's network goes down, the internet's got bigger problems than my site looking odd.

So, after a bit of research, I chose Google's CDN over JQuery's own as users are more likely to have the Google version in their cache.  Sadly Google don't yet have Bootstrap available, so be sure to star this bug to make it happen, so I chose bootstrapcdn.com to host my bootstrap CSS and Javascript.

That was all very easy and straightforward, and the latest version of JQuery worked absolutely fine... Bootstrap however has been upgraded to v3, which the CDN gives you by default, so rather than finding out how to get the v2 branch, I thought I "may as well" upgrade.  Turns out, they've changed quite a lot of things.

2 hours later, and with a massive thanks to the Bootstrap 3 upgrade service everything looks and works more-or-less how it did before I started, and my sites should be a fraction quicker too.

If you're not convinced, check out this article for 3 good reasons to move to a CDN