Sunday, December 31, 2006

Tracing in .Net

We have all gone through our debugging days - whether it was using ddd or gdd, or all those printlns in the code, or, as Visual Studio got more commonly used, watches and the F* buttons.

This article talks about tracing - a form of debugging that allows us to keep track of the health of our applications. We see how tracing is implemented in .NET, and how we can implement our own tracers.

The Basics

.NET provides Trace Listeners, which are objects that receive the trace output and output it somewhere; that somewhere could be the debug window in your development environment, a file on your hard disk, a Windows Event log, a database, or any other customized data store.
A Trace Listener passes on tracing information from your application to the output store.

The System.Diagnostics namespace provides two classes named Trace and Debug that are used for writing errors and application execution information in logs. Only methods of the Trace class become part of the release build code, providing you the ability to track and record the health of your application. When you create a new project in Visual Studio, you need to define the DEBUG and/or TRACE symbols, as required.

.NET Trace Listeners

.NET provides 3 Trace Listeners: DefaultTraceListener (outputs to Debug window), TextWriterTraceListener (Outputs to file) and EventLogTraceListener (outputs to the Windows Event log). The Trace Listeners provide methods to output the trace information, flush the buffer and close the output stream.

The following piece of code demonstrates how a TextWriterTraceListener can be used in your application:

FileStream myLogFile = new FileStream("D:\\MyLogFile.txt",FileMode.OpenOrCreate) ;
TextWriterTraceListener myTraceListener =new TextWriterTraceListener(myLogFile) ;
Trace.Listeners.Add(myTraceListener) ;
Trace.WriteLine("Hello - this is our trace message") ;
Trace.Flush() ;
myLogFile.Close() ;

Note: Event Logs are not recommended for most tracing scenarios, since the log tends to get quickly filled up if you are not careful. Event logs should typically be used for errors and more determined forms of tracing, such as messages from Windows Services.

Changing Trace Listeners

Instead of hard coding the type of trace listeners into your code, however, you can add or remove them through the .config file of your application (applicationname.exe.config for Windows Forms application, web.config for ASP.NET). The element in the config file is where you can add and remove any or all listeners.

Trace Switches

Trace switches allow us to control the operation of the Trace Listeners at run time. These objects can be controlled by an application's configuration file, eventually eliminating the need to change, compile and distribute our code each time we want to change the tracing behavior.

The BooleanSwitch is a kind of on/off switch which can be either enabled or disabled. The TraceSwitch, on the other hand, allows us to control the levels at which tracing can be enabled. This allows our code to check what type of messages to send to the listeners.

Implementing our own Trace Listeners

To implement our own trace listener, we need to derive from the TraceListener base class. At the very least, each inheritor of this class must implement the Write and WriteLine methods.

A typical Trace Listener to implement would be one for writing into a database. Your implementation should also provide for specifying maximum number of trace messages to hold in local cache before flushing to the database - you definitely do not want to open a connection to the database everytime you write a trace message!

Tracing in ASP.NET

.NET also provides powerful tracing mechanism for ASP.NET applications, adding tremendously to your ability to figure out what's going wrong without resorting to those dozens of Response.Write statements that later need to be removed.

The System.Web.UI.Page class provides a Sytem.Web.TraceContext object in the Trace property. The Trace object can be considered as an intrinsic page object, similar to Request, Response and Server. TraceContext class is also accessible through Control.Context.Trace property. This allows us to include trace statements in custom server controls, or when we want to include trace statements from outside the ASP.NET page, for example, from the global.asax file.

ASP.NET provides two types of tracing: page-level tracing and application-level tracing.

Page-level tracing can be enabled by setting the Trace attribute of the @Page directive to true. You can add as many trace messages to the page as you want, allowing you to print out a host of information including cookies, and server side variables. Once you are done, simply turn the Trace attribute to false, and all tracing will be disabled!

However, page-level tracing is cumbersome and does not serve the purpose fully when working on a real application - you need to setup every page individually. ASP.NET therefore provides application-level tracing, which can be enabled in the web.config file of your web application by using the node. If you want to see all the traces that ASP.NET has recorded, you would have to browse to the trace.axd file in that application.

Performance Implications for ASP.NET tracing

Tracing can severally affect ASP.NET application performance. If you want to use tracing in deployed ASP.NET applications, then consider using the classes found in System.Diagnostics namespace - we can fully utilize those classes in our ASP.NET applications.

IT Predictions for 2007

Life changed a lot for the IT professional in 2006 - Ajax changed from cool to essential, Vista slowly concretised into an image from the blurred vision of early 2006, and Avalon and Indigo finally joined the TLA bandwagon, making IT professionals much more comfortable in discussing them!

So what does 2007 hold in store for us? Here are some outrageous predictions based on neither facts, nor research, nor a deep understanding of the core issues...

1) Vista will be highly acclaimed by engineers, but will be shunned by buyers, until Miscrocoft goes for a drastic price reduction.
2) SQL Server 2005 will be the database of choice for most SMEs and SaaS providers, with IE 7 and .NET 3.0 being the platform of choice.
3) Google will get into the television and media advertising market, changing focus into a media company.
4) Google Enterprise platform will be a big failure, and get converted into an open/free source community showcase with no other application in the commercial world.
5) Google will move it's data centers to Canada or maybe even the Arctic! Yahoo and Microsoft will follow suit.
6) Microsoft Live.com will fail to take off. So will Virtual Earth and Map Point, till Microsoft makes it free to use.
7) Ruby on Rails will be a serious contender in University projects - but not in the commercial space
8) Microsoft will tie up with Sun - sounds outrageous?
9) Intel will get a major boost because of Vista 64 bit
10) SaaS will come to mean "renting out software deployed in your captive data center"
11) Virtualization will be big, and a critical component of any web based software delivery model

Sunday, December 03, 2006

Lofty Goals and Impractical Targets

From 60M to 100M, and then on to 200M. Our targets are aggressive and positive, but are they achievable? Do not get me wrong, I always believe in aiming very high. But I do think we need to look at the possibilities from a more practical point of view too.

1) Get an absolute minimum target, which all managers commit to, or lose their bonus. This will give us an idea of the worst case performance of the company, and make sure we do not screw up on this front.
2) Let each account manager also have a target they commit to achieve as part of the growth plans. This should be considered normal growth expected from each account. Managers should also give a list of factors, issues and concerns that they will target for achieving this growth.
This will give managers a clear objective and path, and allow you to follow up and monitor progress in real terms. It's not just about numbers - it's the strategy and path to those numbers that matters most!
3) Let managers also set their starry goals, those targets they should aim for, and be heavily rewarded if they meet them. Again, the point is not the numbers - the point is to get your leaders to chart their path to those numbers!

We have lost and gained some accounts in the recent past. But till today, I do not know
1) Why we got the accounts that we got? Who were the key people who got the account for us? What areas of technology were showcased? Which projects were showcased?
2) Why did we lose the accounts we lost? What was lacking, that we could have done better?
3) If we know (2), can we target these areas as areas of focus for growth in the coming months? Or are we going to achieve our targets through what we did right in (1)?

It's the not just the result that matters, it's the path to those results that managers need to work on!

My MPP Test

Anyone who's ever been responsible for leading a team knows how hard it is to make and follow plans. Microsoft Project is my favourite project planning and tracking tool, and I heavily recommend it to all budding team leaders and managers. While you can use a host of other means to track people, including timesheets and simple Excel-based tracking mechanisms, nothing allows you to visualize and plan your project as the Gantt Chart in MS Project does.

Here's a set of questions for you to try out your MPP skills.

Q1. You are the Project Leader. You have 4 resources, including yourself. One works for you only 50 percent of the time. You have 1 month. You have to develop a Manager Tracking System, by which any employee can get an email alert when his/her manager comes within a range of 5 meters. You need to develop the MPP for this project. Have a strict deadline on the MPP. Take care of all types of tasks including weekly review meetings, document reviews, code reviews, updates and so on.

Q2. One resource falls sick for 3 days. Can you show the impact of this, in comparison to the original plan?

Q3. Another resource leaves the company to pursue a career in cricket, in the middle of your project schedule. You need to reassign resources to try and make up. Does MPP flag an alert if you miss the deadline? How do you handle it?

If you can do the above successfully, you are right on track :)

Software as a Service

Software as a Service (Saas) is a software delivery model where the software provider takes responsibility for the deployment, maintenance, operation and support/updates of the software, rather than the traditional model where the customer "bought and owned" his software. The pricing model changes too - typically, SaaS offerings are charged to the customer on an ongoing pay-as-you-use basis, as against an upfront cost of the product.

So why is SaaS catching up?

For the software developer, SaaS is an effective and efficient way of managing distribution and deployment. You do not need to ship out CDs, you do not need to deploy at the customer site. Software updates, especially in the Web 2.0 world where it's all about incremental deployment of new functionalities, are extremely easy to manage - just deploy on one central server, and all your customer immediately see the change! From a pricing standpoint, the lower cost at entry means lesser budget barriers from the customer side, and a steady, predictable, recurring revenue stream month after month.

The customer is now able to use the product immediately without having to set up his own IT department, and doesn't need to worry about backups, maintenance, upgrades - he just uses what he wants, and pays for it as and when he needs it. So no million dollar budgets.

It's not all that easy and clear though - for one, the product company now needs to be worry not just about software development, but also needs to host it - data security, backups and failover plans, maintenance, and yes, catering to the volume of usage, adds a completely new dimension to the problem. You do not just need software developers and programmers, you now need to have a data center, complete with expensive hardware and system administrators.

SaaS does not necessarily mean a central deployment at one location that belongs to the product company. There could be captive installations at a customer site, installed and maintained physically at the customer's location, or in a separate data center, and each customer may be physically isolated from the other. This is recommended in many cases for security, performance and other factors.

SaaS is not a completely new concept - in the Internet boom days, many Application Service Providers (ASPs) came up, offering their products on the web. There was one subtle difference though - with ASPs, the idea was generally to allow you to use a commercial, packaged product on the web using an additional web UI on top of the product itself. For example, you could use Adobe's PDF writer remotely to get your documents converted into PDF and delivered to you on the web, without actually installing Adobe Writer on your machine. SaaS goes much further, offering products which have the web UI as a first class citizen, where the Internet is central to the whole experience, not an extra layer on the top! Electronic Medical Records systems, for example, have no life without the Internet. Google Docs and Spreadsheet is a curious mix of both the SaaS and ASP models - it's a traditional packaged software component offered on the web, with an interesting suite of web-based functionality like collaboration.

Interestingly, this model is getting accepted not just in software, but in traditional "touch and feel" products too! Bridgestone provides tyres as a service - you do not own the tyres on your vehicle, but you use them, and pay on a per-KM basis. Bridgestone is responsible for servicing your tyres, keeping them operational, changing them when needed. This is a huge advantage in Europe, for example, where a truck can easily travel from the hot plains of Spain to the cold, sub-zero terrain of Sweden. Imagine having to carry twenty snow tyres along, and having to change them on the way! And then repeat the process, this time with dry-weather tyres, on the way back. With Tyres as a Service, you just drive into a Bridgestone service station, and roll out an hour later with the new tyres you needed!

Cummins is pioneering the concept of Power as a Service in India, wherein they do not sell you those million dollar generators. They install one at your location, and then take the responsibility if maintaining and operating these huge machines, while you pay only for the actual use - not the cost of the machine itself!

The key phrase is "service" - as against "the product". So wake up to the concept and align your thinking - before the Web 2.0 juggernaut leaves you behind gasping for breath.

Saturday, December 02, 2006

Teamwork

I have been a strong fan of Saurav Ganguly and the Indian cricket team, and I hated what Chappel-Dravid have done to the team in the past few months. Thankfully, the selectors seem to have woken up to the problem, and things should start falling in place soon. With Dada, Zaheer, Kumble and Laxman back, the indications are extremely positive.

So what was wrong with Chappel-Dravid? What was right about Saurav?

Here's my take:

Chappel tried to get the best out of everyone by keeping them on their toes. Everyone was pushed to perform to their best through intense competition. No one could take things for granted. So what was wrong? He overdid it. You cannot get the best out of your team when the sword is always hanging on their head. They need to be nurtured, they need to be given time, they need to feel that it's OK to make a mistake once in a while. Chappel pushed them so hard, they gave up the fight. On the other hand, Ganguly believed in his team - he gave them the chances, to succeed, and to fail. He backed them all the time! He nurtured a bunch of youngsters into strong, commited adults with the fire in their belly and self-belief in their hearts.

No one was sure of his place in the team. One failure, and you could be thrown into oblivion. What that ensured was that no one played for the team. Everyone played for himself. Nobody was ready to sacrifice their wicket in a run-out - even if it meant that your senio partner got out. Because you wanted to prove yourself - you cared about your score, not about the team! The huddle on the field slowly disintegrated - the celebrations became more personal. Individual numbers and records mattered more.

Ganguly was aggressive, he took flak from the press - but he led his boys and made men out of them. He showed them that it was alright to be proud and aggressive on the field. That they did not need to be shy and gentlemanly on the field. He stood up to the Australians and the Pakistanis and gave them back in their own language, the only language they understood! For once, the Indians were proud of being Indians, and not apologetic about winning! On the other hand, Chappel played dirty games. He mocked his players, exposed their so called flaws, played with their reputations. And if my boss can do it to my peers, will I be next in the firing line?

If you want to be respected as a leader, try and be like Saurav:
1) Back your team. Have faith in your wards. Give them a chance to fail.
2) Show them that the team comes above all. The successes and failures are not individual.
3) Stand by them. Always.