【发布时间】:2021-09-23 06:39:37
【问题描述】:
我通过包含 azure-spring-boot-starter-storage-3.6.0 在 Spring 中使用 MS Azure Java API,并且在迭代小目录(40 项)的内容时遇到了严重的性能瓶颈.
以https://docs.microsoft.com/en-us/azure/storage/files/storage-java-how-to-use-file-storage?tabs=java中的MS为例:
public static Boolean enumerateFilesAndDirs(String connectStr, String shareName,
String dirName)
{
StopWatch stopwatch = new StopWatch();
try
{
ShareDirectoryClient dirClient = new ShareFileClientBuilder()
.connectionString(connectStr).shareName(shareName)
.resourcePath(dirName)
.buildDirectoryClient();
stopwatch.start("Start stream");
dirClient.listFilesAndDirectories().forEach(
if(stopwatch.isRunning()) {
stopwatch.stop();
log.debug("Time taken to start stream of files and directories: {} ms", stopwatch.getLastTaskTimeMillis());
}
fileRef -> System.out.printf("Resource: %s\t Directory? %b\n",
fileRef.getName(), fileRef.isDirectory())
);
return true;
}
catch (Exception e)
{
System.out.println("enumerateFilesAndDirs exception: " + e.getMessage());
return false;
}
}
我添加了一些秒表日志语句,forEach 开始输出大约需要 20 秒。一旦启动,in 就会以预期的速度输出目录的所有内容。
我还围绕创建到达我的文件所在位置所需的各种 ShareClient 和 ShareDirectoryClients 放入了秒表日志语句,并且这些交互与预期的一样,需要 2 毫秒才能完成。
任何人都可以了解这里发生了什么,或者我如何能够诊断出这种延迟发生的位置/原因?
【问题讨论】:
标签: java azure azure-storage