httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Manoj Kasichainula <>
Subject Graceful child shutdown in the presence of accept serialization
Date Fri, 07 May 1999 19:50:32 GMT
We've talked a bit about the problem in the hybrid server right now
with graceful child shutdown with accept serialization. Basically, we
need a way to kick our processes out of waiting on the accept mutex so
that they can exit when told to.

I think we have a solution to this problem, pasted together from some
of the ideas Dean and Ryan have given me.

This problem can be decomposed into two smaller problems: (1) getting
a message to one of the threads of a process to die, and (2) having
one thread noticing a shutdown condition triggering the other threads
to shutdown as well.

For problem 2, the solution is to take advantage of the fact that the
accept mutex lock operation is usually an intraprocess mutex lock
(e.g. pthread_mutex_lock) followed by a cross-process lock (e.g.
fcntl). Then, when a single worker thread notices that it's death time
and exits, then the other threads will each get let past the pthread
mutex, notice it's time to die, and exit, all in sequence.

The only place where this falls apart is where the accept mutex does
not have two separate pieces. For example, when
USE_PTHREAD_SERIALIZED_ACCEPT is active, we use a single mutex which
protects across processes as well as within a process, so no extra
locks have been needed.  Unforturnately, the only solution is to add
an extra lock like the other accept serialization schemes use. But,
this extra lock isn't that expensive.

For problem 1, a solution is to use a server-wide non-blocking pipe to
indicate graceful shutdown time for a child, like the one Dean
suggested a few days ago. Each child will poll() on all its listening
sockets as well as the pipe. The server will write one byte to the
pipe for every child it wishes to shutdown. When the thread wakes up
out of poll, it tries to read a byte from the pipe. If it succeeds, it
sets the shutdown flag and dies.

I've written a patch (attached) which implements the solution for
problem 2.

Manoj Kasichainula -
IBM, Apache Development

View raw message