Tuesday, September 28, 2010

Writing High Performance Software

After working for five years on http proxy, caching, high speed file logging, distributed quota, I believe the following summarizes the results of my experience.

1) Make sure you use all the CPU
2) Reduce your CPU usage

As innocent as they look, they are by no means simple to achieve.  Locks, system calls, network settings, kernel, number of threads, contention, context switches, memory allocation, etc will make it difficult to saturate the CPU.  Reducing your CPU usage is comparatively easy, just use the profiler. This itself is a bit tricky because some profilers will use global locks when collecting data points and we get a perfect example of Heisenberg Uncertainty Principle in action. 

I think of software in three dimensions. Speed, Simplicity and Power. 
Speed       - How fast it runs 
Simplicity - How simple is it to use / maintain 
Power      - The range of problems that can be solved using it 

Think iphone. Think SQL. Memcache has speed and simplicity, but not powerful enough. 

Writing high performance software is fun, but don't forget the simplicity and power aspects of it. If it is not simple and not powerful, most likely no one will care about how fast it runs. If you make it simple and speedy, your target customer set becomes small. Not everyone is solving the exact same problem. Make it speedy and powerful and customers will have tough time using it. They will probably claim it is not powerful, because that power is hidden, not simple enough to use. Make it simple and powerful and not speedy,  customers will compare it with some other product which has high TPS and won't buy. Not that they need the speed, but only to future proof their investment. Every customer feels they will grow and need more and more. 

Overdoing speed, simplicity or power will have some impact on the rest two. Make sure to choose the right combination. 

Sunday, September 26, 2010

Apples and Oranges

Rs 12 is more than Rs 10.
20% growth is better than 18%.
140bhp is more than 120bhp.

It is easy to compare apples to apples. Any one who went to school can understand it. Doing something better than something you have already done is of course  easy to figure out. Study harder and get more marks. Put in more hours and try to get another feature in the release.  Hire more people to get the work done faster. This is natural usage of high school math.

Science or Arts, Medical or Non-Medical, MBA or MS, Job or Business, India or US, stocks or cash. Most questions of life which are worth their salt will force you to compare apples to oranges. Some people tend to be believe they can compare anything using their monitory value.  Well ask them to choose between accelerator, brake and steering.

1  +  1 =  2

1 electron   + 1 proton    = 1 neutron
1 cannibal  + 1 cannibal = 1 cannibal

1 manager  + 2 developers = some work done
2 managers + 1 developer  = don't know
0 manager + 1000's of developers = linux kernel

Math abstracts. It makes us blind to details.  It is good to be blind to details and then it is also bad to be blind to details.  May be you are not dealing with all apples. May be you have few oranges and bananas.
Prerequisite to comparing apples to oranges is realizing you are dealing with not just apples.

Tuesday, September 21, 2010

If Money Expired & people had choice

Money doesn't expires. Its value may decrease over time because of inflation, but it will still work. It may grow if you keep it in bank. But what if money expired...

1) Don't save. Its value will become zero eventually.
2) The only way to survive is by working, by being of value to others.
3) Don't cheat people to extract more money from them. Unless you can use it immediately, having more money doesn't makes you any richer as it will expire.
4) No point in robbing a bank...can't use all the money before it expires

We have two economies working in parallel. The economy of people working, creating value and making life easier on the planet. The second economy is the economy of speculation.  This is what I think causes economic depressions.  I think money is a great invention, but it has its own limitations. Money was intended as a tool to make people help each other now, with belief that they will be helped in future. It is a sane way to make the world exist. 

I believe that money should only do two things:
1) Allow you to use it and expire if you don't use it
2) Allow you to invest and be always at the risk of loosing it. (Loan is not investment)

The third thing is choice. People should always have a choice and more importantly the frequency of choice across all things should be in the same order.  How often can you re-negotiate your salary or your home loan? How often can you change price for your stocks?  In business model terms, it is called install base profit. This happens because people don't have a choice after they make a choice. What if you could buy a car and give it back the next day paying the usage charges? What happens if you could simultaneously work for two/three companies and decide to work each day which company you will work for based on how much money they are giving that day?  The frequency of choice creates great efficiency in the system. What if you could change your vote any day?  Choice makes the demand/supply model work. That is why 5Kg sugar costs less per KG than 1Kg of sugar because what you are trading is your choice. People should have choice and they should be able to exercise it with similar frequency across everything they buy. It is stupid to have stock markets change at millisecond basis, but your home loan fixed for 20 years and your vote for 5 years.

I don't know how to conclude this now.  Capitalism and socialism are not the only options. I think we can make world a better place. We need to push money down at the place it really belongs and bring people up - the place they really belong.

Wednesday, September 01, 2010

Using if

If is very powerful construct of programming languages. Most bug fixes involve adding another "if" or handling the else part properly. Many bug fixes would need adding "ifs" at multiple places. I think of "ifs" as design problem. If essentially means doing something different based on some criteria. If multiple functions needs to check for the same criteria and do something (same or different), then what we are really doing is "adding some functionality" which perhaps belongs to a separate object, to all the places we are adding "ifs". May be what we need is a new object/function to abstract that functionality or perhaps declaring a new interface and adding multiple implementations. Ifs allow us to live with design problem by having special cases, whereas the whole point of design is not to have special cases, just simplicity.


Hindi forces us to think about everything in terms of male and female. TV चल रहा है या TV चल रही है. Kannada and English don't have sounds.  ख, त्त , थ. Punjabi doesn't have very strong notions of half letters. As we keep adding new words to the languages, it would be nice to add new sounds/letters also. Languages we use were invented long, long time ago. May be we should invented new languages which are keyboard friendly, capture enough sounds, have simple grammar,  is easier to learn even for adults, stops forcing us to think in terms of male/female, is computer understandable (avoid NLP) and perhaps easy to work with Text-2-Speech & Speech-2-Text converters.