Skip Menu |

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

Report information
The Basics
Id: 112659
Status: open
Priority: 0/
Queue: Memoize-Memcached

People
Owner: Nobody in particular
Requestors: peter [...] morch.com
Cc:
AdminCc:

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



Subject: Two memcached round-trips for each cache hit
Date: Thu, 3 Mar 2016 10:47:03 +0100
To: bug-Memoize-Memcached [...] rt.cpan.org
From: Peter Valdemar Mørch <peter [...] morch.com>
Memoize.pm has this: if (exists $cache->{$argstr}) { return @{$cache->{$argstr}}; } else { .. } So first exists is tested to see if we have a cache hit, and then the value is fetched. Memoize/Memcached.pm has this: sub FETCH { my $self = shift; my $key = $self->_get_key(shift); return $self->{memcached_obj}->get($key); } sub EXISTS { my $self = shift; return defined $self->FETCH(@_); } So if there is a cache hit, first EXISTS is called (which calls FETCH internally) and then afterwards, FETCH is called again. Here is what it looks like in a NYTProf flamegraph: [image: Inline image 1] ( http://i.imgur.com/WYcDbiK.png ) for: sub foo { return "2"; } memoize_memcached('foo'); foreach (1..100000) { foo(); } I don't know the side effects, but it looks like execution time for a cache hit (the common case?) could be cut in half rather easily... Peter -- Peter Valdemar Mørch http://www.morch.com
memoizeMemcached.png
On 2016-03-03 04:47:22, peter@morch.com wrote: Show quoted text
> Memoize.pm has this: > > if (exists $cache->{$argstr}) { > return @{$cache->{$argstr}}; > } else { > .. > } > > So first exists is tested to see if we have a cache hit, and then the value > is fetched. > > Memoize/Memcached.pm has this: > > sub FETCH { > my $self = shift; > my $key = $self->_get_key(shift); > return $self->{memcached_obj}->get($key); > } > > sub EXISTS { > my $self = shift; > return defined $self->FETCH(@_); > } > > So if there is a cache hit, first EXISTS is called (which calls FETCH > internally) and then afterwards, FETCH is called again. Here is what it > looks like in a NYTProf flamegraph: > > [image: Inline image 1] > > ( http://i.imgur.com/WYcDbiK.png ) > > for: > > sub foo { > return "2"; > } > > memoize_memcached('foo'); > foreach (1..100000) { > foo(); > } > > I don't know the side effects, but it looks like execution time for a cache > hit (the common case?) could be cut in half rather easily... > > Peter
Additionally to the performance problem there's a possible other one: https://en.wikipedia.org/wiki/Time_of_check_to_time_of_use Regards, Slaven