librelist archives

« back to archive

Persistence for Multiple Children Processes

Persistence for Multiple Children Processes

From:
Devon Weller
Date:
2011-02-26 @ 20:13
Hi.


When running multiple children workers for handling web requests, should 
the same user be routed to the same child process every time?

For example, in the 30 line chat example, when running with 3 children 
processes the chat example doesn't work because the same user can be 
routed to a different child process every time.

This is because the in-memory "static $user_list" is different for each 
child process.  Changing this array in one child process doesn't change it
for the others.



- Devon

Re: [photon.users] Persistence for Multiple Children Processes

From:
Loic d'Anterroches
Date:
2011-02-26 @ 20:20
Hi Devon,

> 
> When running multiple children workers for handling web requests,
> should the same user be routed to the same child process every time?

No, the routing is handled by ZeroMQ in a round robin manner. You can
plug a queue between the handlers and Mongrel2 to do process locality,
but I do not think this is worth it at the moment.

> For example, in the 30 line chat example, when running with 3
> children processes the chat example doesn't work because the same
> user can be routed to a different child process every time.
> 
> This is because the in-memory "static $user_list" is different for
> each child process. Changing this array in one child process doesn't
> change it for the others.

Sure, this is why you must run with only one child for such simple
example. But, you can create a background task which will store the list
for you, a kind of memcached. This way you can access it from other
processes:

http://www.photon-project.com/doc/tasks

Look at the "memcached" example.

loïc

--
Indefero - Project management and code hosting - http://www.indefero.net
Photon - High Performance PHP Framework - http://photon-project.com
Céondo Ltd - Web + Science = Fun - http://www.ceondo.com