Re: libmemcache: memcached_behavior_number_of_replicas working?

2011-03-03 Thread Felipe Cerqueira
Hi,

Its works for me on version 0.45 with C.

I didnt like of this behavior but its works.

The concept of master and slave dont exist. So, if its get a error
trying to send data to the hash(key)-server, its dont send data to
the others server(s).



On Mar 3, 12:09 pm, Bill Moseley mose...@hank.org wrote:
 http://docs.libmemcached.org/memcached_behavior_set.html#memcached_be...
 http://docs.libmemcached.org/memcached_behavior_set.html#memcached_be...
 or
 http://docs.libmemcached.org/memcached_behavior_set.html#memcached_be...http://search.cpan.org/~timb/Memcached-libmemcached-0.4406/lib/Memcac...

 Is that feature working in libmemcached?    I tried with Perl's
 Memcached::libmemcached two different versions:

    - Version 0.3102 (with libmemcached-0.31 embedded)
    - Version 0.4406 (with libmemcached-0.44 embedded)

 http://docs.libmemcached.org/memcached_behavior_set.html#memcached_be...

 and watching with Wireshark (and also reading from individual servers) I
 only saw a writes to a single server.

 use Memcached::libmemcached qw(:memcached_behavior_t );
 use strict;
 use warnings;

 my $memc = Memcached::libmemcached-new;
 $memc-memcached_server_add( 'localhost', 11211 );
 $memc-memcached_server_add( 'localhost', 11212 );

 # Also tried specifying 2 for number of replicas
 $memc-memcached_behavior_set( MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS() = 1
 );
 $memc-memcached_set( 'test', 1, 10 ) || die 'set failed ' . $memc-errstr;

 Also, what does MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT do?  Does that mean
 after a server reports that many failures any gets or sets to that server
 will fail without the library attempting to send to the memcached server?  I
 assume that doesn't mean the server will be pulled out of the pool and keys
 would get rehashed to new servers.  (Although, maybe
 if MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS is set, but if that means keys would
 hash to different servers that seems like a bad idea.)

 Yes, I'm looking at poor-man's HA with these two features.  Looking at how
 pulling the plug on one server won't result in get or set failures, and not
 an increased amount of time (say waiting for a failed server to respond).

 --
 Bill Moseley
 mose...@hank.org


Re: libmemcache: memcached_behavior_number_of_replicas working?

2011-03-03 Thread Bill Moseley
On Thu, Mar 3, 2011 at 9:54 AM, Felipe Cerqueira skylaz...@gmail.comwrote:

 Hi,

 Its works for me on version 0.45 with C.


Well, perhaps I'm not configuring the client correctly.  See below.



 I didnt like of this behavior but its works.

 The concept of master and slave dont exist. So, if its get a error
 trying to send data to the hash(key)-server, its dont send data to
 the others server(s).


Are you saying that even with  MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS set
to 1 if the first server write fails then it won't write to the second?
 That is, once a server fails only reads work?


Here's a simple test script using the most recent Perl version with output
below.  Am I not setting this up correctly?

use Memcached::libmemcached qw( :memcached_behavior_t );
use strict;
use warnings;


my $memc = Memcached::libmemcached-new;
$memc-memcached_behavior_set( MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS() = 1
);

$memc-memcached_server_add( 'localhost', 11211 );
$memc-memcached_server_add( 'localhost', 11212 );


my $mem1 = Memcached::libmemcached-new;
$mem1-memcached_server_add( 'localhost', 11211 );

my $mem2 = Memcached::libmemcached-new;
$mem2-memcached_server_add( 'localhost', 11212 );


printf Running libmemcached version %s\n,
Memcached::libmemcached::memcached_lib_version();


for ( 1 .. 8 ) {

my $id = int rand 1000;

print \n= key $id =\n;
$memc-memcached_set( $id, 1, 10 )
|| die 'set failed ' . $memc-errstr . '\n;


my ( $flag, $rc );

$mem1-memcached_get( $id, $flag, $rc )
 print found in mem1\n;


$mem2-memcached_get( $id, $flag, $rc )
 print found in mem2\n;

}

Running this I see -- not it's only finding the key in one server.

Running libmemcached version 0.44

= key 869 =
found in mem2

= key 321 =
found in mem1

= key 618 =
found in mem1

= key 234 =
found in mem2

= key 667 =
found in mem1

= key 54 =
found in mem2

= key 441 =
found in mem1

= key 178 =
found in mem1


One thing I always find odd is if I don't have Memcached running I get:

set failed SYSTEM ERROR Success'


Does that mean a successful system error? ;)


-- 
Bill Moseley
mose...@hank.org


Re: libmemcache: memcached_behavior_number_of_replicas working?

2011-03-03 Thread Felipe Cerqueira
Hi Bill,

On Mar 3, 3:54 pm, Bill Moseley mose...@hank.org wrote:
 On Thu, Mar 3, 2011 at 9:54 AM, Felipe Cerqueira skylaz...@gmail.comwrote:

  Hi,

  Its works for me on version 0.45 with C.

 Well, perhaps I'm not configuring the client correctly.  See below.



  I didnt like of this behavior but its works.

  The concept of master and slave dont exist. So, if its get a error
  trying to send data to the hash(key)-server, its dont send data to
  the others server(s).

 Are you saying that even with  MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS set
 to 1 if the first server write fails then it won't write to the second?
  That is, once a server fails only reads work?


First of all, replication is only for write. Internally, its wont ask
for a second server.

About your question, its really wont replicate the data if fails on
first server. You can see it on the source code of libmemcached:

See: http://goo.gl/JSSro

I dont like this behaivor too.


 Here's a simple test script using the most recent Perl version with output
 below.  Am I not setting this up correctly?

 use Memcached::libmemcached qw( :memcached_behavior_t );
 use strict;
 use warnings;

 my $memc = Memcached::libmemcached-new;
 $memc-memcached_behavior_set( MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS() = 1
 );

 $memc-memcached_server_add( 'localhost', 11211 );
 $memc-memcached_server_add( 'localhost', 11212 );

 my $mem1 = Memcached::libmemcached-new;
 $mem1-memcached_server_add( 'localhost', 11211 );

 my $mem2 = Memcached::libmemcached-new;
 $mem2-memcached_server_add( 'localhost', 11212 );

 printf Running libmemcached version %s\n,
     Memcached::libmemcached::memcached_lib_version();



The replication only works with binary mode. Did you set it up?
And, remember, this feature is only for replication data, not
consulting (get).

I have tested on libmemcached with C. I dont known about perl.



 for ( 1 .. 8 ) {

     my $id = int rand 1000;

     print \n= key $id =\n;
     $memc-memcached_set( $id, 1, 10 )
         || die 'set failed ' . $memc-errstr . '\n;

     my ( $flag, $rc );

     $mem1-memcached_get( $id, $flag, $rc )
          print found in mem1\n;

     $mem2-memcached_get( $id, $flag, $rc )
          print found in mem2\n;

 }

 Running this I see -- not it's only finding the key in one server.

 Running libmemcached version 0.44

 = key 869 =
 found in mem2

 = key 321 =
 found in mem1

 = key 618 =
 found in mem1

 = key 234 =
 found in mem2

 = key 667 =
 found in mem1

 = key 54 =
 found in mem2

 = key 441 =
 found in mem1

 = key 178 =
 found in mem1

 One thing I always find odd is if I don't have Memcached running I get:

 set failed SYSTEM ERROR Success'

 Does that mean a successful system error? ;)

 --
 Bill Moseley
 mose...@hank.org


Re: libmemcache: memcached_behavior_number_of_replicas working?

2011-03-03 Thread Bill Moseley
On Thu, Mar 3, 2011 at 11:18 AM, Felipe Cerqueira skylaz...@gmail.comwrote:

 The replication only works with binary mode. Did you set it up?


Oh, no, I guess that would help.  I must of missed that in the docs.  I was
running Memcached 1.2.8, so I just installed 1.4.5 and enabled binary in the
Perl code with:

$memc-memcached_behavior_set( MEMCACHED_BEHAVIOR_BINARY_PROTOCOL() = 1 );
$memc-memcached_behavior_set( MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS() = 1
);


If I write a sequence of keys using memcached_set( $key, 1 ) in a loop I
only see (with memcached -vv) SET on the one server per key (the primary
based on how it's hashed).

But, then when I exit the program (closing the connection) the LAST key I
wrote gets written to the replicant(s).

Do I need to flush or something like that after every set call?




 And, remember, this feature is only for replication data, not
 consulting (get).


The docs seem to indicate otherwise, and indeed if I kill the primary
where a key was set and attempt to read then it reads from the replicant.

MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS

If you just want a poor mans HA, you may specify the numbers of replicas
libmemcached should store of each item (on different servers). This
replication does not dedicate certain memcached servers to store the
replicas in, but instead it will store the replicas together with all of the
other objects (*on the 'n' next servers specified in your server list*).

MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ

Allows randomizing the replica reads starting point. *Normally the* *read is
done from primary server and in case of miss the read is done from primary +
1, then primary + 2 all the way to 'n' replicas*. If this option is set on
the starting point of the replica reads is randomized between the servers.
This allows distributing read load to multiple servers with the expense of
more write traffic.



-- 
Bill Moseley
mose...@hank.org


Re: libmemcache: memcached_behavior_number_of_replicas working?

2011-03-03 Thread Brian Aker
Hi!

On Mar 3, 2011, at 5:12 PM, Bill Moseley wrote:

 But, then when I exit the program (closing the connection) the LAST key I 
 wrote gets written to the replicant(s).

I explained this on the libmemcached mailing list but I will comment do a short 
comment on it here as well.

Libmemcached with replica set to 2 libmemcached will write to the hashed node 
and additionally to the next node in the list.

The replicated key+pair is buffered on the client, so it is not sent out 
immediately, which is why you might not see it if you immediately go looking 
(it also means that a client crash could leave you with just the not replicated 
value in the cache).

There are no lets vote to see if they both arrive and ordering could be 
thrown off to the replica under a number of different circumstances. There are 
no split brain solutions.

This is far from bullet proof, buyer beware. Frankly though? It is probably 
good enough for the vast majority of problems. If you have greater needs? Go 
use a database. 

Cheers,
-Brian





Re: libmemcache: memcached_behavior_number_of_replicas working?

2011-03-03 Thread Brian Aker
Hi!

On Mar 3, 2011, at 11:18 AM, Felipe Cerqueira wrote:

 About your question, its really wont replicate the data if fails on
 first server. You can see it on the source code of libmemcached:
 
 See: http://goo.gl/JSSro
 
 I dont like this behaivor too.

I'd take a patch to change this behavior (well, add an additional mode). Write 
up a bug at http://bugs.launchpad.net/libmemcached and I will probably get to 
it sooner then later.

Cheers,
-Brian