c# - Azure file Storage SMB slow to list files in directory -
we have app lists files in folder through azure files. when use c# method:
directory.getfiles(@"\\account.file.core.windows.net\xyz")
it takes around minute when there 2000 files.
if use cloudstorageaccount 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 directory if null continue; totallength += file.properties.length; }
it returns files, takes around 10 seconds. why there such large difference in performance?
when using directory.getfiles (system file api), talks azure file storage via smb protocol (v2.1 or v3.0 depends on client os version). when switch cloudstorageaccount, talks file storage via rest. if use wireshark discover smb protocol have several , forth requests between client , server due nature of protocol. reason azure file storage supports both smb , rest access allow legacy code/application(which used access file shares hosted file servers) can talk file share in cloud without code change.
so recommendation in case using rest call access azure file storage better performance.