What is Memcached ?

2

Self Advertisement
—–Start of Advertisement——-
BUILD CAR POOL SOLUTIONS ON ANY DEVICE TO RUN ANYWHERE (www.mcruiseon.com). Introducing mCruiseOn, the java library /json api’s that you can use to build a car pool solution. Be the next avego.com, carpooling.com, zimride.com. mCruiseOn is your one stop API on EC2.
——End of Advertisement——-

Thats the point right, if something ain’t that easy to understand, how easy will it be to implement and maintain ? The challenge is to understand it in one go.

Memcached is a distributed memory object caching system. No, that is not the way I am going to explain it, so chill :).

We all know that our webservers have web applications that run database query’s to get data. They also call query’s to insert, delete and update data. As simple as it sounds, its crazy to get such a system working when millions of connections on the webserver get requests. Webservers need to be added in parallel to handle load, databases need to be replicated so that in parallel data can be accessed, and then starts the complication of ensuring that data is consistent across all the requests. Then comes the challenge of ensuring data is available quickly enough.

Bad examples are http://www.irctc.co.in. But its important to understand how difficult it is to get it right. Especially if your data is as complex as the Indian Railways. If this site is down, the nation stops.

Now, for some basic computer fundamentals. Just as a quick reminder. We all know that tape drives are slower than floppy disks. Floppy disks are slower than hard disks. Hard disks are slower than memory. And memory is slower than CPU memory. CPU memory is much more expensive than memory, and the story continues. Faster the memory the more expensive it will be.

What is serialization ? A object that can be stored on a disk byte by byte, and read back to form that object again, is called a Serializable object.

Now, imagine. If I store a file on a harddisk, and read it. Will it be faster if I read it from the memory ? Obviously. We dont use fread (file read, File.read()) for every operation we want to perform. We first read it into a String, and then read it from that String. Memcached does something similar. It stores all data given to it in memory. So that you can read from it faster as compared to a harddisk.

So, if you have a piece of code doing a lot of read from harddisks, (mind you databases are also stored in big harddisks), AND if that data is needed to be read multiple times, then you can write that data to memcached. So instead of reading data from the harddisk all reads can goto memcached. There by preventing the harddisk from the extra effort for each read. It can do something more important in that time.

Memcached provides you with a way to identify the data that you just wrote with a identifier, a name or a key. We call it key value pair.

When you load memcached, you need to specify the amount of memory that this machine will dedicate for memcached. And memcached reserves that much memory for itself (the -m command). So, what happens when u run out of memory.

Simple load memcached on another machine, and get both these memcached machines to know each other (this is called a cluster). Then you can refer to the cluster and add objects. Memcached will store objects in round robin between the servers on the cluster.

Now, your application needs to identify from its request if similar data is being  requested between its clients. If it is, then the first call can save that common data on memcached, and subsequent calls can retrieve the data from memcached.

Just remember, that memcached is a “explicit cache”. Which means you need to add stuff to memcached, remove it, updated it. It does “nothing” automatically. At this point many people get turned off, but the concept of memcached is to save your trip to the database, and reduce the need for clustering a database and webservers. Since clustering memcached is very cheap, as compared to database and webservers.

This should help you understand the fundamentals of memcached.

Advertisements

Why is WordPress bad ? (Its the best in competition though)

3

I have been using wordpress for last 2 month now to build my website. Although its the best in the market today, as compared to drupal/joombla, I find the following limitations.

  1. As we search for themes/plugins, there is no way to sort/filter on ratings and # of ratings. We have to go into each details link to figure it out.
  2. Its has not been tested for your version of wordpress, is another pain, why show me something that is not tested for my wordpress ?
  3. The Details site of all the plugins are not all good. Some are really good and some are really bad, they just link to the developers site that has absolutely no information on how to get started. For example FoCal plugin, it took me a while to know that it is a widget and not a [focal] entry into the page. Painful getting started, and wordpress allows them to post their plugins with bad documentation. There should be some quality control on wordpress posting site.
  4. Many dont have screen shots, so thats really bad. Have to try it out to get it working.
  5. Bad naming convention, the word “custom” is so misused. On pages we have a “template”, which we can decide with, why cant we do it for posts ? I am using Graphene theme, THE ABSOLUTE BEST, I have after trying out 15. I just cant search for custom template for posts, and if do get something that sounds relevant, it wont work, custom will mean something else.

WordPress is good, but has its own piece of issues. I hope wordpress is hearing, they should be able to fix these 5 issues very easily.

Transfer a WordPress from development to deployment domain

2

So, recently I decided to setup a EC2 ubuntu server to get my developer to work on developing my website. While I was setting it up, I realized the need to document the steps involved. As I could not find all in one place. So here goes for all those dudes out there.

On your EC2, create a new Instance and use a Vanilla Ubuntu 10.04 (not 11, its unstable as of now)\

  • sudo apt-get install subversion mysql-server apache2 php5
  • sudo apt-get install php5-mysql

On your EC2, configure Security Groups to allow port 80, for inbound 0.0.0.0, Apply rules

  • sudo service apache2 restart
  • ssh to the ec2
  • On your EC2 prompt>sudo vi /var/www/index.php and insert

<?
phpinfo();
?>

Test your apache2 on the ec2.

  • Open browser on your host machine, enter dns name of the EC2, test for index.html.
  • Now test for php, On the browse dnsname/index.php

On your EC2

  • sudo mkdir checkout
  • sudo svn co <svn path of your project>
  • mv wordpress /var/www
  • mv bugzilla3 /var/www
  • sudo apt-get install perl gcc bugzilla3

Create appropriate databases on your EC2

  • sudo mysql -u root -p
  • mysql>create database bugs ;
  • mysql>create database wordpress ;

From your Host, export bugs, bugzilla3 and wordpress database to .sql files

  • mysqldump –tables -u root -p wordpress >> wordpress.sql
  • mysqldump –tables -u root -p bugs >> bugs.sql
  • mysqldump –tables -u root -p bugzilla3 >> bugzilla3.sql

On your EC2 .import into database sql files (EXCEPT wordpress)

  • sudo mysql -u root -p bugs < bugs.sql
  • sudo mysql -u root -p bugzilla3 < bugzilla3.sq

Now, the most important part, since you are moving the site from localhost to a EC2, wp_options table needs to be modified a bit.

  • vi wordpress.sql and run a :s%/localhost/YOURNEWDNSNAME/g on it to replace all “localhost” instances in the database with your new dns name.
  • I found 13 places. Modify all localhost to your public dns of EC2.
  • now run a “sudo mysql -u root -p wordpress < wordpress.sql

In my case I had used WP_UI tabs plugin, so its settings just died on the new EC2. So I had to enable a few settings.

If you get lost refer to “http://codex.wordpress.org/Moving_WordPress“. This is what I used to get mine up and running.