When to disconnect_all?

James Mastros james at mastros.biz
Tue Feb 8 20:18:46 PST 2005


Batara Kesuma wrote:
> Hi,
> 
> I read about this on Perl API documentation:
> > $memd->disconnect_all();
> > Closes all cached sockets to all memcached servers. You must do this if
> > your program forks and the parent has used this module at all. Otherwise
> > the children will try to use cached sockets and they'll fight (as
> > children do) and garble the client/server protocol.
> 
> For example, I run mod_perl with 60 processess, and 800
> MaxRequestsPerChild. If I don't do disconnect_all at all how many times
> will the cached sockets be shared?

The part you're missing is /and the parent has used this module at all/. 
  In the processes you're talking about, the parent is the main mod_perl 
process, and the module has not been used.  For that matter, it's a 
freshly minted interpreter.

The problem the docs are pointing out will occur when a process that's 
been using the memcached module gets duplicated with the perl fork() 
call or with perl-level threads -- in which case both processes share 
the same connection, which will confuse things.  (NB: I'm not completely 
sure about the threads case -- and the problem could probably be fixed 
by setting the "do not duplicate across forks" flag on the FD.)

	-=- James Mastros


More information about the memcached mailing list