Profiling Azure Storage with Fiddler part 2: Load First, Ask Later
In a previous post I talked about profiling your Windows Azure Storage using the Fiddler HTTP proxy. When I started profiling Glassboard with Fiddler, I saw a lot of traces like the one below.
Notice how the two highlighted HTTP requests are virtually identical. The only difference is that the first one has the query string argument $top=1 applied to it, so it will only retrieve the first result. In this case I want all the results back, so that first request is a complete waste. What’s going on? Here’s the code:
var query = (from row in base.Rows
where row.PartitionKey == statusId
select row).AsTableServiceQuery();
if (query.FirstOrDefault() == null) //BAD IDEA
{
return new List<CommentInfo>(0);
}
else
{
return query.ToList().ConvertAll(r => r.ToBoardStatusCommentInfo());
}
The query.FirstOrDefault() method call is the source of our problem. It causes that first HTTP request, and if it returns a value then the later query.ToList() method causes the second HTTP request. If you have set the DataServiceContext.IgnoreResourceNotFoundException to true you can eliminate the problem by loading the results without first checking if there are any results, like so:
var query = (from row in base.Rows
where row.PartitionKey == statusId
select row).AsTableServiceQuery().Take(max);
return query.ToList().ConvertAll(r => r.ToBoardStatusCommentInfo());
That simple change was enough to cut our storage traffic in half, which sped up the app considerably. Not only that, remember that each call to Azure Storage costs you money, so this is also a cost savings! If you’re a startup, that’s money staying in your pocket. If you work for a bigger company, put that savings on your quarterly review and ask for a raise!
Written by Brian Reischl
