Re: reusing sockets between Perl memcached objects

2010-03-12 Thread Jonathan Swartz
The way I would solve this would be to change  
Cache::Memcached::libmemcached to *contain* a Memcached::libmemcached  
object (go from ISA to HAS-A), and forward all methods appropriately.  
Then multiple C::M::l objects could share the same M::l object.


Other than the ref() of the object, everything else in the API should  
remain the same.


I've written to dmaki asking if he'd be willing to accept such a patch.

Of course it would be even nicer if the C libmemcached handled this,  
but I've got a lot less ability to affect that. :)


Jon

On Mar 12, 2010, at 2:56 AM, dormando wrote:

We discovered this as well a few months ago... I don't think we  
found a

workaround :(

Maybe someone else has?

On Fri, 12 Mar 2010, Jonathan Swartz wrote:


We make liberal use of the namespace option to
Cache::Memcached::libmemcached, creating one object for each of our
dozens of namespaces.

However I recently discovered that it will create new socket
connections for each object. i.e.:

  #!/usr/bin/perl -w
  use Cache::Memcached;
  use strict;

  my ( $class, $iter ) = @ARGV or die "usage: $0 class iter";
  eval "require $class";

  my @memd;
  for my $i ( 0 .. $iter ) {
  $memd[$i] = $class->new( { servers => ["localhost:11211"] } );
  $memd[$i]->get('foo');
  }

  my $memd = new Cache::Memcached { servers => ["localhost:11211"] };
  my $stats = $memd->stats;
  print "curr_connections: " . $stats->{total}->{curr_connections} .
"\n";

swartz> ./sockets.pl Cache::Memcached 50
curr_connections: 10
swartz> ./sockets.pl Cache::Memcached::Fast 50
curr_connections: 61
swartz> ./sockets.pl Cache::Memcached::libmemcached 50
curr_connections: 61

I don't know why curr_connections starts at 10. In any case,
curr_connections will not grow with the number of Cache::Memcached
objects created, but will grow with the number of
Cache::Memcached::Fast or Cache::Memcached::libmemcached objects
created.

I was a little surprised that libmemcached, at least, didn't have  
this

feature. Just wondering if I'm doing something wrong.

If I want to keep using libmemcached, I guess I will have to create
just one option and override its namespace each time I use it.

Jon





Re: reusing sockets between Perl memcached objects

2010-03-12 Thread dormando
We discovered this as well a few months ago... I don't think we found a
workaround :(

Maybe someone else has?

On Fri, 12 Mar 2010, Jonathan Swartz wrote:

> We make liberal use of the namespace option to
> Cache::Memcached::libmemcached, creating one object for each of our
> dozens of namespaces.
>
> However I recently discovered that it will create new socket
> connections for each object. i.e.:
>
>#!/usr/bin/perl -w
>use Cache::Memcached;
>use strict;
>
>my ( $class, $iter ) = @ARGV or die "usage: $0 class iter";
>eval "require $class";
>
>my @memd;
>for my $i ( 0 .. $iter ) {
>$memd[$i] = $class->new( { servers => ["localhost:11211"] } );
>$memd[$i]->get('foo');
>}
>
>my $memd = new Cache::Memcached { servers => ["localhost:11211"] };
>my $stats = $memd->stats;
>print "curr_connections: " . $stats->{total}->{curr_connections} .
> "\n";
>
> swartz> ./sockets.pl Cache::Memcached 50
> curr_connections: 10
> swartz> ./sockets.pl Cache::Memcached::Fast 50
> curr_connections: 61
> swartz> ./sockets.pl Cache::Memcached::libmemcached 50
> curr_connections: 61
>
> I don't know why curr_connections starts at 10. In any case,
> curr_connections will not grow with the number of Cache::Memcached
> objects created, but will grow with the number of
> Cache::Memcached::Fast or Cache::Memcached::libmemcached objects
> created.
>
> I was a little surprised that libmemcached, at least, didn't have this
> feature. Just wondering if I'm doing something wrong.
>
> If I want to keep using libmemcached, I guess I will have to create
> just one option and override its namespace each time I use it.
>
> Jon
>