How to get great performance when using Azure Storage is a topic we've talked with you about many times: during talks at TechEd and Build, in threads on forums, on our blog, and in person. It’s always exciting to see how passionate you are about making your applications perform as well as possible!
To help you further in this goal, we’ve now released the Azure Storage Performance Checklist which consolidates our performance guidance in a single easy to use document, in one easy to find location. It’s a short document (about 15 printed pages) that a developer should be able to read in about 30 minutes and it contains details of over 40 proven practices structured as a checklist, which will help you to improve the performance of your applications. Here is a small selection from the checklist:
Example Scenarios
Many of the recommendations in the checklist are simple to implement in your code. Here are three examples, each of which may have a significant effect on the performance of your application if you apply them in the correct context: Scenario #1: Queues: ConfigurationHave you turned Nagle off to improve the performance of small requests? The Nagle algorithm is enabled by default. To disable it for a queue endpoint, you can use the following code. This code must execute before you make any calls to the queue endpoint:var storageAccount = CloudStorageAccount.Parse(connStr); ServicePoint queueServicePoint = ServicePointManager.FindServicePoint(storageAccount.QueueEndpoint); queueServicePoint.UseNagleAlgorithm = false; CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();Scenario #2: Blobs: Copying BlobsAre you copying blobs in an efficient manner? To copy blob data from a container in one storage account to a container in another storage account, you could first download and then upload the data as shown here:
CloudBlockBlob srcBlob = srcBlobContainer.GetBlockBlobReference("srcblob"); srcBlob.DownloadToFile(@"C:\Temp\copyblob.dat",System.IO.FileMode.Create); CloudBlockBlob destBlob = destBlobContainer.GetBlockBlobReference("destblob"); destBlob.UploadFromFile(@"C:\Temp\copyblob.dat", System.IO.FileMode.Open);However, a much more efficient approach is to use one of the copy blob methods such as StartCopyFromBlob as shown here:
CloudBlockBlob srcBlob = srcBlobContainer.GetBlockBlobReference("srcblob"); CloudBlockBlob destBlob = destBlobContainer.GetBlockBlobReference("destblob"); destBlob.StartCopyFromBlob(GenerateSASUri(srcBlob));
Note that this example uses a Shared Access Signature (SAS) to access the private blob in the source container.Scenario #3: Blobs: Uploading FastWhen trying to upload one blob quickly, are you uploading blocks in parallel? If you are using the .NET Storage Client Library, it has the capability to manage parallel block uploads for you. The following code sample shows how you can use the BlobRequestOptions class to specify the number of threads to use for a parallel block upload (four in this example):
CloudBlockBlob blob = srcBlobContainer.GetBlockBlobReference("uploadinparallelblob"); byte[] buffer = ... var requestOptions = new BlobRequestOptions() { ParallelOperationThreadCount = 4 }; blob.UploadFromByteArray(buffer, 0, buffer.Length, null, requestOptions);
Note that the Storage Client Library may upload small blobs as a single blob upload instead of multiple block uploads: the SingleBlobUploadThresholdInBytes property of the BlobRequestOptions class sets the size threshold above which the Storage Client Library uses block uploads.