Tuesday, January 10, 2012

Relational DB and Objects


Strange observation.

DB's mature over time and adapt to new requirements much easier than code. Code breaks from release to release and after some time needs major changes to keep in shape.

Relational DBs are more Zen compatible - A is A and A is not A. Code is usually not so flexible. More strangely, relational db's are less flexible (schema, everything is table) and ends up being more flexible whereas code is flexible (extend, copy-paste, interfaces, override) and ends up being inflexible.

Wonder, if we could associate code (C, Java, PHP) with tables/columns or joins and write our web applications in SQL.  Immediately all the hashmaps and arrays become moot. No for/while loops just select/where.  It becomes so much easier to create as many views as you like which are consistent by writing new SQL queries.  If queries can be named, they can be used as first level objects for creating higher level queries.  Empty tables that only have code associated with them but no data, can be used for providing all the decoration or access control or mappings.

I haven't seen something like this, but I do think that it is very much possible to build. With all the ORM tools and frameworks we are almost at the point where talking to DB is almost automated. I guess all I want to say is that SQL is probably a good framework for not just managing data, but also code. Lets give it a shot.

Friday, January 06, 2012

The Ambulance Lane

Hardly a day passes by when I don't see an ambulance screaming on the road while coming back from office.  In spite of all the good intentions of the frustrated drivers, most of the time ambulance is stuck with rest of the traffic.

I think one way to make things a little better would be fix say the left most or the right most lane as the virtual Ambulance Lane. The idea is to align the good intentions of people so that instead of randomly deciding how to give way to ambulance, it is pre-decided for them. How does it help? Lets say we decide right most lane to be Ambulance Lane. If you hear Ambulance and you are in the rightmost lane, move to left and make the right lane free.  If you are not on the right lane, make space for vehicles on the right. If you are in the rightmost lane and you can't move to left, honk, put on your parking lights and jump the red light. That is it.

As long as people follow this one rule, I am sure we could help more Ambulances reach hospitals on time.

Thursday, December 22, 2011

Economics of a slow judicial system

Let me go first to to non obvious and we will deal with the obvious later.

If it takes 10 or 20 years for the court to give judgement, who benefits from it? I guess it is the lawyers. The question is, is the judiciary slow or is it the lawyers who use the loopholes of the system to make cases last forever. If judiciary was fast and people didn't fight much in the courts, the only people who stand to loose is the lawyers.  Net income of lawyers is dependent on number of concurrent cases they are handling. To maximize their income, they should make sure that none of the cases they fight reach any judgement, because that is like losing a customer and why would a lawyer want it. Just a thought. No facts.

The obvious part is, even if you committed a crime and have enough money, lawyers will keep the judgement out of the way to let you live free.

This is another instance where demand supply completely breaks. The business depends upon the idea of selling justice, but not delivering it..because the moment it is delivered, no more money can be extracted from the customer.

Wednesday, November 30, 2011

Why power outlets are below the desk?

I have one pain in my life that I go through twice a day. The pain of plugging in laptop cable in the morning and taking it out in the evening. For some reason all carpenters/designers seem to find power outlets hidden below the desk more appropriate instead of providing one over the desk.

The reason is offices or the modern offices were invented in the era of desktops and it made sense to keep all the wires hidden below. Once connected, no one needs to touch them ever. Unfortunately most of world has moved on to laptops, but the modern office design has become a little obsolete. 

Friday, October 21, 2011

Use cases for Cacheismo

Cacheimso is a scriptable in-memory lua object/key value cache, written in c and works on most posix compliant systems. It is based on a simple idea of exposing objects with methods instead of opaque values.

  • Simplest use case would be to use cacheismo as a key value cache, just like memcached. It supports the tcp ascii memcached protocol. No need to specify or tune slab sizes. You would be surprised by improvement in your cache hit rate. This comes from using special memory management scheme to optimize memory usage.  Cacheismo Memory Management 
  • Second use case for cacheismo is when you would like to store server side state which is frequently modified. Typically this is where you would use CAS operations in memcached.  Example could be counters, rate limiting, last N users, etc. If you use memcached for storing session objects, it would be essential to map users to specific machines so that session information is not corrupted because of concurrent modifications to session state. With cacheismo you could keep your session object in cacheismo server and let any app server to handle any user request.  Cacheismo allows creating server side objects in lua scripting language which can be atomically modified by use of get operations on special keys called virtual keys.  Cacheismo running on single core can at max do about 80K get operations per second and this includes running a minimal script on every get operation. Your mileage will depend upon complexity of the script and size of your objects.   Sliding Window Counter Quota With Cacheismo Cacheismo Lua API
  • Cacheismo also supports talking to other cacheismo server from the scripting environment. This is based on two functions getFromServer and getInParallel.  These can be used to create synchronous  replication, proxy functionality to route requests to different servers and for in memory parallel computations.  Cacheismo Cluster Using Cacheismo Cluster For Real Time Analytics 
  • Cacheismo also supports querying for existing keys through scripts. This can be used to create replica of an existing system if the current system needs to be shutdown for any reason. Finding Keys In Cacheismo
  • Cacheismo supports server side consistent hashing. If you find it difficult to update all your app machines when new servers are added, you could use this feature to do seamless upgrades. This comes with a network cost. One hop to the first cacheismo server which finds the right node and second to the right node for the key.