Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uploading Azure Blob(s) Async : BeginUploadFromStream vs. BackgroundWorker

I am uploading blobs asynchronously to Azure Blob Storage. I can use CloudBlockBlob.BeginUploadFromStream or I could call the synchronous Upload methods (like UploadFile or PutBlock) with a BackgroundWorker. I am looking for some opinions on the pros and cons of either approach.

I'll get the ball rolling. It appears much easier to report progress back with the BackgroundWorker approach.

Thanks!

like image 507
Rob Bagby Avatar asked Apr 07 '26 08:04

Rob Bagby


2 Answers

BeginUploadFromStream will be more efficient because it uses the asynchronous programming model which will not use up CPU resources while I/O is occurring. If you spin up a BackgroundWorker and call any of the non-APM methods your essentially wasting that thread while things like reading from disk and writing to the network are occuring.

In .NET, you pretty much always want to use the APM model when it's available for maximum efficiency.

like image 160
Drew Marsh Avatar answered Apr 09 '26 22:04

Drew Marsh


I am updating this old question because I still get a lot of blog hits from noir's post. Please note that there is a new version of my blog post using the *FromStream methods in Azure Storage Client library 2.0. This new code is more performant and more reliable, and still provides all of the progress reporting.

Asynchronous Parallel Block Blob Transfers with Progress Change Notification 2.0

like image 40
kwill Avatar answered Apr 09 '26 22:04

kwill