Using the new Windows Azure Tools v1.4 for VS2010

The new Windows Azure Tools for v1.4 (August 2011) for VS2010 have just been released.  You can download them using Web Platform Installer here. This latest version of the tools introduces several new features as follows:
  1. Support for Multiple Service Configurations
  2. Profiling support for Windows Azure apps running in Windows Azure
  3. MVC 3 web role support
  4. Package validation
Note: Profiling is only supported in VS 2010  Ultimate+Premium.  All others are available from Visual Web Developer 2010 and up.
This post will take a brief look at the benefits each of these new features bring to you – the developer :)

 

Multiple Service Configurations

Gone are the days of having to change your settings in your ServiceConfiguration.cscfg when you switch from debugging your local cloud+storage emulator to publishing up to Windows Azure.  For example in your development environment for:
  1. local debug you may want to:
    • utilize 1 instance of your web/worker role
    • use the local storage emulator
  2. whereas in Windows Azure you may want to:
    • utilize 4 instances of your web/worker role
    • use a production Windows Azure storage account
To achieve this using the new multiple service configurations is easy.
  1. Create a new Windows Azure project with an arbitrary web or worker role.
    • File > New Project > Cloud > Windows Azure Project
    • Select a web or worker role and press OK
  2. Observe that the ServiceConfiguration.cscfg is now split by default into two files:
    • ServiceConfiguration.Local.cscfg – default used when debugging in VS
    • ServiceConfiguration.Cloud.cscfg – a config you can use on publish
  3. To configure each individual configuration with the settings we desired above.
    • Double click on the WorkerRole1 in the roles folder of the cloud project
    • then and select the Service Configuration dropdown for Cloud
    • Select Service Configuration Profile

    • Set the desired settings for your Cloud profile ServiceConfiguration.Cloud.cscfg

  4. You can then repeat the above for your Local configuration profile to setup and set the desired settings for ServiceConfiguration.Local.cscfg
  5. The net result is that both ServiceConfiguration.Cloud.cscfg and ServiceConfiguration.Local.cscfg will now have their independent settings as follows:
      Independent config in ServiceConfiguration.Cloud.cscfg

      Independent config in ServiceConfiguration.Cloud.cscfg

      Independent config in ServiceConfiguration.Local.cscfg

      Independent config in ServiceConfiguration.Local.cscfg

  6. When you hit debug now the ServiceConfiguration.Local.cscfg is used and when you hit publish you can select which Config you would like to use:

Overall its quite an easy experience to configure and use multiple Service Configuration profiles for your different environments.  Please note that you can also rename and add additional Service Configuration profiles perhaps such that you would have a config for Local, Staging and Prod.  For more detail on how to work with Service Configuration files please see Configuring a Windows Azure Application.

Profiling Support

This is an incredibly useful tool for any Windows Azure developer as it enables you to profile your Windows Azure application that’s running up in Windows Azure.  The information gathered can help analyze any performance issues you may be facing.  When you publish your application from VS you are able to specify your profiling options that will apply for the profiling session and results can be pulled for each instance.
The supported profiling options are as follows:
  1. CPU Sampling – Monitor CPU-bound applications with low overhead
  2. Instrumentation – Measure function call counts and timing
  3. .NET Memory Allocation (Sampling) – Track managed memory allocation
  4. Concurrency -Detect threads waiting for other threads
In this segment I will demonstrate how to configure a profiling session for a Windows Azure Application:
  1. Open your existing cloud project and right click on the windows azure cloud project and select Publish
  2. Select the Enable profiling option on the publish page and click settings
  3. Select the type of profiling you wish to perform in this case .NET Memory Allocation
  4. Note: Checking the Enable Tier Interaction Profiling option captures additional information about execution times of synchronous ADO.NET calls in functions of multi-tiered applications that communicate with one or more databases.  With the absence of a SQL Profiler in SQL Azure this feature is useful for those developers who want to gain some insight into what queries or stored procedures are running slowly.
  5. Press OK.
  6. Once the deployment is complete and the application has been running for a period of time you can go and download the captured profiling report.
  7. To download the profiling report
    • Select View > Server Explorer
    • Expand Windows Azure Compute
    • Expand the hosted service
    • Right click on the Instance that you want do download the profiling report from and press View Profiling Report
  8. Once the report is downloaded it will open in VS and as you can see the CPU is maxing out
  9. If we change the Current View dropdown to Allocation we can quickly identy a problem method that is using excessive amounts of memory
  10. and finally if we right click and select View Source on the method of interest we can see the offending line causing the allocations
What an awesome tool.  I look forward to digging deeper into the capabilities provided by for Windows Azure Profiling. In the meantime for more information please see – Profiling a Windows Azure Application

 

MVC 3 Web Role Support

ASP .NET MVC 3 web roles are now supported out of the box with the new tools.  You can select ASP .NET MVC 3 from the new Windows Azure project dialog and the required assemblies used by ASP .NET MVC 3 are set to copy local for you.  This results in these assemblies being deployed up to windows azure when you publish your application thus ensuring your MVC 3 application will start when deployed. I know a lot of you are probably thinking Eureka right now and those that may get a little bit too excited may even verbalize it, I know I did :)

To create a new Windows Azure ASP .NET MVC 3 application:

  1. File > New Project > Cloud > Windows Azure Project
  2. Select ASP .NET MVC 3 Web Role, press the > button followed by OK
  3. In the ASP .NET MVC 3 project dialog select settings to suit your preferences and press ok
  4. In solution explorer observe that all the references assemblies for ASP .NET MVC 3 that are not in the GAC in the current Windows Azure gues OS have had their Copy Local property set to true.  The below image shows and example of one of the required reference assemblies that is automatically set to copy local so you dont actually have to do anything :)

From here on in all you have to do is start coding :) – For more information on ASP .NET MVC 3 see this and for a detailed walkthrough of ASP .NET MVC 3 on Windows Azure see this post by Nathan Totten

Package Validation

Last but definitely not least is improved package validation. When you select to create a package or publish your Windows Azure application. Additional warnings or errors are now provided in VS to enable you to fix the problem before you package or publish it.  This as you know will be a great timesaver for details of what package validations are performed please see Troubleshooting Package Validation Errors and Warnings

Time to Download

All in all its an excellent new set of features that focus on improving your productivity and make your dev life a whole lot easier. If you have not already then now would be the time to download using Web Platform Installer :)

happy coding,

Nick

Asynchronous Image download on Windows Phone 7

When running your solution on local and setting the Source property of the System.Windows.Controls.Image it is not visually apparent that the Image may take some period of time to download simplifying the code the following the original image swap out whereby i was using an arbitrary Uri to an image in Azure Blob Storage that would change at a predefined interval.

imgContent.Source = new BitmapImage(new Uri(arbitraryImageUriThatKeepsChanging));

As soon as the image is available from Azure Blob Storage – or any other hosting provider for that matter if you are not using a CDN and are a long way from your host then or the image is of a large size then it is likely that as soon as the image is set the image content becomes empty until the image is downloaded – i found this to be 10 to 30 seconds over the slow bandwidth of my phone.  To have an empty Image control on the screen was not acceptable so the simple solution is to pull down the image asynchronously using a WebClient then once downloaded update the Image.Source as follows:

Starting the Async download of the image:

WebClient wc = new WebClient();
wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
wc.OpenReadAsync(new Uri(arbitraryImageUriThatKeepsChanging), wc);

Handling the completed download and updating the image source – note: have intentionally removed the MVVM implementation here to minimise code in post if using MVVM setup the binding on the Image.Source property to the model Source.

void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
   if (e.Error == null && !e.Cancelled)
  {
      try
      {
         BitmapImage image = new BitmapImage();
         image.SetSource(e.Result);
         imgContent.Source = image;
      }
      catch (Exception ex)
      {
          //Exception handle appropriately for your app
      }
  }
  else
  {
      //Either cancelled or error handle appropriately for your app
  }

Async download of Images from Azure to windows phone.

Note: WebClient executes on the UI thread if you wish to do this on a background thread and then later update the UI you should use HttpWebRequest and then Dispatcher within your response to update the UI thread.

Note: It would be interesting to configure the Azure CDN to see the improved performance once the node is distributed from a CDN node that is geographically close.

Nick

Some first time Azure deployment findings

Today I completed my first couple of deployments of an OData service to Windows Azure hosted in the Geographic Location of “Anywhere Asia”.

What I liked about the dev experience – As  a complete Azure newb I was able to do the following in under a day :

  1. Migrate an existing SQL 2008 R2 DB to Azure SQL
  2. Connect remotely to the new Azure SQL DB using SQL Management Studio
  3. Create and deploy an OData Service that is fed from the Azure SQL DB
  4. Get some blobs into the Blob storage
  5. Consumed the OData service and Blob from a Windows Phone 7 Application – All I had to do was update the client I created here Consuming an OData service from windows phone 7 to point my TestClient URI to the cloud service rather then my local. 
  6. 16 Months Free*

What I didn’t like:

  1. Could not find support in Visual Studio 2010 to deploy to SQL Azure directly.  If anyone is aware how please throw a link at me.  I had to gen deployment scripts using SQL Management Studio.  VS 2010 Data compare did not work when compairing between SQL Server 2008 R2 and SQL Azure. Note I did find this project on codeplex which might be handy – SQL Azure Migration Wizard v3.3.5

  2. newsequentialid() is not supported in SQL Azure - makes sense given that the sequential id is partially generated based on the network card therefore does not fit well with sql azure running across multiple machines.  But the issue is to get it up and running quickly i had to update to use newid() so now not sure how fragmented my indexes are going to become and this will have an impact on my insert performance so I will need to revise this.

  3. Unable to upload to blob storage from within Server Explorer.  You can only view your blobs as per image

    below and I had to code a client application just to upload the simple HelloWorld test file you see below :( … Would be great to see an Upload option in the context menu.

    Server explorer azure no blob upload
    Server explorer azure no blob upload
  4. Time to taken to deploy the service that contained only a simple Entity Model and single OData service was quite a while.  But when you look at whats going on under the hood its pretty damn quick althought it would be great to have the output window for the azure deployment indicate exactly whats happening rather then just a few initialising, busy, running statements etc.
  5. If anyone has any helpful links to the issues above – please feel free to post the links in the comments.
Nick

Sign up to free trial of Azure using your Bizspark account

If you are a member of Bizspark you are able to get 8 – 16months “free” Azure hosting.  Cool :)

To sign up using your Bizspark account select the My Account tab from the MSDN Subscription site. Make sure you read the fine print

so whats on offer:

Grabbed the following  from here http://www.microsoft.com/WindowsAzure/offers/popup.aspx?lang=en&locale=en-AU&offer=MS-AZR-0005P

“This promotional offer provides monthly compute hours, storage, data transfers, SQL Azure databases, Access Control transactions and Service Bus connections for MSDN premium subscribers.

MSDN Premium Subscription Benefit:

  • Windows Azure
    • 750 hours of a small compute instance
    • 10 GB of storage
    • 1,000,000 storage transactions
  • SQL Azure
    • 3 Web Edition databases (up to 1 GB relational database each)
  • AppFabric
    • 1,000,000 Access Control transactions
    • 1 pack of 5 Service Bus connections
  • Data Transfers
    • North America and Europe (per region)
      • 7 GBs in
      • 14 GBs out
    • Asia Pacific Region
      • 2.5 GB in
      • 5 GB out

You may utilize up to the above amount of service each month without additional charge for 8 months following sign up for this offer as long as you maintain your MSDN Premium subscription.

Any usage each month in excess of the MSDN Premium Subscription Benefit will be charged at the MSDN Premium rates.

MSDN Premium Rates:

Windows Azure

  • Compute
    • Small instance (default): $0.1253 per hour
    • Medium instance: $0.2506 per hour
    • Large instance: $0.5011 per hour
    • Extra large instance: $1.0022 per hour
  • Storage
    • $0.1649 per GB stored per month
    • $0.011 per 10,000 storage transactions
  • Content Delivery Network (CDN)
    • $0.1649 per GB for data transfers from European and North American locations*
    • $0.2198 per GB for data transfers from other locations*
    • $0.011 per 10,000 transactions*

SQL Azure

  • Web Edition
    • $10.4286 per database up to 1GB per month
    • $52.14 per database up to 5GB per month**
  • Business Edition – Up to 10 GB relational database
    • $104.3846 per database per month
    • $208.77 per database up to 20GB per month**
    • $313.15 per database up to 30GB per month**
    • $417.54 per database up to 40GB per month**
    • $521.92 per database up to 50GB per month**

AppFabric

  • Access Control
    • $2.0775 per 100,000 transactions
  • Service Bus
    • $4.1654 per connection on a “pay-as-you-go” basis
    • Pack of 5 connections $10.3874
    • Pack of 25 connections $51.9368
    • Pack of 100 connections $207.7471
    • Pack of 500 connections $1,038.7350

Data Transfers

  • North America and Europe regions
    • $0.1099 per GB in
    • $0.1649 per GB out
  • Asia Pacific Region
    • $0.3297 per GB in
    • $0.4946 per GB out
  • Inbound data transfers during off-peak times through October 31, 2010 are at no charge. Prices revert to our normal inbound data transfer rates after June 30, 2010.

*CDN rates are effective for all billing periods that begin subsequent to June 30, 2010. All usage for billing periods beginning prior to July 1, 2010 will not be charged.

** SQL Azure 50 GB Business Edition Database and 5 GB Web Edition Database will be available starting on June 28, 2010. “

 

Some more detail available here http://msdn.microsoft.com/en-us/subscriptions/ee461076.aspx

Paul Glavich Microsoft MVP releases free e-book .NET Performance Testing and Optimization The Complete Guide

Paul Glavich Microsoft MVP sent a link to his free e-book around this morning.

“My book on performance testing, profiling and optimisation has been officially released and is available as a free download (eBook)! I think the hardcopy version will be available on amazon as a paid version.”

.NET Performance Testing and Optimization

The chapter list is:

Chapter 01: Introduction – The What and the Why
Chapter 02: Understanding Performance Targets
Chapter 03: Performance and Load Test Metrics
Chapter 04: Implementing your Test Rig
Chapter 05: Creating Performance Tests
Chapter 06: Next Steps – Profiling
Chapter 07: Performance Profiling
Chapter 08: Memory Profiling
Chapter 09: The Performance Testing Process
Chapter 10: Common Areas for Performance Improvement
Chapter 11: Load Balancing
Chapter 12: Internet Information Server (IIS)
Chapter 13: HTTP Optimization

Remember to support the hard of Paul and Chris by buying a copy of the hardcopy from Amazon