What is Windows 7 doing at a web conference like MIX09? Last week I went along to the above titled session, in which Yochay Kiriaty, an irrepressible evangelist on my team, presented the case for a desktop application in an increasingly web-orientated world.
He talked about how local desktop applications remain just as relevant as ever in the world of the web. For example, even though Twitter is often portrayed as the doyen of the Web 2.0 world, there are over 560 applications that use the Twitter API, spreading across client and mobile devices. Similarly, many other web properties such as Netflix, New York Times, eBay and Windows Live, have great desktop experiences that add value to the core experience. With a market of one billion addressable devices, it would be foolish to ignore the role Windows-based applications can play.
Yochay demonstrated a number of potential entry points in Windows 7 for a website that might want to supplement their browser-based offering with a “sticky” branded desktop experience:
Above: Screenshot demonstrating Windows Live Messenger jump list, barclaycard.co.uk desktop gadgets, Twitter search connector and Wikipedia visual search.
It’s clear that there’s increasing convergence between the web and the desktop. Beyond the search features above, the inclusion of multi-touch and gesture support in Silverlight 3 demonstrates how the lines are blurring. It’s going to get easier and easier to build applications that run great on the web but do even more when they take advantage of the full power of Windows. It’s an exciting time to be a Windows developer!
(Note: I originally posted this session’s notes at http://visitmix.com/Opinions; I’ve edited them a little and reposted them here for consistency with the other posts below.)
Windows Azure isn’t particularly “on-topic” for this blog, but hey, just because I’m a client guy doesn’t mean that I can’t show any interest in other technologies, right? Manuvir Das presented a session on the subject at MIX09, and since I’m sat at home with a heavy cold feeling sorry for myself, I thought I’d catch up on some of the sessions that I’d missed via the free online MIX09 recordings.
(In passing, I’d love to know whether these kinds of detailed session notes are helpful to you – feel free to add a comment below or send me a private note.)
What is Windows Azure? In a nutshell, Windows Azure is an operating system for the cloud.
As an application developer, one can think of an operating system in the following ways:
Why do we need a new operating system for the cloud? What’s wrong with the existing model?
The reality is that running cloud-based services presents many unique needs (as an example, consider a popular website like Flickr or Hotmail). Any service that is provided at scale is distributed across servers in one or more geographically-dispersed datacenters. It is expected to be available 24 hours a day, 7 days a week: a failure in any individual piece of commodity hardware needs to be automatically and silently managed without external disruption. Servers need to be upgraded to new software and hardware without taking the whole service offline; the service also needs to be able to support sudden increases in traffic or storage requirements seamlessly.
All these demands mean that infrastructural concerns become an overriding constraint in providing the service. We need software that can manage and abstract these problems – specifically, an operating system that spans and controls a set of connected servers, providing an execution environment, a shared file system, resource allocation, administrative tools and so on. In this world, the ideal is a utility computing model that presents the datacenter as having essentially infinite scale available, with the application developer paying only for the actual resources consumed.
As an operating system for the cloud, Windows Azure provides four facilities:
Development and Computation In building Windows Azure, the primary goal was to create a rich and familiar programming experience. You can write code using .NET, PHP or native Windows code, using Visual Studio or even Eclipse. The SDK provides a simulated cloud environment (known as the development fabric) that a developer can run locally to build and test an application, along with tools to package the application for production deployment: it’s important to note that there is no difference to a developer between the local and cloud-based environments.
Newly introduced at MIX09 is support for full-trust application execution, allowing you to run any native code via P/Invoke (as well as more complex .NET applications); you can also now use FastCGI as a way to offer native handlers for your application. Another new addition that will be available shortly is geo-location, allowing you to target your services to one or more locales and ensuring that data and storage are co-located for performance optimization.
Windows Azure is now running in production on datacenters across the world. As part of the session, Manuvir demonstrated two Windows Azure-based demo sites, Botomatic and Tweval, that build on Twitter to provide live session feedback.
Management The overriding constraint in Windows Azure was to ensure that services can be managed automatically. When you develop your service, you also define a model using XML that describes the service topology and size (number of instances), the resources required (e.g. disk sizing), health constraints (how Windows Azure should know when a service is “unhealthy”), and other configuration settings. When you deploy the service, Windows Azure takes care of identifying one or more virtual machines to run the service, setting up load balancing, creating an entry point for the service and then ultimately monitoring the service for health.
Storage Windows Azure provides a number of simple abstractions over the underlying cloud-based storage: blobs for large items of data, tables for handing service state, and queues for communicating between services. Additional abstractions over the storage will be exposed over time. One important caveat is that Windows Azure doesn’t support automated geo-replication in the current production environment (although it is coming): you need to manually deploy your data to different locales if you need it to be geographically dispersed.
What if you need a relational database in the cloud? The Azure Service Platform will provide a SQL Server-based cloud relational store, called SQL Data Services; the separate MIX09 session on this topic provides more detailed information on this aspect.
Conclusion Beyond the core functionality that Windows Azure provides, best architectural practices remain important. The platform is designed to encourage best practices: stateless computation with durable storage, with web and worker roles co-located and communicating over queues.
Windows Azure is currently in CTP, offering free usage with quotas; an updated technical preview was released at MIX09, with regular updates expected through 2009 culminating in a commercial release by the end of the year.
Seema Ramchandani works on performance as a Program Manager on the Silverlight team. She gave a fast-paced talk at MIX09 covering the graphics and media that contained some helpful tips for performance profiling, debugging and optimization.
Silverlight Rendering Architecture When building a graphics-rich application, it’s first important to be aware of the underlying architecture of the rendering and media pipelines in Silverlight.
To begin, there is one main execution thread that you need to be careful of not clogging when you build your application. The UI thread executes your code directly along with operating the animation and layout systems. (On older browsers, there’s one UI thread for all tabs in the browser; on newer browsers, we’re starting to see one process per tab.) We spin up separate (non-UI) threads for all other work, such frame rasterization, media decoding and GPU marshalling.
Media is delivered to the end-user through a pipeline: decoding the source, performing YUV –> ARGB conversion, resizing and blending the output (as appropriate) and finally drawing the resultant pixels on-screen. Silverlight 3 enables the latter steps to be performed by the GPU if you enable hardware acceleration. For maximum throughput, make sure you encode the video at the minimum framerate that you need (typically 18-20fps). To make the most of the software renderer, ensure you are also encoding at the desired size so there is no rescaling required, and minimize the amount of media blending.
One word of caution: most developers have high-specified machines that aren’t representative of their target customers’ devices. As a result, when focusing on performance, set the MaxFrameRate property on the Silverlight control to an arbitrarily high number (e.g. 10,000 fps) so that the speed measured isn’t being capped, and then use the EnableFrameRateCounter (IE-only) and EnableRedrawRegions properties to show the rendering speed and areas being redrawn on a per-frame basis respectively.
For maximum performance, there’s no substitute for minimizing the amount of work being asked of the runtime: reduce the size of the objects being rendered; simplify the visual tree; minimize the number of operations required per draw. Lastly, use windowless mode judiciously: it’s expensive because it requires per-frame blending with the underlying background.
Lastly, be aware when you start developing an application of your target goals: how many objects, elements and animations you’re expecting in the final project. Be aware of bloat in the XAML – for instance, it’s easy for tools to insert tens of keyframes that don’t make any visual difference.
Silverlight Profiling with XPerf For profiling, one of the best tools is XPerf, a long-standing internal Windows performance analysis tool that has recently been released externally as part of the Windows SDK. It uses Event Tracing for Windows (ETW) to analyze the call stack, taking advantage of the fact that both Silverlight and the CoreCLR have embedded ETW events. XPerf can give you a good idea of the expensive operations in your code: for example, drawing v. browser interactions v. JIT compilation of .NET code.
To use XPerf, enable the profiler while you run the problematic area of your application to generate a capture. (Seema’s blog has more detailed information on the process.) It shows CPU usage across the period of time captured; if you connect to the Microsoft public symbol server you can then break this down against the various internal methods within Silverlight. It’s relatively easy to tell what’s going on, as the following screenshot demonstrates: As we’ve had customer applications in the Redmond labs, we’ve noticed that it’s quite common to see applications spending a lot of CPU time in the text stack. In Silverlight 3, you can use an inherited property to apply a hint to the text rendering engine when you’re animating the text that turns off pixel-snapping. RenderOptions.TextRenderingMode = RenderForAnimation
One last note: it’s worth downloading the PowerPoint slides for this session for more information. There are lots of hidden “context” slides included that add depth to the notes above.
Brandon Bray gave an interesting presentation at MIX09 on how the CLR (the execution engine that underlies the .NET Framework) was refactored to support for Silverlight; I thought I’d share my distilled notes from the session.
Bringing .NET to the Silverlight world was an obvious choice. Not only does it have a broad community and powerful tools ecosystem, but the CLR also offers many important and useful features for building RIAs: strong type safety, partial trust security verification and AppDomains (providing isolation for multiple applications within a single process). But the existing .NET Framework is specific to Windows, and has grown too large for deployment in a web runtime where every byte counts. So it was necessary to rework the CLR to be optimized for this purpose.
CLR Size Reductions
Looking at the .NET architecture, it was designed to support many different scenarios across client and server, including profiling and debugging, just-in-time compilation, and so on. For Silverlight, we just needed to focus on one scenario: interactive client applications. Silverlight contains “CoreCLR”, a cut down version built from the same sources that runs side-by-side with the full .NET CLR. CoreCLR is just 2MB in size. It’s worth noting in passing that CoreCLR is also embedded within other Microsoft technologies, most notably Live Mesh.
Some compromises that could be made to trim the size of the CLR right down:
The Silverlight architecture is fundamentally the same: the same architectural boxes are present (albeit the surface area is much smaller in each case), with the exception of NGEN and profiling API support. The JIT does a minimum of optimization to improve startup time and reduce code size. The server-optimized garbage collector is removed, since it isn’t required; the reflection engine is substantially reduced, and Silverlight relies on the underlying operating system for collation string tables that are already standardized.
But that wasn’t enough. To get the CoreCLR down to its target size of 2MB, a good proportion of the size savings had to come from the base class library. CoreCLR includes a subset of the base class library called Small BCL. As with the rest of CoreCLR, Small BCL is built from the same source code as the full .NET BCL.
CoreCLR Security Model
One other area that has contributed significant code size savings is the notion of transparent libraries. The full desktop .NET supports Code Access Security, a very rich but complex security model. The CoreCLR security model makes reasoning about security much easier. There are three layers of code:
Along with the transparent code that a developer compiles into a XAP, the same concept is used for other libraries like LINQ and the DLR as well as many controls; this means that they don’t need to be installed as part of the Silverlight runtime itself but can be downloaded on-demand as part of the application download on request. In Silverlight 3, transparent libraries can be cached so they only have to be downloaded once.
Cross-Platform Support In one critical way the CoreCLR in Silverlight has to do more than the full .NET CLR: it has to run on Mac OS as well as Windows. This is implemented through a Platform Abstraction Layer (PAL), based on the work done some years ago for a research project called Rotor. The PAL can be fairly simple because Silverlight only needs to support the x86 instruction set. Again, this is checked into the main CLR codebase, but is only required for the CoreCLR implementation.
For more information about the CoreCLR, Andrew Pardoe’s MSDN Magazine article on Programming Silverlight with the CoreCLR is perhaps the most authoritative online source.
Deborah Adler presented a fascinating case study of how user experience design can really have a positive impact on the lives of those who touch our products. She was the principal designer behind Target’s ClearRx drug prescription packaging, which has had a big impact in avoiding drug prescription misusage. As Bill Buxton highlighted in his introduction, “she doesn’t come from our culture. To her, a developer is someone who turns your photos into prints!” Nevertheless, her talk was very relevant to all of us involved in creating rich user experiences, whether we realize it or not!
The Challenge: Confusing Design Costs Lives When you wipe away the high-tech jargon, we’re all in the business of creating an experience for a customer. When you make it a comfortable or enjoyable one, your job is done. In redesigning the Target packaging, Deborah started with her grandmother, who accidentally took her husband’s prescription. When she investigated further, it was easy to see why – they both were prescribed the same drug at different strengths, and since their names were similar, there was very little to notice different about the two packages.
60% of Americans don’t take their medications correctly. On average, over ten prescriptions per person are filled each year. With 300 million citizens, that represents three billion drug prescriptions. We spend a huge amount of money dealing with the issues of incorrect drug usage, and the costs are measured in lives.
Deborah highlighted some of the design issues that plague drug packaging – poorly printed text with bad iconography, large quantities of small print text with poor formatting and long line length, complex text (“do not take with nitrates” is only meaningful if you know what a nitrate is). There’s no hierarchy of information – how do you know what is relevant and what is just manufacturing information?
Redesigning with the End User in Mind In redesigning the packaging, the goal was to combine information architecture with intuition and previous knowledge of cognitive schemas (knowledge of what the most important pieces of information are). She used color coding so that no two people in the same household have the same color bottle. She wanted people at a glance to know who it was for, what the drug was, and when to take it. The updated packaging even included a magnifying lens in the back of the bottle to make it easier for those with poor eyesight to read the small print.
They’re continuing to investigate further innovations, for example printing with chemicals that change color over time (so that when a drug expires, a big cross appears over the label).
Turning Design into Production When Deborah completed her thesis, at first she took it to the FDA with an ambitious goal of having the new prescription labeling being mandated as a federal standard. For various reasons, including the way that control over packaging was mostly federated at a state level, this was unsuccessful. So she started looking for a large nationwide pharmacy to see whether they would adopt it for their own usage.
Target has a “design for all” philosophy, and they took the idea under their wings and refined it into the ClearRx system, which is now standard for all Target prescriptions.
There were lots of real-world challenges that had to be addressed in productizing this: for example, there are 23 variations of the system that had to be produced due to state law differences. It required a retooling of the production system too (for example with duplex printing).
When Richard Carmona, the former US Surgeon General reviewed this, he said, “the new design is a simple yet important step in improving the health literacy of all Americans.” New York Magazine first broke the story about the ClearRx system – it was great to hear the story presented both from the designer’s perspective and the end-users’ perspective.
Some life-long lessons learned from this project: