0

I have a method to upload a file to Azure to my storage account. My Method is simple

blob = new CloudBlockBlob(new Uri(Uri));
var ms = new MemoryStream(block.Data);
blob.PutBlock(block.BlockId, ms, null)

But sometimes my PutBlock is throwing an exception:

Operation has timed out

StackTrace

at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext)\r\n at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.PutBlock(String blockId, Stream blockData, String contentMD5, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)

Inner Exception Stack Trace

at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)\r\n at System.Net.HttpWebRequest.GetRequestStream()\r\n
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext)"

This usually happens when I am asynchronously uploading say 40 files at a time and the files have caused a bottleneck. I have obviously now limited it to 1 file at a time. But I was wondering why this was happening and if there was a way to prevent it so that I know it wont happen again on say a generally slow internet connection?

1 Answer 1

1

There are a few things you could try:

  • Reduce the number of parallel uploads: You can try by reducing the number of parallel uploads to say number of logical processors (or may be half of that). So for example, if you have 8 core processor then you could try by uploading say 4 - 8 files in parallel. In my experience, uploading more files in parallel actually slows things down. From what I understand the reason for that being a lot of context switching is happening.
  • Reduce the block size: You can try by reducing the block size.
  • Increase the request timeout: If I am not mistaken, the default request timeout in web request is 100 seconds (https://msdn.microsoft.com/en-us/library/system.net.webrequest.timeout%28v=vs.110%29.aspx). You can try by increasing that. This would take care of timeout from the client side. There's a server side request timeout as well which by default is 30 seconds (with some exceptions). You can read more about server side timeout here: https://msdn.microsoft.com/en-us/library/azure/dd179431.aspx. If I am not mistaken, the default request timeout is 90 seconds. You can try by increasing the timeout. You can specify it in ServerTimeout property of BlobRequestOptions parameter in PutBlock method.
3
  • These are some good points. I have already reduced the parallel uploads to 1 at a time so hopefully this should reduce the chance of it happening. I could also try reducing the block size currently each block is 512bytes. How did you know default timeout was 90 seconds? I was trying to find this out for myself but found the msdn documentation on the azure api next to useless
    – JKennedy
    Feb 9, 2015 at 12:24
  • Updated my answer. HTH. Feb 9, 2015 at 12:39
  • I would just like to add here for anyone else experiencing this problem. From what I've been looking at the Azure API provides no way to increase the default request timeout and by the looks of my stacktrace that's where the error is being thrown. Therefore I am going to try reducing the block size and number of parallel uploads. Thanks for the help
    – JKennedy
    Feb 9, 2015 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.