views:

32

answers:

1

I have a simple service that does approximately the following:

  1. An HTTP client connects to the server
  2. The server writes the sessionID of the client and the timestamp to the database, and in most cases just returns an empty response

(The cases when it does do real work and return actual data are irrelevant to this question)

In order to return this response as soon as possible, I'd like to write the info to memcache in the request handler's body (because memcache is fast), and to spawn a separate thread where another function using SQLAlchemy will write it to the persistent storage. This way, I'll be able to return immediately after writing to memcache and spawning a thread, and the request handler will not have to wait until SQLAlchemy saves the info to the database.

Does this make sense? If yes, how should I implement it?

+2  A: 

You could use something like the Celery distributed task queue to offload processing to other machines. It does require setup of a separate infrastructure, but will allow for tasks to be handed off from web requests for processing in the background, while the HTTP repsonse to the request can be returned immediately.

Vinay Sajip
Thanks, looks like that's exactly what I need
David Parunakian