Showing posts with label memached. Show all posts
Showing posts with label memached. Show all posts

Friday, December 9, 2011

Membase

Membase is high performance key value pair system used for cacheing data. Membase generally provide superset of memcached.

You can use Membase to and configure either "memcached" type or "membase" type buckets. A membase-type bucket provides additional features such as key-value persistence and replication, whereas a memcached-type bucket provides only memory-only caching.

Memcached has it’s limitations. Moving to large+1 machines is going to lose a lot of your data. There is no master to organize the re-balancing of the data.We can avoid data loss using membase bucket type, while adding new server to the clusters.

Moxi

Moxi is the component of Membase that handles the re-routing of requests to other Membase servers when the server receiving the original request is not the one responsible for the data requested.

You can install membase using the instructions here.

testing membase.

you can test it using telnet utility.

shell> telnet localhost 11211 Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'

set test_key 0 0 1 a STORED
or you can run a PHP script to check if membase is installed properly or not.

connect("localhost",11211); // try 127.0.0.1 instead of localhost
// if it is not working

echo "Server's version: " . $memcache->getVersion() . "
\n";

// we will create an array which will be stored in membase serialized
$testArray = array('horse', 'dog', 'pig');
$tmp = serialize($testArray);
$memcache->add("key", $tmp);
echo "Data from the cache:
\n";
print_r(unserialize($memcache->get("key")));
?>




Thursday, September 22, 2011

Working with memcached

memcached is a general-purpose distributed memory caching system used to speed up dynamic database driven websites by caching data in RAM to reduce the number of times an external data source to be read.

Here is how memcached can be useful.The system uses a client server architecture. Server maintains associative array in key value pair. the clients populate this array and query it. Keys are up to 250 bytes long and values can be at most 1 MB size. by default server runs on 11211 port. A client should be installed in order to access memcached data. client can connect to multiple server by adding new server to it's pool. gettting data from memcached there are several methods to use memcached. yo can go to official site for more information on memcached.

Using memcached from a script. [I've used PHP in example.]

1. Memcached class should exist if memcached client is installed properly. Create an object of memcached.
                  $obj = new Memcached();
    if object created means memcached service is running. If not then you can start the service from command prompt.using command  svc -u path/to/memcached/ [eg:  /usr/local/memcache/bin/memcached ]

2. Add the server to the pool.
                $obj->addServers($servers); [$servers = array( '172.18.1.69', 11211) where 1st param. is IP of the server and second is port.]

3 Now you can use different methods to add/fetch memcached data. [example get($key),set($key,$value)]. for more information visit php.net site and search for memcached based function.


Checking memcache log.

1. Go to memcashed directory  /service/memcached

2.write the following command to get log
tail -f log/main/current | tai64nlocal


Using telnet to connect to memcache server.

1. telnet server_IP port [telnet 127.0.01 11214]

Once connected, you can check if memcache key is set, by typing  get memcache_key_name to get the memcached data for the key memcache_key_name and press enter. You can also set and delete key using set and delete.

Well that's all folks. We'll see membase in the next session.