Tuesday, November 16, 2010

Happy 2nd Birth Day ....

I am not there with him today, the mom is. And though he would have some fun for sure, I am going to miss all of that... :(

wish you a happy birthday remotely...

Monday, November 15, 2010

scripts and hash bang ( #! )

More often than not, people have to tell the unix shell / perl scripts or other programs where lies their interpretor, e.g. write their command line calls as 

perl SomeScript.pl

or 

ruby ARubyProgram.rb

or 

sh SomeShellScript.sh

this is because the system may not be aware of the location of the the executable interpreter of the exact type that needs to be used for the corresponding script.  Well, for this purpose, windows has the file extension association concept, but we are dealing with Unix like systems not windows, so that option is not really available to us (besides, there are ill effects of that convention too, but lets not go in that discussion).

So, to tell a unix program where to find its interpreter, besides launching the script along with it on command line, there is another way, and rather beautiful at that.

Just put the exact path of your interpreter executable at the very first line of your script preceded by these two magic characters, a hash and an exclamation (#!) also called as hash-bang or shebang.  Now, once your script is marked as executable (see chmod), you are good to go, no need of putting explicit calls to the interpreter to run your code.

Basically, your code should now look like this - 

#!/usr/local/bin/perl5
print "testing hashbang with raghav"

Save this short script as aa.pl (assuming that your system has perl 5 interpreter installed in the location I used). Make the script executable (chmod) and you can just launch the script, like ./aa.pl  instead of earlier example perl aa.pl

A word of caution though, these magic characters have to be absolutely the first and second character of the file, no exceptions to that. Else, the system cant make out the special meaning of this and the purpose is lost.

Pretty neat.. hunh...

Tuesday, November 9, 2010

Experience with Air India - 2

The return flight from Delhi to Bangalore, on the evening of Sunday 7th Nov 2010, turned out to be the most horrible flying experience I have ever had, till date.  The flight was AI-622, bound to fly out from T3 at 2010 hours 7th Nov.

When I reached at the airport, the check-in area was a mess in itself.  The Air India staff had invited all the passengers to check-in from all the counters, basically creating a mess of a situation. When they realized what they have done, they scrambled to a fix, and started calling out to the people for whom the flights were about to depart (and these ppl were still stuck in check-in queues).

When these people were taken away, my checkin process suddenly looked easier and faster.  Basically, I was all checked in at around 6:45 and inside the boarding gates area by that time.



The display panel had no mention of my flight but other flights both domestic and international, before and after my flight were listed properly, with whatever status applicable to them.  When inquired, they said, it was ok, not to worry, and told me of my gate no for boarding (also that the flight was on schedule).

By 7:25 pm, the boarding should have begun, but there was no air india official to be seen around the gate till that time, or even later, till 2000 hrs.  I think thats when I begun to think, that something was wrong.  I went to the info desk and asked the person there, he had no information.

Slowly people started assembling around the gate and asking questions. There was nobody to answer them. Slowly the mob mentality was becoming visible. People shouting, grabbing whoever was visible in an air india garb, or with some kind of airport office link.

Initially, someone caught hold of a lady, fairly senior (by age i mean), and started asking her questions. She DID NOT know anything. Someone said that she was the duty manager, and this angered people even more.  

By now, it was well past 2100 hrs and still nobody had appeared on the assigned gate.  Then people caught hold of two air india officials who were just passing by. The mob really got angry and wanted answers.  The two guys were so visibly helpless they couldnt do anything.  Ppl asked them to call up the responsible officials, but none of the officials were picking up their phones.  Then one passenger asked for the officials' number and called from his own mobile. The official did pick up the phone, but, still couldnt offer any answers to the situation.

Slowly a pattern was emerging out of the situation. No flights scheduled to leave after 1900 hrs or so were taking off. Flights to Bangalore, Chennai, Kolkata, Mumbai and Dubai were in this unknown situation. Some people for bangalore flight were waiting since 1100 in the day since their 1300 flight was cancelled and they were bumped up to this 2010 flight.  Effectively they were the worst hit guys, waiting for about 10 hrs already.

Finally, the mob started walking with this official, demanding to be put in touch with the officials face to face, nothing happened, since the passengers are not allowed to leave the boarding area after check-in. People were diverted to another official at another gate, who could not answer any questions anyway.

By now, it was already 2300 hrs, and still no answers. It was pretty chaotic, since nobody knew whats the status of the flight, and whats going to happen.  There was some infants among the passengers. Their parents were the more anxious lot. A Danish national got migraine attack during all this chaos. There were at least 10 people who were over 70 yrs old, and the waiting process was not helping them at all, let alone the uncertainity.
As it turned out, around 2330 there was announcement of the cancellation the bangalore flight.  It just broke some patience barriers. People started shouting at the info desk guy, since he had not been advised about the next steps for the passengers.  

He made a few phone calls and a lady appeared.  This lady tried to offer some hope, but it was a failed attempt. People had realized by now that air india has no intention of flying the people to their destinations and it would be a cancelled flight for good. They are just not announcing it in good time so that they wont have to pay the passengers' hotel stay etc.

They still had no clue around the solution to the problem.  Now a new face appeared, Mr Nalin. He claimed to be in an executive authority and wanted to fix the problem for good. He promised a special flight to Bangalore at 0145 hrs in the night. After making some other promises, he went off. Nowhere to be seen again.

People thought that they have been conned again.  By now, its already 0015.  Suddenly, people caught hold of two female officials in air india garb. The poor girls didnt know anything but were shouted at anyway.  A new face appears now, Mr Pankaj, supposedly GM of Air india.

He was shouted at all possible ways. Everybody was venting his anger on him, but guy showed remarkable patience and didnt react even once. We were thinking, had he reacted even once, god knows how the mob would have acted/reacted.  I would say, he was not physically handled, barring that, all possible ways were used to vent anger at him.

Finally, he started moving some things, the officials started appearing. He found a crew for one of the flights, and then another crew came in.  Some more officials came in, a lot of CISF people showed up. Apprantly to handle the situation if the mob went physical with him.

Already 0100 hrs and no sign of boarding activity. Mob had not let him go anywhere, so he announced that the bangalore flight will leave "if not 0145 perhaps by 0200 or 0215".  Another 30 minutes passed by, and now the mob was on the brink.  A gentleman, father of two young kids, literally charged at him, wanting to know when the flight would actually go.  

Now he says, 0300. And this was genuinely interesting, the guy asked Mr GM, what would you do if the flight does not depart by 3 AM... the GM guy had no answer, literally tense face, sweating brows, no voice. 

Finally, around 0255 there was an announcement for boarding for the bangalore flight.  A decent 7hrs 30 mins delay, and I am sure, had the people not been so vocal and demanding, the flight would never have been arranged and we got home the way we got home.

At the end, the flight, which should have landed bangalore 2240 the previous evening, now landed past 0600 the next morning, spoiling the next day for everybody, more so for the working passengers.

Someone rightly spoke, "this is my last flight with air india, never again". Well, I am with the group who says, "never say never", but for once, for this one I feel like agreeing with him. Never Again with air india, or at least till the wounds are fresh :)

Experience with Air India - 1

It was not my first time flying with air india, perhaps 2nd or 3rd, but its going to be the last one, at least these are the emotions rights now...

I booked this round trip in october last week, attempt to go home for Deepawali utilizing the long weekend.  It was a Bangalore - Delhi - Bangalore round trip, and I was pretty excited to have clinched this deal.

Flying out to Delhi from Bangalore was already giving indications of trouble with Air India.  When I reached airport, they had already cancelled my flight.  Later I got to know that they had in-fact merged my flight with another flight, which was an international flight, coming from somewhere. The fact was, almost nobody was certain whats the situation. On the check-in counter, I was told that my seat was not confirmed yet, was on standby. Luckily, it was confirmed within the next few seconds itself, and I had a seat (which I realized later, was the last available seat on the flight).

The flight was delayed by about half an hour was another fact. During the waiting period, I met a few passengers, who were waiting since 4-5 hours since another afternoon flight was delayed and the passengers were supposed to leave together on this flight.

Inside the aircraft, we were welcomed by two angry air hostesses, and a third one relatively better.  Mis-management was rampant there too. Ground staff had put in some stuff meant for passengers cabin luggage and the air hostesses were having hard time accomodating passengers' luggage.


Once I got to my seat, I found out a few more things. The hand rest of the seat was taped using cello tape, or else it would just come out into your hands. Later during the flight, one of the overhead lights came out into the hands of of the passengers when she was trying to refocus the beam.  All in all, the aircraft looked like from stone age,  not withstanding the fact that they didnt have aircrafts in stone age :) .

Eventually, we reached delhi airport, but were informed that we would land on the newly built-operationalized terminal (known as T3).  While going to the baggage claim area through a bus, we could actually see labour working here and there. Basically, it was evident that construction work is not over.

The baggage claim belt didnt start until about half an hour after our arrival in the lounge. Some passengers had literally shouted out to get some air india officials around there and take some action for that.

At the end, it turned out, the new terminal is really still new for the people also, and they have issues synchronizing everything. 

It turned out that the whole ordeal took about 2 hours extra than the normal.

Sunday, October 31, 2010

A Note to New Consultants

I  am about to start a new role, that of a consultant at a new customer site soon. In order to prepare for that mentally, I was looking around for inspiration and advice. In the process, I stumbled across this gem from the founder of Boston Consulting Group.  I have picked up the text from this webpage(http://www.careers-in-business.com/consulting/hendnote.htm), and then tried to see through it from my own eyes.  All credits with the original webpage owners.

Written by Bruce Henderson, Founder of Boston Consulting Group in the 1970s

In a sense the consultant's role is a paradox. He gives advice to people of equal intelligence who have vastly superior and extensive experience and knowledge of the problem. Yet he is not necessarily an expert in anything. What is the justification for his value?

       Need of Consultant
  1. The consultant can function as a specialist or expert, In this role he must be more knowledgeable than the client. This implies a very narrow field of specialization, otherwise the client with his greater continuity of experience would be equally expert.

    The consultant can function as a counselor or advisor on the process of decision making. This implies an expertise of a special kind, that of the psychotherapist. This is merely a particular kind of expertise in a particular field.

    The most typical role for a consultant is that of auxiliary staff. This does not preclude any of the other roles mentioned before, but it does require a quite different emphasis.

    All companies have staff capabilities of their own. Some of this staff is very good. Yet no company can afford to have standby staff adequate for any and all problems. This is why there is an opportunity for consultants. They fill the staff role that cannot be filled internally.

    By definition this means that consultants are most useful on the unusual, the non-recurring, the unfamiliar problem. Outside consultants are also most useful where the problem is poorly defined and politically sensitive, but the correct decision is extremely important. Outside consultants get the tough, the important and the sensitive problems.

    The natural function of a consultant is to reduce anxiety and uncertainty. Those are the conditions under which anxiety and uncertainty are greatest and where consultants are most likely to be hired.

    Problem Definition
  2. If this point of view is our starting point, then problem definition becomes extremely important.
    • If the problem is incorrectly defined, then even its complete solution may not satisfy the client's perceived needs.
    • If the problem is improperly defined, it may be beyond our ability to solve.
  3. Problem definition is a major test of professional ability. Outside consultants can frequently define problems in a more satisfactory fashion than internal staff, primarily because they are unencumbered with the historical perspective of the client and the resulting "house" definition.

    A consultant's problem definition is the end of the assignment if the problem is not researchable. If the problem is not researchable, then the consultant is either a specialist-expert or a psychotherapist. Neither of these roles are suitable for the use of the resources of an organization such as The Boston Consulting Group.

    A researchable problem is usually a problem that should be dealt with by a group approach
    . Data gathering and analysis requires differing skills and different levels of experience that can best be provided by a group. The insights into complex problems are usually best developed by verbal discussion and testing of alternate hypotheses.

    Good research is far more than the application of intellect and common sense. It must start with a set of hypotheses to be explored. Otherwise, the mass of available data is chaotic and cannot be referenced to anything. Such starting hypotheses are often rejected and new ones substituted. This, however, does not change the process sequence of hypothesize / data gathering / analysis / validation / rehypothesize.

    Great skill in interviewing and listening is required to do this. Our client starts his own analysis from some hypothesis or concept. We must understand this thoroughly and be able to play it back to him in detail or he does not feel that we understand the situation. Furthermore, we must be sure that we do not exclude any relevant data that may be volunteered. Yet we must formulate our own hypothesis.

    Finally, we must be able to take our client through the steps required for him to translate his own perspective into the perspective we achieve as a result of our research. This requires a high order of personal empathy as well as developed teaching skills.

  4. The end result of a successful consulting assignment is not a single product. It is a new insight on the part of the client. It is also a commitment to take the required action to implement the new insights. Equally important, it is an acute awareness of the new problems and opportunities that are revealed by the new insights.

    We fail if we do not get the client to act on his new insights. The client must implement the insights or we failed. It is our professional responsibility to see that there is implementation whether we do it or the client does it.

    Much of the performance of a consultant depends upon the development of concepts that extend beyond the client's perception of the world. This is not expertise and specialization. It is the exact opposite. It is an appreciation of how a wide variety of interacting factors are related. This appreciation must be more than an awareness. It must be an ability to quantify the interaction sufficiently to predict the consequences of altering the relationships.

    Consultants have a unique opportunity to develop concepts since they are exposed to a wide range of situations in which they deal with relationships instead of techniques. This mastery of concepts is probably the most essential characteristic for true professional excellence.

    A successful consultant is first of all a perceptive and sensitive analyst. He must be in order to define a complex problem in the client's terms with inadequate data. This requires highly developed interpersonal intuitions even before the analysis begins.

    His analytical thinking must be rigorous and logical, or he will commit himself to the undoable or the unuseful assignment. Whatever his other strengths, he must be the effective and respected organizer of group activities which are both complex and difficult to coordinate. Failure in this is to fall into the restricted role of the specialist.

    [raghav] The first time I have read that a specialist role can be restrictive, and honestly, when you think about it again, it does come back as a correct statement, specially in the wider world of other opportunities. Specially for a management consultant.

    In defining the problem, the effective consultant must have the courage and the initiative to state his convictions and press the client for acceptance and resolution of the problem as defined. The client expects the consultant to have the strength of his convictions if he is to be dependent upon him. Consultants who are unskilled at this are often liked and respected but employed only as counselors, not as true management consultants.

    The successful professional inevitably must be both self-disciplined and rigorous in his data gathering as well as highly cooperative as a member of a case team.

    The continuing client relationship requires a sustained and highly developed empathy with the client representative. Inability to do this is disqualifying for the more significant roles in management consulting.
In other words, the successful consultant:
  • Identifies his client's significant problems;
  • Persuades his client to act on the problems by researching them;
  • Organizes a diversified task force of his own firm and coordinates its activity;
  • Fully utilizes the insights and staff work available in his client's organization;
  • Uses the full conceptual power of his own project team;
  • Successfully transmits his findings to the client and sees that they are implemented;
  • Identifies the succeeding problems and maintains the client relationship;
  • Fully satisfies the client expectations that he raised;
  • Does all these things within a framework of the time and cost constraints imposed by himself or the client.

Thursday, October 7, 2010

Thursday, September 30, 2010

my experiments with solr :)

Its a catchy title, but yes.. thats what I am going to talk about...

I came across hadoop, when I was looking for a new solution for one of our in-house projects. The need was quite clear, however, the solution had to be dramatically different.

The one statement we received from business was, "We need an exceptionally fast search interface". And for that fast interface to search upon they had more than a hundred million rows worth of data in a popular RDBMS.

So, when I sat about thinking, how to make a fast search application, the first thing that came to my mind was, Google. Actually, whenever we talk about speed or performance of web sites, Google is invariably the first name that comes across.


Further, Google has a plus point that there is always some activity at the back end to generate the page or results that we see, its never static content. And, then, another point, Google has a few trillion pieces of information to store/index/search whereas our system was going to have significantly lower volume of data to manage.   So, going with that, Google looked like a very good benchmark for this fast search application. 

Then I started to look for "How Google generates that kind of performance". There are quite a few pages on the web talking about just that.   But, probably none of them has the definitive/authoritative view on Google's technology or for that matter the insider's view on how it actually does what it does so fast.

Some pages pointed towards their storage technology, some talked about their indexing technology, some about their access to huge volumes of high performance hardware and what not...

For me, some of them turned out to be genuinely interesting, one of them was the indexing technology. There has to be a decent indexing mechanism to which the crawler's would feed and the search algorithms hit.  The storage efficiency is probably the next thing to come in the play. How fast can they access the corresponding item ?

Another of my observation is that, the search results (the page mentioning page titles and stuff) comes real fast, mostly less than 0.25 seconds, but the click on the links does take some time.  So, I think it has to be their indexing methodology that plays the bigger role.

With that in mind, I sat about finding what can do similar things and how much of Google's behaviour they can simulate/implement.

Then I found Hadoop project on apache (http://hadoop.apache.org/) which to a large extent reflects the way Google kind of system would work. It provides distributed computing(hadoop core), it provides a bigTable kind of database (hbase), provides map/reduce layer, and more.  Reading into it more, I figured out that this system is nice for a batch processing kind for mechanism, but not for our need of real time search.

Then I found solr(http://lucene.apache.org/solr/), a full text search engine under Apache Lucene.  It is a java written, xml indexing based genuinely fast search engine.  It provides many features that we normally wish for in more commercial applications, an being from apache, I would like to think of it as much more reliable and stable than compared to many others.

When we sat about doing a Proof of Concept with it, I figured out a few things –

•    It supports only one schema, as in, rdbms tables – only one. So, basically you would have to denormalize all your content to fit into this one flat structure.
•    It supports interactions with the server interface only through http methods be it the standard methods get/put etc or be it REST like interfaces.
•    It allows you loading data in varying formats, through xml documents, through delimited formats and through db interactions as well.
•    It has support for clustering as well. Either you can host it on top of something like hadoop or you can just configure it to do it within solr as well.
•    It supports things like expression and function based searches
•    It supports faceting
•    Extensive caching and “partitioning” features.

Besides other features, the kind of performance without any specific tuning efforts made me think of it as a viable solution.

In a nutshell, I loaded around 50 million rows on a “old” Pentium-D powered desktop box with 3 GB RAM running ubutnu 10.04 server edition (64 bit) with two local hard disks configured over a logical volume manager.

The loading performance was not quite great. Though its not that bad either. I was able to load a few million rows (in a file that was sized about 6 GB) in about 45 minutes when the file was on the same file system.

In return, it gave me query performances in the range of 2-4 seconds for the first query. For subsequent re-runs of the same query (within a span of an hour or so), it came back in approx 1-2 milliseconds.  I would like to think that its pretty great performance given the kind of hardware I was running upon, and the kind of tuning effort I put in (basically none – zero, I just ran the default configuration).

Given that, I wont say that I have found the equivalent or replacement of Google’s search for our system, but yeah, we should be doing pretty good with this.

Although there is more testing and experimentation that is required to be able to judge solr better, the initial tests look pretty good.. pretty much in line with the experiences of others who are using it.