Skip Menu |

This queue is for tickets about the Cache-Memcached-Fast CPAN distribution.

Report information
The Basics
Id: 57099
Status: rejected
Priority: 0/
Queue: Cache-Memcached-Fast

People
Owner: Nobody in particular
Requestors: david.morel [...] booking.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



Subject: Automate disconnect_all on fork
The documentation rightfully advises to call disconnect_all when forking, however it would be even nicer to have this done automatically, if the performance penalty isn't too great. Before doing any talk on the wire, would it be possible to have something like: sub new { ... return bless { ... , pid => $$ } $class; } then on any call, have this: if ($self->{pid} != $$) { $self->disconnect_all; $self->{pid} = $$; } Thanks!
But the performance penalty *is* too great. With this proposal we would make every user pay the price of extra system call on every request just to remove a bit of work for those who actually fork.
Subject: Re: [rt.cpan.org #57099] Automate disconnect_all on fork
Date: Sat, 1 May 2010 11:33:27 +0200
To: bug-Cache-Memcached-Fast [...] rt.cpan.org
From: David Morel <david.morel [...] booking.com>
Le 1 mai 2010 à 10:50, Tomash Brechko via RT a écrit : Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=57099 > > > But the performance penalty *is* too great. With this proposal we would > make every user pay the price of extra system call on every request just > to remove a bit of work for those who actually fork.
This is what I feared. Thanks for your answer anyway :) David Morel -- <david.morel@booking.com> - <http://www.booking.com/> office: +33 4 72 83 48 23 - gsm: +33 6 80 38 56 83 Booking.com - 23 rue Jules Vallès - F-69100 Villeurbanne
Download smime.p7s
application/pkcs7-signature 4.5k

Message body not shown because it is not plain text.

Subject: Re: [rt.cpan.org #57099] Automate disconnect_all on fork
Date: Sat, 1 May 2010 12:55:56 +0200
To: bug-Cache-Memcached-Fast [...] rt.cpan.org
From: David Morel <david.morel [...] booking.com>
Le 1 mai 2010 à 10:50, Tomash Brechko via RT a écrit : Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=57099 > > > But the performance penalty *is* too great. With this proposal we would > make every user pay the price of extra system call on every request just > to remove a bit of work for those who actually fork.
Okay, what about giving this option then: use Cache::Memcached::Fast qw( :SAFE_FORKING ); And use a constant that compiles away the slower code? As much as I agree about "the app/programmer should take care of this", it's not always as easy as it seems IRL (and this is from experience here). Lack of disconnect doesn't always lead to obvious protocol errors but can have the effect of the answers to concurrent requests to be swapped (req A receives answer B, req B receives answer A), which makes it very tricky to identify. David Morel
Download smime.p7s
application/pkcs7-signature 4.5k

Message body not shown because it is not plain text.

If a person remembers to use :SAFE_FORKING, then she as well can remember to use disconnect_all. The only problem is when you do not have a control over fork point. But in this case the problem should be addressed generally, not per module. For instance at the beginning of your program do my @before_fork; my @parent_fork; my @child_fork; BEGIN { *CORE::GLOBAL::fork = sub { $_->() foreach @before_fork; my $res = CORE::fork(); return unless defined $res; if ($res) { $_->() foreach @parent_fork; } else { $_->() foreach @child_fork; } return $res; }; } and then my $memd = Cache::Memcached::Fast->new(...); push @before_fork, sub { $memd->disconnect_all }; You can also wrap C::M::F in a class that will remove corresponding hooks in DESTROY. See man CORE for details; there's also fresh Hook::Fork on CPAN.