Azure文件存储SMB缓慢列出目录中的文件 [英] Azure file Storage SMB slow to list files in directory

查看:113
本文介绍了Azure文件存储SMB缓慢列出目录中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个应用程序,可通过Azure文件列出文件夹中的文件.当我们使用C#方法时:

We have an app that lists files in a folder through Azure Files. When we use the C# method:

Directory.GetFiles(@"\\account.file.core.windows.net\xyz")

有2000个文件时,大约需要一分钟.

It takes around a minute when there are 2000 files.

如果我们使用CloudStorageAccount进行相同操作:

If we use CloudStorageAccount to do the same:

  CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
  CloudFileDirectory directory = fileClient.GetShareReference("account").GetRootDirectoryReference().GetDirectoryReference("abc");
  Int64 totalLength = 0;
  foreach (IListFileItem fileAndDirectory in directory.ListFilesAndDirectories())
  {
    CloudFile file = (CloudFile)fileAndDirectory;
    if (file == null) //must be directory if null
      continue;

    totalLength += file.Properties.Length;
  }

它将返回所有文件,但大约需要10秒钟.为什么性能会有如此大的差异?

It returns all the files, but takes around 10 seconds. Why is there such a large difference in performance?

推荐答案

在使用Directory.GetFiles(系统文件API)时,它实际上通过SMB协议与Azure File Storage对话(v2.1或v3.0取决于客户端操作系统)版本).但是,当切换到CloudStorageAccount时,它将通过REST与文件存储通信.如果使用Wireshark,您会发现由于协议的性质,SMB协议将在客户端和服务器之间有多个来回请求. Azure文件存储同时支持SMB和REST访问的原因是允许您的旧代码/应用程序(用于访问文件服务器托管的文件共享)现在可以与Cloud中的文件共享进行对话,而无需更改代码.

When using Directory.GetFiles (System File API), it actually talks to Azure File Storage via SMB protocol (v2.1 or v3.0 depends on client OS version). However when switch to CloudStorageAccount, it talks to File Storage via REST. If you use Wireshark you will discover the SMB protocol will have several back and forth requests between client and server due to the nature of the protocol. The reason for Azure File Storage supports both SMB and REST access is to allow your legacy code/application(which used to access file shares hosted by file servers) can now talk to a file share in Cloud without code change.

因此,根据您的情况,建议使用REST调用来访问Azure文件存储,以提高性能.

So the recommendation in your case is using REST call to access Azure File Storage for better performance.

这篇关于Azure文件存储SMB缓慢列出目录中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆