mod_wsgi Problems Continued

The last deployment of the mod_wsgi version of the site failed again. This time I finally learnt the lesson and went to the bother of setting up a better test environment. Rather than simply using my Mac OS X laptop to test prior to deployment on Debian I am now testing on Debian too. I’m also making liberal use of Apache benchmark to at least do some basic testing under load.

The first problem I had was that I was ending up with an enormous number of database connections again which eventually crashed out. This turned out to be a problem with my code, I am now just using a global variable to store the MySQL connection object which seems to be working fine.

The second problem was that the server failed around half the time under load with simultaneous connections. No error messages that I could find were generated. This took about half a day to track down and eventually I found out that the problem was actually down to Python 2.4’s randint method from the random standard library. This was quite a surprise but when I Googled it turned out that other people have had similar problems.

In my case I was just trying to generate a random number so that I could choose between one of three adverts to display so I’m now just doing datetime.time().second % 3 which is absolutely fine under load and I don’t really care that it isn’t very random.

The performance numbers I’m now seeing from Apache benchmark are now in line with the numbers that Plenty of Fish have published although I’m very aware that there’s a huge difference between performance under test conditions and in real life.

Fingers crossed that the deployment tomorrow am goes to plan!

Leave a Reply

You must be logged in to post a comment.