Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUERY] Performance difference between UploadBlobAsync and OpenWriteAsync #43598

Open
shaaradmsft opened this issue Apr 23, 2024 · 1 comment
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files)

Comments

@shaaradmsft
Copy link

shaaradmsft commented Apr 23, 2024

Library name and version

Azure.Storage.Blobs 12.19.1

Query/Question

Hi, I am trying to figure out the reason behind the performance difference between UploadBlobAsync and OpenWriteAsync methods.

Here is the minimal test code that I have -

using Azure.Storage.Blobs;
using Azure.Storage;
using System.Runtime.CompilerServices;
using System.Diagnostics;
using Azure.Storage.Blobs.Specialized;

namespace BlobUploadTest
{
    internal class Program
    {
        static async Task Main(string[] args)
        {
            var accountName = "accountname";
            var accessKey = "accessKey";
            var containerName = "containerName";

            var keyCred = new StorageSharedKeyCredential(accountName, accessKey);
            var blobClient = new BlobServiceClient(new Uri($"https://{accountName}.blob.core.windows.net"), keyCred);

            var containerClient = blobClient.GetBlobContainerClient(containerName);

            var sw1 = new Stopwatch();
            sw1.Start();

            {
                using var fs1 = new FileStream(@"C:\temp\LocalExport\dataFile.data", FileMode.Open, FileAccess.Read);

                await containerClient.UploadBlobAsync("dataFileUploadBlobAsync.data", fs1, CancellationToken.None);
            }

            sw1.Stop();
            Console.WriteLine($"Time taken by UploadBlobAsync is {sw1.ElapsedMilliseconds} ms");

            var sw2 = new Stopwatch();
            sw2.Start();

            {
                using var fs2 = new FileStream(@"C:\temp\LocalExport\dataFile.data", FileMode.Open, FileAccess.Read);

                var blockClient = containerClient.GetBlockBlobClient("dataFileOpenWriteAsync.data");

                using var blobUploadStream = await blockClient.OpenWriteAsync(true, null, CancellationToken.None);

                await fs2.CopyToAsync(blobUploadStream);
            }

            sw2.Stop();
            Console.WriteLine($"Time taken by OpenWriteAsync is {sw2.ElapsedMilliseconds} ms");
        }
    }
}

Both the ways to upload blobs use a file stream that reads from a locally present file (to make sure the incoming stream isn't involving any network I/O etc.) and upload it to a blob store container.

This program was run on an Azure VM (with release configuration built, if it matters) in the East US region, and it was pointed to a storage account in the East US region. The blob being uploaded was of size 256MBs. The output was -

Time taken by UploadBlobAsync is 31936 ms
Time taken by OpenWriteAsync is 165537 ms

Can you please help me understand why there's a significant difference in the two upload methods? I checked that if no BlockBlobOpenWriteOptions are given to OpenWriteAsync, the default BufferSize is 4MB. So not sure what else could be a contributing factor to the slowness of OpenWriteAsync.

Environment

Host:
  Version:      8.0.4
  Architecture: x64
  Commit:       2d7eea2529
  RID:          win-x64

.NET SDKs installed:
  No SDKs were found.

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
@github-actions github-actions bot added Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files) labels Apr 23, 2024
Copy link

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

No branches or pull requests

1 participant