guettli
guettli

Reputation: 27129

Parallelism in one web request

Our server has a lot if CPUs, and some web requests could be faster if request handlers would do some parallel processing.

Example: Some work needs to be done on N (about 1-20) pictures, to severe one web request.

Caching or doing the stuff before the request comes in is not possible.

What can be done to use several CPUs of the hardware:

Platform: Django (Python)

Upvotes: 0

Views: 220

Answers (2)

mbatchkarov
mbatchkarov

Reputation: 16109

Regarding your second and third alternatives: you do not need to start a new process for every request. This is what process pools are for. New processes are created when your app starts up. When you submit a request to the pool, it is automatically queued until a worker is available. The disadvantage is that requests are blocking- if no worker is available at the moment, your user will sit and wait.

Upvotes: 3

phant0m
phant0m

Reputation: 16905

You could use the standard library module asyncore.

This module provides the basic infrastructure for writing asynchronous socket service clients and servers.

There is an example for how to create a basic HTML client.


Then there's Twisted, it can do lots and lots of things, which is why it's somewhat daunting. Here is an example using its HTTP client.


Twisted "speaks HTTP", asyncore does not, you'll have to.


Other libraries:

Upvotes: 1

Related Questions