We have a web service that serves small arbitrary segments of a fixed inventory of large MP3 files. MP3 applications are generated on the fly by the python application. Model, make a GET request to a URL that identifies which segments you want, will receive a stream audio/mpegin response. This is an expensive process.
We use Nginx as a foreground request handler. Nginx takes care of caching responses for common requests.
We initially tried to use Tornado on the back-end to process requests from Nginx. As you would expect, blocking an MP3 operation caused Tornado to do its job (asynchronous I / O). So, we went multithreaded, which solved the blocking problem and performed quite well. Nevertheless, he presented a subtle race condition (under real load), which we have not yet been able to diagnose or reproduce. The race condition distorts our MP3 output.
So, we decided to configure our application as a simple WSGI handler for Apache / mod_wsgi (still with Nginx up). This fixes the lock problem and race condition, but creates a cascading load (i.e. Apache creates too many processes) on the server in real conditions. We are currently working on configuring Apache / mod_wsgi, but still at the trial error stage. (Update: we are back to the Tornado. See below.)
Finally, the question is: are we missing something? Is there a better way to serve expensive CPU resources via HTTP?
Update: Thanks to the article received from Graham, I am sure that this is an Apache configuration issue. At the same time, we returned to using Tornado and are trying to solve the data corruption problem.
, , Tornado ( , ) () Amazon EC2.