Azure file Storage SMB slow to list files in directory

邮差的信 提交于 2020-01-04 05:14:04

问题


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")

It takes around a minute when there are 2000 files.

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;
  }

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


回答1:


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.

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



来源:https://stackoverflow.com/questions/37581971/azure-file-storage-smb-slow-to-list-files-in-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!