首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >阅读Azure Blob异步,为什么2延迟

阅读Azure Blob异步,为什么2延迟
EN

Stack Overflow用户
提问于 2019-06-15 12:20:12
回答 1查看 622关注 0票数 1

我正在编写由存储队列消息触发的Azure函数。然后,它将逐行读取blob,并对数据进行一些处理。这条线本身就是一条Json线。

我根据网络上的例子编写了我的代码,但我的印象是有问题。我正在开发(在VS2017上)两个主要的延迟。在OpenReadAsync和每个ReadlineAsync上..。

所以,如果有人有建议的话,我不是c#开发人员。

代码语言:javascript
复制
private static async Task ProcessFile(string fileName, ILogger log)
    {
        // Connect Source
        CloudStorageAccount cosmobatchStorageAccount = AzureBlobHandling.GetStorageAccount(CommonCode.GetEnvironmentVariable("ComsoBatch_Storage"));
        CloudBlobClient cosmobatchBlobClient = AzureBlobHandling.GetStorageClient(cosmobatchStorageAccount);
        CloudBlobContainer cosmobatchBlobContainer = AzureBlobHandling.GetStorageContainer(cosmobatchBlobClient, CommonCode.GetEnvironmentVariable("CosmoBatch_Container"));
        CloudBlockBlob cosmobatchBlob = cosmobatchBlobContainer.GetBlockBlobReference(fileName);

        // Connect Destination
        CloudStorageAccount singlefileStorageAccount = AzureBlobHandling.GetStorageAccount(CommonCode.GetEnvironmentVariable("SingleFile_Storage"));
        CloudBlobClient singlefileBlobClient = AzureBlobHandling.GetStorageClient(singlefileStorageAccount);
        CloudBlobContainer singlefileBlobContainer = AzureBlobHandling.GetStorageContainer(singlefileBlobClient, CommonCode.GetEnvironmentVariable("SingleFile_Container"));
        //CloudBlockBlob singlefileBlob = cosmobatchBlobContainer.GetBlockBlobReference(fileName);

        try
        {   // Read Blob
            log.LogInformation("Pass 1");
            using (Stream stream =  await cosmobatchBlob.OpenReadAsync())
            {
                log.LogInformation("Pass 2");
                using (StreamReader reader = new StreamReader(stream))
                {
                    log.LogInformation("Pass 3");
                    while (true)
                    {
                        log.LogInformation("Pass 4");
                        string line = await reader.ReadLineAsync();
                        if (line == null)
                        {
                            break;
                        }
                        Console.WriteLine(line);

                        jRecord jRec = JsonConvert.DeserializeObject<jRecord>(line);
                        log.LogInformation(String.Format("MsgNbr : {0}, FileName : {1}, FileType {2}", jRec.msgnbr, jRec.filename, jRec.msgtype));
                    }
                }
            }
        }
        catch (Exception ex)
        {
            log.LogError(String.Format("Catch: {0}", ex));
        }
        finally
        {
        }
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-16 09:58:20

我可以想象OpenReadAsync需要一些时间,因为它

启动一个异步操作来打开流,以便从blob读取。

来源:https://learn.microsoft.com/en-us/previous-versions/azure/dn451819(v=azure.10)

它正在为您使用Stream操作blob奠定基础。

ReadLineAsync

异步从当前流读取一行字符,并将数据作为字符串返回。

来源:https://learn.microsoft.com/en-us/dotnet/api/system.io.streamreader.readlineasync

本质上是一种下载。因此,如果这是一个巨大的线(这意味着大量的数据),这可能也需要一些时间。

另外,请注意,在调试模式下运行代码会减慢它的运行速度。当然,这种类型的操作在本地机器上比在Azure中运行要慢,因为带宽(连接的速度)是这个场景中的一个因素。

如果数字是在(低100毫秒)内,我就不会担心我是不是你。否则,您可能需要查看数据的大小,如果Blob是这类数据的最佳存储类型。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56610339

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档