<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<TITLE>Message</TITLE>
<META content="MSHTML 6.00.2900.3199" name=GENERATOR></HEAD>
<BODY
style="WORD-WRAP: break-word; webkit-nbsp-mode: space; webkit-line-break: after-white-space">
<DIV><SPAN class=218594318-12102007><FONT face=Arial color=#0000ff size=2>Hi
Maxwell,</FONT></SPAN></DIV>
<DIV><SPAN class=218594318-12102007><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=218594318-12102007><FONT face=Arial color=#0000ff size=2>Thanks
for letting me hear from you -- I knew I wasn't crazy!! Actually I already
knew that -- the behavior is so black-and-white in my case: If I allow more than
one child to fork, there are problems; If I restrict it to just one child, no
problems. Clearly, something isn't working correctly in the memcache php
client, but I don't yet have the time to put a test script together for
Mikael. One of these days...</FONT></SPAN></DIV>
<DIV><SPAN class=218594318-12102007><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=218594318-12102007><FONT face=Arial color=#0000ff
size=2>Meanwhile, I'm living with the restriction that my daemon only forks one
child at a time. Fortunately, I was able to make other performance
improvements so we can live with this restriction for a while, but eventually
I've got to come back to this problem. Sorry I can't be of more help to
you.</FONT></SPAN></DIV>
<DIV><SPAN class=218594318-12102007><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=218594318-12102007><FONT face=Arial color=#0000ff size=2>I like
your idea of building in an automatic check/retry. It's not ideal, of
course, but it might help me when I go to the next stage of truly needing
multiple forked children, assuming the problem hasn't been fixed by then.
Thanks!</FONT></SPAN></DIV>
<DIV><SPAN class=218594318-12102007><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=218594318-12102007><FONT face=Arial color=#0000ff size=2>Best
of luck. I'll let you know if I come up with anything.</FONT></SPAN></DIV>
<BLOCKQUOTE style="MARGIN-RIGHT: 0px">
<DIV></DIV>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><FONT
face=Tahoma size=2>-----Original Message-----<BR><B>From:</B>
memcached-bounces@lists.danga.com [mailto:memcached-bounces@lists.danga.com]
<B>On Behalf Of </B>Maxwell Lamb<BR><B>Sent:</B> Friday, October 12, 2007
11:33 AM<BR><B>To:</B> memcached@lists.danga.com<BR><B>Subject:</B> Reentrancy
problem forking children with the PHP client<BR><BR></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>Sorry, didn't realize it wouldn't find the context - see
below.</FONT></DIV>
<DIV style="MIN-HEIGHT: 16px; MARGIN: 0px; FONT: 13px Courier"><BR></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>Hi,</FONT></DIV>
<DIV style="MIN-HEIGHT: 16px; MARGIN: 0px; FONT: 13px Courier"><BR></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>We've been experiencing the exact same issue, although our only
difference is that we're only opening the memcached connection once, prior to
forking using pctnl_fork.</FONT></DIV>
<DIV style="MIN-HEIGHT: 16px; MARGIN: 0px; FONT: 13px Courier"><BR></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>I was wondering if you'd had any joy finding a resolution to this -
we're currently working on the basis of storing everything in memcached within
a one-keyed array, where the key is the same as the memcached key, and the
value the same as the value to be stored, and we're then checking the key of
the returned array against the requested key from memcached, and if it's
wrong, trying again. While this resolves the issue insofar as it prevents us
from having the wrong data in the wrong place, it's obviously far from ideal
due to the overhead of having to do multiple requests in the case of failure,
and of having to check a key value after every get.</FONT></DIV>
<DIV style="MIN-HEIGHT: 16px; MARGIN: 0px; FONT: 13px Courier"><BR></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>Anyway - even if you don't have a solution, it isn't just you having
this issue.</FONT></DIV>
<DIV style="MIN-HEIGHT: 16px; MARGIN: 0px; FONT: 13px Courier"><BR></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>Thanks,</FONT></DIV>
<DIV style="MIN-HEIGHT: 16px; MARGIN: 0px; FONT: 13px Courier"><BR></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>Maxwell</FONT></DIV>
<DIV style="MIN-HEIGHT: 16px; MARGIN: 0px; FONT: 13px Courier"><BR></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>************************************************************************</FONT></DIV>
<DIV style="MIN-HEIGHT: 16px; MARGIN: 0px; FONT: 13px Courier"><BR></DIV>
<DIV style="MIN-HEIGHT: 16px; MARGIN: 0px; FONT: 13px Courier"><BR></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>Hi,</FONT></DIV>
<DIV style="MIN-HEIGHT: 16px; MARGIN: 0px; FONT: 13px Courier"><BR></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>Since you actually fork the process there should be no possibility
of</FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>sharing memory between children. And since the connection is
established</FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>after the fork no sockets are shared, in which case you would
probably</FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>get data corruption errors instead of a whole object being
swapped.</FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>Also, the client doesn't use any globals and works fine under ZTS
(the</FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>thread safe PHP build).</FONT></DIV>
<DIV style="MIN-HEIGHT: 16px; MARGIN: 0px; FONT: 13px Courier"><BR></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>If you have a short script that reproduces the problem, I'd be glad
to</FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>give it a try and see if I can hunt down the problem.</FONT></DIV>
<DIV style="MIN-HEIGHT: 16px; MARGIN: 0px; FONT: 13px Courier"><BR></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>//Mikael</FONT></DIV>
<DIV style="MIN-HEIGHT: 16px; MARGIN: 0px; FONT: 13px Courier"><BR></DIV>
<DIV style="MIN-HEIGHT: 16px; MARGIN: 0px; FONT: 13px Courier"><BR></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>Kenner Stross wrote:</FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> There appears to be a re-entrancy issue with the PHP
client. Here's a</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> brief recap of my situation:</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> </I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> I have a daemon process that is written in php (and is thus
called like</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> this: "php -e myDaemon -- -paramOne -paramTwo &").
Once it is launched,</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> it follows standard daemon coding practices to set itself up as
a</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> detached session leader and wait for something to do.
Once there is</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> something to do, it will fork some children to do the
work. Looks like</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> this:</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> </I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> myDaemon (the parent, which forks three times in this
example)</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> <SPAN class=Apple-tab-span
style="WHITE-SPACE: pre"></SPAN>myDaemon (child 1)</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> <SPAN class=Apple-tab-span
style="WHITE-SPACE: pre"></SPAN>myDaemon (child 2)</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> <SPAN class=Apple-tab-span
style="WHITE-SPACE: pre"></SPAN>myDaemon (child 3)</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> </I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> The memcache client is not instantiated until the children have
forked,</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> so that each child can have a memcache client that is separate
from and</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> unrelated to the other children. However, it appears that
they are all</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> still intertwined at some deeper level, apparently as a result
of having</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> forked out of the same php process space (I
guess).</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> </I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> The symptoms are this: At various random points, a memcache
"get" for</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> object1 (whose type is class1) will return object2 (whose type
is</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> class2). In other words, it is returning the wrong
objects. To me,</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> this sure looks like a reentrancy problem, where one child is
being</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> swapped in by the processor at JUST THE RIGHT MOMENT to pick up
the</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> OTHER OBJECT from the OTHER CHILD that was just swapped
out.</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> </I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> The confirmation that this is the problem is that when I set a
limit</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> such that the parent can never fork more than one child, the
problem</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> goes away. Handled that way, memcache always returns the
correct</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> object.</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> </I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> Has anybody had similar experiences? I'd love to hear
what others may</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> know about this issue and/or the architecture of the php
client</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> vis-a-vis forking.</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> </I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> Thanks,</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> Kenner Stross</I></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 13px Courier" face=Courier
size=4>><I> </I></FONT></DIV>
<DIV></DIV><BR></BLOCKQUOTE></BODY></HTML>