views:

535

answers:

2

In Python, if I want my server to scale well CPU-wise, I obviously need to spawn multiple processes. I was wondering which is better (using Twisted):

A) The manager process (the one who holds the actual socket connections) puts received packets into a shared queue (the one from the multiprocessing module), and worker processes pull the packets out of the queue, process them and send the results back to the client.

B) The manager process (the one who holds the actual socket connections) launches a deferred thread and then calls the apply() function on the process pool. Once the result returns from the worker process, the manager sends the result back to the client.

In both implementations, the worker processes use thread pools so they can work on more than one packet at once (since there will be a lot of database querying).

+2  A: 

I think that B is problematic. The thread would only run on one CPU, and even if it runs a process, the thread is still running. A may be better.

It is best to try and measure both in terms of time and see which one is faster and which one scales well. However, I'll reiterate that I highly doubt that B will scale well.

kylebrooks
+1  A: 

I think that "A" is the answer you want, but you don't have to do it yourself.

Have you considered ampoule?

Glyph