question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Slow scanning time on SpringMVC application

See original GitHub issue

Hey guys!

I’m currently using the 2.9.2 version on Springfox and I’m facing long wait times deploying my application, just when springfox starts to scan for api listing references and generating unique operations. If I add “nickname” on @ApiOperation to avoid the unique operation generation, the slow time stays the same.

This is my SwaggerConfiguration.java:

@Configuration
@EnableSwagger2
public class SwaggerConfiguration extends WebMvcConfigurerAdapter {

    private static final String RESOURCE_PACKAGE = "br.com.finchsolucoes.xgracco.application.api.resource";

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

    @Bean
    private Docket api() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .useDefaultResponseMessages(false)
                    .groupName("Api")
                    .select()
                    .apis(RequestHandlerSelectors.basePackage(RESOURCE_PACKAGE))
                    .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                    .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                    .paths(regex( "/api.*"))
                    .build()
                    .ignoredParameterTypes(AuthenticationPrincipal.class)
                    .globalOperationParameters(
                        Collections.singletonList(
                                new ParameterBuilder()
                                        .name("Authorization")
                                        .description("Bearer token")
                                        .modelRef(new ModelRef("string"))
                                        .parameterType("header")
                                        .required(true)
                                        .build()));
                    .apiInfo(metaDados());
        }

        private ApiInfo metaDados() {
            return new ApiInfoBuilder()
                    .title("X-Gracco API")
                    .description("Módulo Gestão Processos.")
                    .version("5.4.0")
                    .contact(new Contact("Finch Soluções", "http://www.finchsolucoes.com.br",     "comercial@finchsolucoes.com.br"))
                    .build();
    }
}

I was using the 2.4.0 version before, it deploys really fast, but it is very slow to fetch de JSON data from /v2/api-docs to swagger-ui.html. On the other side, the swagger-ui.html works like a charm on 2.9.2, but the deploy doesn’t.

Any help is appreciated.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:6
  • Comments:33 (12 by maintainers)

github_iconTop GitHub Comments

4reactions
sgricommented, Aug 26, 2019

While my pull request fixed issue with 2.9.2, it is required, but not sufficient for 3.0.0 because version 3.0.0-SNAPSHOT has introduced another bottleneck in springfox.documentation.spring.web.scanners.ApiModelReader#mergeModelBranch which has been re-written since 2.9.2 was released. ApiModelReader#mergeModelBranch in version 3.0.0 has @SuppressWarnings({“CyclomaticComplexity”, “NPathComplexity”}) annotation which indicates that some code inspection tool detected that code is potentially very slow, and that warning should not have been ignored.

I could not fix it in version 3.0.0, merging algorithm is fairly complicated. Version 3.0.0-SNAPSHOT is significantly slower than 2.9.2 because it has two bottlenecks, and Springfox initialization takes 5 minutes compared to 40 seconds with version 2.9.2 for 158 REST functions. That makes version 3.0.0-SNAPSHOT completely unusable in large projects with more than 150 REST functions.

So the only option to get it fixed is to make a hotfix release 2.9.3 based on 2.9.2.

0reactions
dream-ycommented, Jan 13, 2022

I also have this issue with 2.10.5 that /v2/api-docs is very slow. Is this issue fixed with 2.10.5 version ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring startup performance issues - java - Stack Overflow
A easy way to generate the Spring XML is to write a simple spring application that uses the class path scanning like your...
Read more >
Performance - Spring Boot - Server Response Time-Spring MVC
based on your data my best guess is that the first two steps are slow and untile the DB pool is warmed up...
Read more >
Spring MVC + GAE = slow startup - Google Groups
After deploy, the app takes 50+ seconds to start (sometime the first request get killed after 60 seconds and another app is started)...
Read more >
Speed up Spring Boot Startup Time - Baeldung
However, lazy initialization has a few drawbacks. The most significant disadvantage is that the application will serve the first request slower.
Read more >
SpringFu Solves Slow Spring Startup - Alibaba Cloud
According to unofficial experimental data, transforming the SpringMVC application into the SpringFu structure can shorten the startup time ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found