May 30, 2008

Learning to Program all Over Again

This is just a jotting down of thoughts I have been having for the last couple of weeks. Had an interesting discussion with Pandu on this last evening and I thought it would be valuable writing down some of the key takeaways. Most of this is early thinking, but I think that as programmers, all of us need to start thinking hard about the issues below and start figuring our way around them.

1) Learn the trade-offs all over again: The CPU is getting cheaper and would continue to do so at an ever increasing pace as transistor density continues to increase. However, while disk capacity is getting cheaper and would continue to do so, disk IO is not getting any faster. While IO has always been the big bottleneck , with CPUs getting more powerful, more and more workloads would become IO bound. Thankfully Flash provides some reprieve here and as hybrid disks and pure Flash storage gets mainstream, IO contention should reduce. But to take advantage of Flash, we would need to design apps which are Flash aware so that you can keep the hotter areas of your data on the Flash storage while the colder ones go on magnetic storage. A much harder problem is the memory wall - the access to memory is not getting faster and as CPUs get more powerful, all that computing power would end up waiting on memory. There are no hardware solutions to this, so it boils down to better caching and being super aware of data locality. So when you design a app next time, think about the trade offs all over again - CPU is cheap, code needs to be Flash aware and design for better caching and locality.

2) Learn to Parallelize Code: I have written and talked about multi-core several times, and it always surprises me to see people getting surprised when they learn that their apps would need to be re-written to take advantage of the next set of chips. All that cheap computing power in the previous point is not easy to harness because it would be distributed across multiple cores. To take advantage of these cores, your code would need to be parallelized. This needs to happen on both client side and server side:

a) Server-Side: While server-side workloads are mostly parallelized already thanks to the transaction model on databases for stateful workloads and the atomic request-reply model in the web-server stateless model, we do have a problem is on the business logic code. As your web-server hands over a request to a business logic component and it does its computation, there are other requests waiting to be serviced by the same business logic component even as a CPU core lies idle.

b) On the client, the situation is worse - all UI is done using one thread. And while some apps use the background worker thread approach, even there most of the apps tend to use a single thread only. Now on the client again, the CPU is not getting any faster, but more and more slow ones are becoming available. So for your app to take advantage of the new hardware, it needs to be parallelized.

So irrespective of whether you are on the server or the client, you need to re-write your code. I had posted on some of what you can do earlier over here. Since then, Microsoft has launched a full fledged Parallel Computing Developer Center which is a great resource to learn the issues and how to address them.

3) Learn to Work with Offline Data: While bandwidth cost is getting cheaper and coverage is increasing, the fact is that it is flaky - sometimes you have a lot of it, sometime you have none at all. Also, there are other points of failure in the system and there is no chance that you would have the latest, correct data all the time. This has two consequences:

a) From a client side perspective, since the expectation is that with pervasive connectivity, you can be online anytime, connected apps is the way to go. However, the flakiness also means that you need to work offline. That means storing data locally and sync-ing it with the online service depending on bandwidth availability. This would at times lead to issues - the pricelist on the tablet PC of the sales guy may change while he makes a transaction based on the data he has. Offline data is not friendly towards consistency, but availability. And a business would rather make a system more available, even if it means that sometimes business transactions would happen on wrong data which would require compensating actions.

b) From a server perspective, since your app and data would be residing in the Cloud, spread over several boxes, maybe several datacenters, changes to data would happen in different places at different points in time by different activities. So the change in inventory for example would need to be propagated and since bandwidth is flaky and boxes would go down, you would need to take the decision on the current inventory level based on the data that you have, and not some global version of the inventory. At some point in time, the data would sync and it would be figured that some transactions happened on bad data and these would need to be compensated again.

This model of working with data you have (I am calling this offline data for the want of a better word) in an optimistic way hoping that the data is correct, syncing at some later time in point, figuring out the inconsistencies and then dealing with them is increasingly going to be a complex problem all App architects would have to solve. While there is some technology to help - ADO.net Sync Framework, Workflow Foundation and Communication Foundation come to mind - the business logic of detection, deciding on the compensation and carrying out the compensation would need to be designed in the biz-logic of the app.

4) Learn to Slice up the App: The point on data above leads to a bigger point on slicing up the app in general. The first level of slicing is on having an offline semi-connected client. The second level of slicing is on the server-side. Some of the server-side functionality would need to be in the Enterprise datacenter where your app may need to talk to some of the other systems. Some of the functionality would need to go to the Cloud - mostly areas where you need infinite scaling and 100% uptime. This leads to questions on what should be the boundaries, how do you come up with the boundaries, how does the communication happen between the boundaries, etc. So how we slice up the apps is a huge issue, and we all need to find our feet when it comes to this. I have some thoughts on this, but over here I basically want to highlight the issue and not discuss possible approaches - that is a topic for some other post in future.

So those were the major points in my mind on the challenges ahead and skills we would need to acquire to address these challenges. Obviously, various technologies would also evolve to help solve these issues - new languages, new algorithms, new frameworks, new design patterns .. I think the way to go would be declarative - state your intent and let the runtimes handle stuff for you. Also it would be mostly model-led. Lots of new stuff to learn - it never gets too dull here!

May 9, 2008

Web Innovation Conference 2008 - Mumbai

 

Just got back to my hotel room from the Web Innovation Conference 2008, and despite being really tired, I am feeling quite happy since this was one of those rare conferences that I really enjoyed - both as a sponsor and as an attendee. The crowd was quite diverse and knowledgeable and I had a lot of very lively conversations with decision makers, developers, designers and marketeers from our customers and partners.

My key takeaway was that in India, people are doing some great work, have great ideas and are truly excited about converting them to reality. This was most energizing. What was also very heartening was to see the buzz and excitement around Silverlight. Almost everyone whom I spoke with (and I must have spoken to at least 50-60 people thru the day) was quite impressed by the capabilities of Silverlight and wanted to find out what more could be done with it.

But most of all, I think I would remember this conference for making some new friends - met Amuleek Bijral from RSA after several years and it was fun catching up, had a great discussion with Amit Somani from Google on various aspects of cloud computing and hardware trends, the state of computer science research and a shared respect for some of the greats in the field, and had a lot of discussions with Bhavin Turakhia from Directi on a thousand interesting topics - I think we could have gone on for a couple more days without a break and without repeating a subject. All thanks to Kaushal Karkhanis who got us to talk on WPF vs. AIR on camera and then ran out of space as we just went on and on!

Great fun and very energizing!!

May 3, 2008

Getting Started with Google App Engine - Part I

 

I have a new found interest in Cloud Computing, and the first attack is on the Google App Engine. Didn't exactly get off to a flyer:

1) Limited beta - they are going to send me a mail on my GMail account on when I can start using it. But I can start right away by using the SDK.

2) Downloaded the SDK and ran the installer - damn! Requires Python - go download separately!! This is ridiculous - why can't they bundle it with the installer?

3) Now I am on the Python site and see a set of versions - do I install the latest version? Not sure, let me run the installer again ... ok, it requires 2.5 from Python.org or from activestate. Would 2.5.2 work? Not sure. Wish they could have given a page with a link rather than a modal dialog!

4) Downloading Python-2.5.2.msi from http://www.python.org/download/ - it is 10 MB. Went to ActiveState and after 10 odd clicks, I now have to fill up a form... I think I am going to download the python.org version - AppEngine cannot be using ActiveState specific extensions.

5) Download started - need to learn Python now ... next step, download the documentation from http://docs.python.org/download.

6) Python compiler installed. Now running the installer .. it is Vista ready, but not signed yet .. makes sense, bits are in beta. Installed smoothly.

7) Ok, now to figuring out what this stuff is. http://code.google.com/appengine/docs/ talks about a Python runtime, a datastore, users API, URL Fetch (sounds like a REST consumer) and a mail API - not bad, got this piece.

8) Finally, how to work with this - http://code.google.com/appengine/docs/gettingstarted/ basically says that there is a dev web-server which I think will run locally and a utility to upload code to the Google cloud. The web-server seems interesting - it is an emulation environment for the cloud infra. Can I use it without the invite? Seems I can!

9) Now reading http://code.google.com/appengine/docs/gettingstarted/helloworld.html - so the idea is that you write your code in python, describe the app environment using app.yaml (that obviously uses the YAML syntax) and then start the dev web-server with the path to your code. Pretty simple, eh? The URL - http://localhost:8080 is hardcoded, but that's ok.

10) My next question - where is the web framework - is answered in http://code.google.com/appengine/docs/gettingstarted/usingwebapp.html. So any CGI targeting framework written in pure Python would work. You got to upload the framework along with the app ... hmm, that keeps things simple for AppEngine while giving a choice to Python toting devs. The other choice is to use the AppEngine supplied framework called webapp. Since I do not know any Python based framework, I think I am going to use this. Not sure of what Python devs would typically use. I have heard of Django and Zope.

11) Finally went thru the links in http://code.google.com/appengine/docs/python/ and this gives me a decent idea of what this environment is like. It is a simple programming model and I think that is a strength, though having to learn Python may dishearten your average dev.

So I think what I am going to do next is to maybe write a bunch of simple apps on the local dev-server and pick up Python while I wait for my AppEngine invite. This is cool - I wanted to learn a new language anyway and AppEngine forces me to learn Python which I can also use for SL 2 demos!