Monthly Archives: August 2013

Spring data -yet another abstraction -quickly getting started

We started with JDBC, then ORM which abstracted the underlying relation DB. Then came JPA -which abstracted the underlying ORM. Now Spring Data

But the kind of versatility we see today in data storage -relational, distributed, nosql and others, to me Spring Data seems to server the purpose.

It abstracts the CRUD for “different” type of data as relational, nosql and just by coding to appropriate interface CRUD operations can be achieved. For getting started use this link for configuring the entity manage, transaction manager -basically the setup stuff.

Write a DaoInterface -here the magic goes, the extended interface decides type of data , relational, nosql etc.

public interface TestDao extends CrudRepository<TestData , Integer> {

And then for CRUD operations use this Interface :

public class TestService{
    TestDao testDao;
 	public boolean saveTestData(TestData testData){
                return true;
    	return false;
	@Table (name="testtable")
	public class TestData {
	    private Long id;
	    public Long getId() {
	        return id;
	    public void setId(Long id) { = id;

I found it simple, yet flexible and power full considering the fact that although projects start with SQL, but down the line NOSQL is definitely on their road map -this abstraction will ensure least throwaway code!

Is amazon micro instance of any worth?

I was attracted by per hour pricing of Amazon cloud hosting – to see how things work out, I decided to give it a try.

The Good Part
The entry level is “micro instance” -free of cost for 750 hrs a month. I quickly calculated 24×30=720 -hmm and it works. It says, it good for small traffic -perfect! I just had couple of visitors per HOUR! Nothing can be lesser than that 😉

Background of my APP -its a enterprise app, CPU intensive and high on DB queries. Wanted to demo a couple of clients so was just looking around for some cheap option and I stumbled upon “Free” option.

And The Bad Part
My excitement did not last longer -I noticed a behavior that for a couple of ‘seconds’ things would work as fast as its locally deployed but just a couple of minutes of continuous usage -and thing would come to grinding halt:(

I would have smelled fishy on my side if I could produce this behavior locally, but I have been running this app in LAB environment for a couple of days without any issue.

I spend couple of hours searching for the root cause and I stumble upon this -Thanks god, it saved me a hell lot of effort! Visit this blog and it’s nicely described how “stealed CPU” is the culprit!

So is micro instance any worth ? Only if you want to get a first hand feel of deployments in the cloud and a pat that “hooo -my app is running in ‘cloud’ “, nothing more nothing less!

For starter and less traffic -use their small instance which as on today comes at .080$ in singapore zone. As explained in the blog-at least it will provide consistent behavior.

HAPROXY up and running in couple of minutes

I tried HAPROXY for my WEBAPP (Hosted on tomcat) -reason for using HAPROXY is that it also supports WEBSOCKETS and my current project uses websockets for server push.
As first step, I tested it with bare bone web application -wow, it’s just so easy, without any hiccups it was up and working in ~30 minutes. I used Linux box as no distribution for windows is available (One can use cygwin) -My previous poston same.

  1. Download HAPROXY , I used version haproxy-1.4.24.
  2. Untar it tar -xvf haproxy-1.4.24.tar.gz.
  3. Build HAPROXY, command “make TARGET=linux26” This is for centos58, Linux kernel 2.6. 26 in “TARGET=linux26″ indicates kernel for linux, if its 2.4 use TARGET=linux24”. As a side note, to know the kernel use uname -a on your linux box.
  4. copy haproxy to /usr/sbin use “cp haproxy /usr/sbin/haproxy”
  5. Create a config file say /etc/haproxy_chandan.cfg:
  6. A mentioned on the HAPROXY site, this is the bare minimum configuration needed -Add it to the config file
        maxconn 256
        mode http
        timeout connect 5000ms
        timeout client 50000ms
        timeout server 50000ms
    frontend http-in
        bind *:80
        default_backend websockets_support
    backend websockets_support
        server ws1 a.b.c.d:8888 maxconn 32
        server ws2 a.b.c.d:8080 maxconn 32
    listen admin
        bind *:8080
        stats enable
  7. Start HAPROXY, /usr/sbin/haproxy -f /etc/haproxy_chandan.cfg
  8. As configured, requests will be handled at port 80 while the admin console for haproxy is 8080

Access your app from http://ipofmachinewherehaproxyisinstalled:80
Access haproxy admin console from http://ipofmachinewherehaproxyisinstalled:8080/haproxy?stats

Thats all. Moving on to configure it for WebSockets and see if it needs additional configuration tweaks or changes -will post.