Wednesday, February 17, 2010

Terracotta Ehcache 3.2.1 Bulkload feature

Terracotta 3.2.1 release has several new features and I am going to write about one of them i.e. Bulk loading for ehcache.

Why do we need bulk loading?
Bulk loading helps us reduce the time required for warming up large caches.

Basic Idea:
The basic idea for doing fast bulk loading can be achieved by reducing lock acquisition time and transaction overhead. To do this one can move the cache from "coherent" mode to "incoherent" mode when you want to do bulk loading. In incoherent mode, the cache is non-coherent and concurrent locks mark Terracotta transaction boundaries. Multiple puts are batched up automatically and sent as one Terracotta transaction.

Implementation details:
Cache interface (in ehcache-core) now exposes a few more methods which makes using bulk load quite simple to use. So here are are basic descriptions of those methods:
  1. setNodeCoherent(boolean) -- When false is passed as a parameter to this method then it simply makes the cache incoherent. However when the cache is coherent then this call stops the local buffer and waits until all the Terracotta transactions have been acked back.
  2. waitUntilClusterCoherent() -- This call will wait until all the nodes in the cluster are coherent.
  3. isNodeCoherent() -- Returns true if the current node is coherent.
  4. isClusterCoherent() -- Returns true if the cluster is coherent.
Using these interfaces one can easily use bulk load.

A simple example here:

// This call makes the cache incoherent and enables buffering and will use concurrent locks
cache.setNodeCoherent(false);

// Start loading
startLoading();

// This makes the cache coherent again and this will wait
// until all Terracotta transactions have been acked
// by the server

cache.setNodeCoherent(true);
cache.waitUntilClusterCoherent();

Hence by just using these interfaces one can start using bulk load.

Performance
The sample app attached shows bulk load time reduced from 134 seconds to 10 seconds when bulk loading 100,000 objects.

Advanced tuning parameters
If you want to tune the bulk loading further, then here are some more tuning parameters:
  • ehcache.incoherent.putsBatchTimeInMillis -- Time to sleep for the flush thread between subsequent clearing of the local buffer to server.
  • ehcache.incoherent.putsBatchSize -- Number of elements that will be batched together in a (terracotta concurrent) transaction.
  • ehcache.incoherent.throttlePutsAtSize -- Number of elements that can be in the local buffer beyond which app threads doing put()'s will sleep (until the local buffer size becomes less than this number).
  • ehcache.incoherent.logging -- If true, does some minimal logging (like when cache goes to coherent/incoherent mode etc), useful for debugging.
So to get started please read these steps which will guide you through the Terracotta Express installation. It is pretty simple :)
Express installation steps

Here is the sample code along the ehcache.xml and tc-config.xml
Sample code

Thursday, September 10, 2009

Unix redirection

Well today I am going to blog about the file redirection operators.
2>&1
What does this mean? This command used to confuse me at times. So I will explain about it in this blog.

Well there are 3 standard input and output streams:
0 - Standard input
1 - Standard output
2 - Standard error

"X>&Y" => copy the file descriptor Y to X.
Point to note: this is copy by value (remember this and you will not get confused between commands).

Example 1:

$ some-command > file 2>&1

The above command will redirect both Standard output and error to file.

How?
  • > file implies that redirect standard output to file
  • 2>&1 implies copy the file descriptor of 1 to 2, hence 2 gets redirected to the file as well
Example 2:

$ some-command 2>&1 >file

The above command will redirect standard output to file but standard error will still be displayed on the console.

Why?
  • 2>&1 copies file descriptor of 1 to 2 which would mean to display on console
  • > file implies redirect standard output to file. Hence the standard error on the console.
Example 3:

standard error, output to a file and to console as well
Simply do:

$ some-command 2>&1 | tee file

How?
  • 2>&1 copy fd of 1 to 2.
  • A pipe(|) simply directs standard output from the first command to the standard input of the second command.
  • tee basically copies standard input to standard output.
Hence the result.

Example 4:

If you don't want to see the output of standard error at all. Then simple do the following:

$ some-command 2>&-

Simple enough!!!
Enjoy.

Wednesday, September 9, 2009

Restoring a deleted svn branch

This blog is dedicated to my flatmate who accidentally deleted a svn branch a few days back :)

$ svn delete http://server/repos/enterprise/branches/mybranch -m "Removed a branch accidentally"
Committed revision 10.

So dont panic a branch can be restored back very easily.

$ svn copy -r 9 http://server/repos/enterprise/branches/mybranch http://server/repos/enterprise/branches/mybranch
Committed revision 11.

And your branch is restored.
So don't panic and have fun!!!!


Monday, August 31, 2009

Terracotta Tuning: Part 1

One of the major features of Terracotta 3.0 was the support for Terracotta Striped Array. This removed the limitation of having only 1 Active server in a cluster. This would enable achieve linear scalability in the throughput on increasing the server count.

To get the best out of the Active servers present in the cluster, the load should be distributed among the different Active servers.
So the aim of this blog is to show with an example as to how we can distribute the most used shared objects equally among the different mirror groups in the Terracotta cluster if not already happening.

How the objects are distributed?
To begin with Terracotta has the concept of the transactions, so when we try to create some shared objects it happens within the scope of these transactions. Currently what happens is that the default round robin strategy for object creat
ion makes all the objects created within a single transaction go to a single server. That is all the objects created within a single transaction will reside only on one of the mirror groups.

When will this problem arise and how to verify?
So this issue which I am trying to address in the blog will only arise if the most used shared objects are created within a single transaction. To verify this one can launch the dev console present in the bin bin directory of Terracotta installation. Then the object browser will tell the gid(group id) in which the object is residing. This has been explained in a little more detail later in the blog.

However there is a very simple workaround for this issue.
Let us take an example here:
Consider we have a map like Store which supports the following operations:
1. put(key, value)

2. get(key)
3. remove(key)
The way this Store works is similar to that as a Map would. Thus when a put operation is performed then an appropriate Bucket is selected based on the hash code. Each Bucket hold a pointer to the head of a
linked list and the new key is inserted as the head of the list. So this test program aims at sharing an instance of such a store. The test class has an instance store which will shared as a root in the cluster using Terracotta:

private final Store store = new Store();

The Test class has a run method which just does some puts and gets on this store.
So when this store will be initialized, then all buckets will be created in a single transaction and hence all of the buckets will reside on a single mirror group.


public Store() {
buckets = new Bucket[NO_OF_BUCE
KTS];
for (int i = 0; i <
NO_OF_BUCEKTS; i++) {
buckets[i] = new Bucket();
}

}

So if we start 4 mirror groups and start a client. Then all the buckets will be formed on a single mirror group. We can confirm this by launching dev-console provided by Terracotta. The dev console will be present in the bin directory of Terracotta installation.
On launching dev-console and clicking on the object browser in the le
ft panel, you will see something like shown below:



So if see on the right panel, you will see something like:
0(blog.store.Bucket() [@11011, gid=0]
This implies that this particular Bucket is being stored in a mirror group with group id = 0.
You will also notice that all the Buckets have group id = 0.

This kind of scenario won't be able to extract the best out of the Terracotta striped Array.
So to remove this problem we just need to make Bucket implement a marker interface. When Terracotta encounters this marker interface then it automatically takes care of uniformly distributing this objects of this class across the different mirror groups.

So we just need to add tc.jar present in the lib directory to the classpath and make Bucket implement the interface AAFairDistributionPolicyMarker, something like shown below:

public class Bucket implements AAFairDistributionPolicyMarker

On running the tests again, the Bucket will be distributed uniformly among the different mirror groups. We can verify this by launching dev-console again.



The source code along with the tc-config.xml can be downloaded from:
http://www.easy-share.com/1907575717/src.tar

How to take back up from MAC

Recently my MacBook Pro screen went all black .. Probably some problem with its logic board. Now I had loads of stuff to take back up.
Thanks to Terracotta(the company for which I work) I soon got hold of another Mac. So there is an easy way for transferring stuff from 1 Mac to the other (of which I was not aware of).

Here the step goes:
1. Get hold of a firewire cable. Something like shown below:

2. Connect the 2 Macs with this cable.

3. Then start the mac from which u need to take the back up by pressing the "t" button. This will start your mac in the target mode.

4. After this hard disc will get mounted on the working mac and you are good to move your stuff around.

Simple right.
Apple rocks !!!

Saturday, May 16, 2009

For newbies in MAC

This blog is very very sincerely dedicated to all the guys who are new to the world of MAC, so some useful crap for newbies :)

Well i think the first thing you would face as enter the world of MAC is that where the F*** is the right click (in case you are using track pad.)

Enabling right click
  1. Go to the "System Preferences..."
  2. Click on "Keyboard and Mouse"
  3. Go to the Trackpad tab
  4. Check on the box "Tap trackpad using two fingers for secondary click"
So this will make life much more easier just put 2 fingers on the trackpad simultaneously and you get the right click. Prettly cool !!!
You can also look at the options available on the Trackpad tab and customize accordingly.

Well another small problem is how to lock the screen. Well here we go:

Lock Screen
  1. Go to the "System Preferences..."
  2. Then click on "Accounts"
  3. Then on the left panel you will see "Login Options". Click on that.
  4. Then click "Enabling fast user switching" check box
  5. This will result in an icon in the Apple menu bar.
  6. Clicking on that icon will give you the option of "Login Window..." which in result will lock your screeen
Now we come to making your life a little easier.

QuickSilver
Download Link: http://quicksilver.en.softonic.com/mac
Well u must install this. Lets you open an application or even help you navigate through folders.
Some people though prefer to use Spotlight of Mac but I personally prefer this. The reason is quite simple that i get to see a big icon of the application i want to open which makes things faster. Also if u have a software like "x-lite" and you "xlite", then QuickSilver will help you but not Spotlight. But then SpotLight has its own advantages, so upto you guys :)

Well then so we are ready for open applications so what do we need next a good mail client and a good browser. Well again it depends on prefernce of people but I am most comfortable with Firefox and Thunderbird.

Firefox
Download Link: http://www.mozilla.org/products/firefox/

Thunderbird
Download Link: http://www.mozilla.org/products/thunderbird/

Caffeine
Dowload Link: http://www.versiontracker.com/dyn/moreinfo/macosx/31941
Caffeine is a tiny program that puts an icon in the right side of your menu bar. Click it to prevent your Mac from automatically going to sleep, dimming the screen or starting screen savers.

iTerm
Download Link: http://iterm.sourceforge.net/download.shtml
Are you continously working on different tabs in a terminal often sending the same command to all the terminals. Well if yes then this software might turn out to be pretty useful. Have a look very similar to Terminal of Mac with some good features like "Sending input to all tabs", "Fullscreen", etc. Very useful for Tiger users (Mac 10.4) since the Terminal is not tabbed in that version of Mac.

Well now we move to moving stuffs :) i mean downloading and uploading:

FTP - Cyberduck
Download Link: http://cyberduck.ch/
Very simple interface and easy to use

Torrents - Vuze (Previously Azureus)
Download Link: http://azureus.sourceforge.net/download.php
Searches through some a fixed torrent sites. Pretty good interface.

Download Manager - Folx
Download Link: http://www.macupdate.com/info.php/id/29767
Again very easy to use with a very simple interface

Chatting - Yeah !!!!!
Adium is quite a good option for this yahoo, gtalk, etc works with this and easy to use.
Download Link: http://adiumx.com/

So once you guys are free from chatting, we can move ahead with other stuff :)

Now don't you want to always know what up with your MAC, when the CPU is high, who is hogging all the memory and whats the download and upload happening from your system. You can get all this in a single click. Sounds sensational right :)

iStat menus
Download Link: http://www.islayer.com/apps/istatmenus/
Well this will add everything to your menu bar and you can continuously monitor CPU, memory, etc. Very useful.

PresButan
Download Link: http://alum.hampshire.edu/~bjk02/presButan/index.htm
Do you feel that "Enter" should open a file and not start renaming the file. Well no shortcuts for this and you need to install this.

Bwana
Download Link: http://www.versiontracker.com/dyn/moreinfo/macosx/25078
Do you read manual pages very often? Then why not read it in a browser. Download this then type "man:" on the browser and enjoy. Gives a colored view to make reading man pages much simpler.

Media Player
VLC - what else. A very stable player for all platforms.
Download Link: http://www.macupdate.com/info.php/id/5758

Show Desktop
Download: http://www.instructables.com/id/Show-desktop-in-mac-osx-aka-hide-all/
F11 doesn't satisfy me. Download this to get satisfied ;)

DeskLickr
Download: http://www.apple.com/downloads/macosx/icons_screensavers/desklickr.html
Keeps changing your Desktop by downloading pics from facebook. Keeps me happy :)

PDF Veiwer - Skim
Download: http://mac.softpedia.com/get/Word-Processing/Skim.shtml

NeoOffice
Download: http://www.neooffice.org/neojava/download.php
Free office utilities

Parallels
Download: http://www.parallels.com/download/desktop/
Run windows on mac