【问题标题】:Azure Java DirectoryClient slow to list files and directoriesAzure Java DirectoryClient 列出文件和目录的速度很慢
【发布时间】: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


    【解决方案1】:

    这个问题一天消失,第二天又出现后,我又做了一些挖掘,发现这似乎是由于azure使用的默认netty http客户端造成的。

    将我的 POM 更新为以下内容已解决此问题:

    <dependency>
            <groupId>com.azure.spring</groupId>
            <artifactId>azure-spring-boot-starter-storage</artifactId>
            <version>3.6.0</version>
            <exclusions>
                <exclusion>
                <!-- Removed due long delays in listing folder contents. Using azure-core-http-okhttp instead-->
                    <groupId>com.azure</groupId>
                    <artifactId>azure-core-http-netty</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.azure/azure-core-http-okhttp -->
        <dependency>
            <groupId>com.azure</groupId>
            <artifactId>azure-core-http-okhttp</artifactId>
            <version>1.7.1</version>
        </dependency>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-19
      • 1970-01-01
      • 2012-07-28
      • 1970-01-01
      • 1970-01-01
      • 2013-05-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多