PHP is a programming language for web applications but Django is a full-fledged framework that provides database abstraction, caching, authentication and a host of other services. Comparing the performance of the two is not a fair, apples to apples comparison. However I want to do it in order to better decide what I should use for an application.
I created a light-weight HTML page, a “hello world” php app (no db or sessions) and a light weight “hello world” django app using mostly default values (sessions are enabled). I then ran the apache benchmark (ab) on the three using a small VPS w/ 512 MB of RAM from localhost (so no latency is involved giving ideal conditions).
Apache is configured with a max clients of 40 so I tested with a concurrency of 40.
- Static HTML:
Requests per second: 3249.36 [#/sec] (mean)
(no measurable impact on server load) - PHP:
Requests per second: 2786.73 [#/sec] (mean)
(no measurable impact on server load) - Django:
Requests per second: 157.97 [#/sec] (mean)
(no measurable impact on server load) - Static HTML using SSL:
Requests per second: 10.30 [#/sec] (mean)
(during this, server load rose uncomfortably high)
What do we understand from this? First, considering the added functionality of the Django framework, I’m quite comfortable with the performance here. If I need as lean of an app as possible, I may want to consider not using a framework. Carefully crafted PHP is probably going to be faster.
However, with a concurrency of 40 the Django app was able to support 157 connections per second. The server load and memory utilization indicates that this VPS can probably handle a higher value for max-clients.
I’m quite shocked at the poor SSL performance. I have no idea why the VPS would perform so poorly. I wonder if the VPS technology forces the server to offload SSL decryption to a virtual network adapter. The CPU of the VPS is an Intel Core 2 Quad @ 2.4GHz.
This is an OpenVZ VPS running Ubuntu 10.04 LTS, Apache 2.2.14, PHP 5.3.2, Django 1.2.3 on Python 2.6.5 using mod_wsgi 2.8.
You can get a good deal on a VPS at burst.net for $5.99/mo (this link uses my “refer a friend” feature so I get credit). I’m extremely happy with the quality of their service and have had 0 downtime in the few months I’ve been a customer.