Mod-Wsgi or Mod-Python?

Mon 25 February 2008 by Thejaswi Puthraya

Mod_WSGI or Mod_Python?

Recently, I had the opportunity of deploying django apps that would receive heavy traffic and yet be lite on the memory because I was using a 256 MB virtual private server.

Django has two options:

I have had bad experiences with Mod_Python with issues ranging from memory leaks to difficult configuration. Off late there has been lots of talk about Mod_Wsgi and it's performance.

I decided to do a benchmark test to figure out the truth. For the benchmark test I used Apache 2.2.8 with prefork MPM. I used apache's inbuilt benchamark analyzer ab for the test. The single media file that was being served was a single SWF file with a size of 350KB. The multiple media files being images from a gallery app. Here are the results of a 1000 non-concurrent requests being served:

Mod-Python serving media

Single media file

Total transferred:      4515000 bytes
HTML transferred:       4335000 bytes
Requests per second:    140.90 [#/sec] (mean)
Time per request:       7.097 [ms] (mean)
Time per request:       7.097 [ms] (mean, across all concurrent requests)
Transfer rate:          621.21 [Kbytes/sec] received

Multiple media files

Total transferred:      6789000 bytes
HTML transferred:       6595000 bytes
Requests per second:    10.95 [#/sec] (mean)
Time per request:       91.294 [ms] (mean)
Time per request:       91.294 [ms] (mean, across all concurrent requests)
Transfer rate:          72.61 [Kbytes/sec] received

Mod-WSGI serving media

Single media file

Total transferred:      4513000 bytes
HTML transferred:       4335000 bytes
Requests per second:    158.71 [#/sec] (mean)
Time per request:       6.301 [ms] (mean)
Time per request:       6.301 [ms] (mean, across all concurrent requests)
Transfer rate:          699.43 [Kbytes/sec] received

Multiple media files

Total transferred:      6787000 bytes
HTML transferred:       6595000 bytes
Requests per second:    11.05 [#/sec] (mean)
Time per request:       90.487 [ms] (mean)
Time per request:       90.487 [ms] (mean, across all concurrent requests)
Transfer rate:          73.24 [Kbytes/sec] received

Mod-Python with Apache serving media

Single media file

Total transferred:      4515000 bytes
HTML transferred:       4335000 bytes
Requests per second:    141.61 [#/sec] (mean)
Time per request:       7.061 [ms] (mean)
Time per request:       7.061 [ms] (mean, across all concurrent requests)
Transfer rate:          624.37 [Kbytes/sec] received

Multiple media files

Total transferred:      6789000 bytes
HTML transferred:       6595000 bytes
Requests per second:    10.93 [#/sec] (mean)
Time per request:       91.470 [ms] (mean)
Time per request:       91.470 [ms] (mean, across all concurrent requests)
Transfer rate:          72.47 [Kbytes/sec] received

Mod-WSGI with Apache serving media

Single media file

Total transferred:      4513000 bytes
HTML transferred:       4335000 bytes
Requests per second:    159.35 [#/sec] (mean)
Time per request:       6.275 [ms] (mean)
Time per request:       6.275 [ms] (mean, across all concurrent requests)
Transfer rate:          702.27 [Kbytes/sec] received

Multiple media files

Total transferred:      6787000 bytes
HTML transferred:       6595000 bytes
Requests per second:    11.12 [#/sec] (mean)
Time per request:       89.922 [ms] (mean)
Time per request:       89.922 [ms] (mean, across all concurrent requests)
Transfer rate:          73.70 [Kbytes/sec] received

Mod-WSGI with Nginx serving media

Single media file

Total transferred:      4472000 bytes
HTML transferred:       4335000 bytes
Requests per second:    344.56 [#/sec] (mean)
Time per request:       2.902 [ms] (mean)
Time per request:       2.902 [ms] (mean, across all concurrent requests)
Transfer rate:          1504.68 [Kbytes/sec] received

Multiple media files

Total transferred:      6746000 bytes
HTML transferred:       6595000 bytes
Requests per second:    28.77 [#/sec] (mean)
Time per request:       34.760 [ms] (mean)
Time per request:       34.760 [ms] (mean, across all concurrent requests)
Transfer rate:          189.50 [Kbytes/sec] received

Conclusion

Mod-WSGI gives a 12.5% improvement in performance while serving a single media file while it gives a mere 1% improvement while serving multiple media files. Not much change is seen while apache is made to serve the media, the figures show a small performance improvement. When Nginx comes into the picture it blows away apache to bits. It gives a 116% improvement while serving a single media file and 160% improvement while serving multiple media files. Use Nginx to serve static media (and for reverse proxying) and notice the performance difference.