Monday, August 29, 2011

Membase deployment and scaling with Ubuntu Server and Juju

** This is an updated post reflecting the new name of the project formerly known as Ensemble and now known as Juju **

Let's talk about Membase

Membsase ( from their website ):
Membase Server is the lowest latency, highest throughput NoSQL database technology on the market. When your application needs data, right now, it will get it, right now. A distributed key-value data store, Membase Server is designed and optimized for the data management needs of interactive web applications, so it allows the data layer to scale out just like the web application logic tier – simply by adding more commodity servers.

When I first read about Membase, my first thought was something like: yup...yet another NoSQL thing like memcached, cassandra, mongodb, etc. I have done Juju charms for MongoDB here and Cassandra here so, I thought I would do a Membase one as well.

Well.. I stand corrected. Membase is different in some significant ways. I got the following points from their website but, I gotta tell you; I actually agree with them:
  • Membase is simple
    • Easy to get, install, manage, expand and use
      • Especially now that I have the juju charm ready for use
    • Production ready
      • I have seen this deployed in networks that handle some really heavy traffic
  • Membase is fast
    • Durable Speed Without Compromising Safety.
      • Again, I have seen this thing in action and I'm impressed.
    • Managed Memory Caching Layer.
  • Membase server is elastic
    • Zero Downtime Topology Change
    • Spreads Data Across Cluster
I should probably stop now before I turn this into a Membase commercial :)


I you are not familiar with Juju, I highly recommend that you go over their website and read up on it.  I plan on doing a quick howto and basic intro about Juju but, not today so, go read about it.  I'll be here when you get back.

Welcome back .... By now I hope you like Juju as much as I do and are ready to check out some of the inner workings of the Membase Juju charm.  

Juju charms are pretty liberal.  They just need to have a basic directory structure and some aptly named files.  One of those files is the metadata.yaml file.  

The metadata.yaml file contains the charms' description and some information about what it provides, requires and "peers" with.

Here is the metadata.yaml file for the Membase charm:
name: membase
revision: 2
summary: Membase Server
description: |
   Membase Server is the leading distribution of memcached and
   membase, created and supported by top contributors to the memcached
   and membase open source projects.
provides:
  db:
    interface: membase
peers:
  cluster:
    interface: membase-cluster
This metadata file is pretty simple.  It contains the charms' description ( taken directly from their package ), what the charm provides ( it provides a db by the name of membase ) and it's "peers" interface.

"peers" interfaces are not required but, are the special interfaces that are used to have "peers" share information, settings, etc between nodes.  In fact, peers interfaces are how I have the different Membase nodes communicate with each other and incorporate themselves into the cluster.  Read up about the different types of interfaces and much more on Esemble's documentation page. Let's take a look at how this all works.  The interesting bit of this charm is in the cluster-relation-changed hook that is responsible for adding new nodes to the existing cluster.  Here is the script:

#!/bin/bash 
set -ux
MASTER_INSTALL_TIME=`facter membase-install-time`
MASTER_MEMBER=$JUJU_UNIT_NAME
# Find out the oldest/first node
for MEMBER in `relation-list`
do
   INSTALL_TIME=`relation-get install-time ${MEMBER}`
   [ ${INSTALL_TIME} -lt ${MASTER_INSTALL_TIME} ] && MASTER_MEMBER=${MEMBER}
done
if [ ${JUJU_UNIT_NAME} != ${MASTER_MEMBER} ]; then
   # I am not the master node so, I need to join up with the master node
    /opt/membase/bin/membase rebalance \
                 -u `relation-get username ${MASTER_MEMBER}` -p `relation-get password ${MASTER_MEMBER}` \
                 -c `relation-get ip ${MASTER_MEMBER}` \
                 --server-add=`facter membase-ip` \
                 --server-add-username=`facter membase-username` \
                 --server-add-password=`facter membase-password`
fi
exit 0
Not too complicated for what it does huh?  Juju provides the foundation for all of this to happen easily and Membase provides a lot of the facilities that simplify the needed actions ( in our case, add a new node and rebalance the cluster ).

The above script looks for the oldest node ( during install, I keep track of the installation time ).  The oldest node in the deployment is considered to be the master.  Once the "master" has been identified, all new nodes in the deployment add themselves to the master's cluster and re-balance the cluster.  Membase provides a good cli from where to accomplish all that's needed hence the simplicity of this script.

Juju's installation instruction are here.  The charm can be downloaded from here.  

Here is a quick rundown on the commands you will need to run in order to get your Membase deployment ready:
  • mkdir ~/juju-charms
  • cd ~/juju-charms
  • bzr branch lp:principia/membase
  • juju bootstrap
  • juju deploy --repository . membase
  • juju status
    • You should see something like this:
2011-08-26 20:08:54,112 INFO Connecting to environment.
machines:
  0: {dns-name: ec2-50-16-161-217.compute-1.amazonaws.com, instance-id: i-65ece204}
  1: {dns-name: ec2-50-19-19-37.compute-1.amazonaws.com, instance-id: i-29ebe548}
services:
  membase:
    charm: local:membase-2
    relations: {cluster: membase}
    units:
      membase/0:
        machine: 1
        relations: {}
        state: null
  • I've highlighted the part you would want to copy and paste on your browser.  It will point you to the Membase's web interface.  It defaults to port 8091 so, you would ( in this case ) open your browser to http://ec2-50-19-19-37.compute-1.amazonaws.com:8091
  • Log in with the default username and password ( Administrator/administrator )
    • You can change the default username and password in the file membase/hooks/install
  • You should see something similar to this:


  • Leave that Browser running, go back to the command line and add another unit by typing:
    • juju add-unit membase
  • In a few minutes, you'll see the new node in the Web interface.  The data is being rebalanced and, when complete, the node will be available and a member of the cluster.  

Membase does many things right and, Ubuntu Server provides a stable platform where to deploy.  Juju wraps it all up by making it reusable and simple.

Check out Membase's documentation here as well for information on testing your Membase deployment and more of it's features.

Questions/Comments/Feedback.  Let me know ...


-Juan


No comments:

Post a Comment