Good question. Right now there is not any built-in way of doing
it. If we had the ability to close the connection via gearmand, the
worker will just keep trying to reconnect. The methods now would be
to either register a shutdown function like you mention or to catch
signals and check/break out of the worker->work() loop when you see
a signal come in. It would be possible to add something into the
protocol, but I'd like to avoid that.
-Eric
How about we hook up a shutdown into the signal handler?
Cheers,
-Brian
--
_______________________________________________________
Brian "Krow" Aker, brian at tangent.org
Seattle, Washington
http://krow.net/ <-- Me
http://tangent.org/ <-- Software
_______________________________________________________
You can't grep a dead tree.
One issue is you don't always want to takeover the signal handlers in
case the parent application is taking them already (ie, PHP interpreter
process or some custom C worker code). I guess we could have a function
the client can call to handle this if they want, I'd be afraid to do
it by default.
Hmm, perhaps having a shutdown command from server is the best way to
deal with it and avoid signals with embedded/interpreted workers. Of
course that means having to telnet to a gearmand the worker is
connected to.
-Eric
On May 13, 2009, at 1:59 PM, Eric Day wrote:
> Hmm, perhaps having a shutdown command from server is the best way to
> deal with it and avoid signals with embedded/interpreted workers. Of
> course that means having to telnet to a gearmand the worker is
> connected to.
My thoughts:
1) Build a proper shutdown function.
2) Extend the protocol.
3) Run the function if the signal handler is called.
The above would be for the server. We could dummy up one for a worker
but I think it would be less useful...
Cheers,
-Brian
> 1) Build a proper shutdown function.
The Perl, PEAR/PHP, and Python clients all have hooks for stopping
workers. Python has a stop_if(), Perl has a stop_if call back and the
PEAR client has $monitor callback you can pass to beginWork. Every one
of these are perfectly capable of being used to gracefully shut down
workers.
> 2) Extend the protocol.
I vote no on this.
> 3) Run the function if the signal handler is called.
Exactly. Have your callback for the worker code trap signals and
gracefully kill each worker.
Some notes about how we run/use workers at Digg:
1. We run PHP workers via the daemon utility (http://libslack.org/daemon/
)
2. We gracefully exit the worker every 10 - 20 iterations due to PHP's
horrible memory management. The daemon utility re-HUP's the process
from there. We do this via the $monitor callback.
--Joe
--
Ernesto Rodriguez Reina