Azure file Storage SMB slow to list files in directory
Asked Answered
C

1

5

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?

Capella answered 2/6, 2016 at 3:8 Comment(2)
Hi, I am trying to work with the first approach i.e. system.io namespace and use Directory.GetFiles or Directory.CreateDirectory but I couldn't find any complete example/sample anywhere. Do we have to do any step before this? How do we authenticate with Azure Storage?Erstwhile
@MilindThakkar, regarding managing objects on Azure File Storage, you might find the this article useful ("Develop for Azure Files with .NET") learn.microsoft.com/en-us/azure/storage/files/…Bertabertasi
P
4

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.

Petey answered 28/6, 2016 at 1:22 Comment(1)
Tang: Hi, I am trying to work with the first approach i.e. system.io namespace and use Directory.GetFiles or Directory.CreateDirectory but I couldn't find any complete example/sample anywhere. Do we have to do any step before this? How do we authenticate with Azure Storage?Erstwhile

© 2022 - 2024 — McMap. All rights reserved.