Friday, August 3, 2007

Programming Lessons on Western Railway - Multiple threads and performance

Western Railway in Mumbai has 4 tracks - slow Up, slow Down, fast Up and fast Down. In order to provide a fast service to passengers in various areas, Western railway has some trains which are slow between Borivli and Andheri and fast between Andheri and Churchgate. There are trains which start or terminate at Andheri and are slow between Andheri and Bandra.
Conditions of passengers at intermediate stations can be very difficult; so, Western Railway has special trains which, e.g. start at Goregaon and are slow up to Andheri and fast after that.
A programmer will see an obvious design concern. These threads will need to be synchronized. Will there be a problem? Every day and night, I experienced the problem. The train would halt and we wait. The design problem was even more severe. To switch between slow and fast tracks, the train had to cross a track with traffic in the opposite direction. More the traffic as at peak hours, worse the synchronization delays.
My brain had nothing else to do during the seemingly endless delays except dream of a different design. If the mind was occupied, the claustrophobia of being surrounded by a mass of humanity seemed less.
My ideal solution - in another post.

Daydreaming - I wish I were a Superman

I read in the morning paper that a SUV didn't stop for a cop and carried him a couple of kilometers. The cop is seriously injured. On the inside page, the story is that a cop is suspended for asking for a bribe for a traffic violation.
As I am crossing the road, a lunatic runs through the red light. I scramble across the road but how I wish I were Superman. I would have stood still and enjoyed the look on the driver's face as his car would have been crushed like a piece of paper after the collision.
Well, even if we can't do anything about it, at least we can daydream:)