0

My motivation for this question are slow response times of our application's REST endpoints, ca 500ms.

To narrow down the cause, I followed this Spring Boot getting started tutorial and created very basic single endpoint app. And the repsponse times are the same, ca 500ms.

Code:

@RestController
public class Rest {

    @GetMapping("/rest")
    public String index() {
        return "Greetings from Spring Boot!";
    }
}

@SpringBootApplication
public class App extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(App.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.kousalik</groupId>
    <artifactId>boot</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
<properties>
    <java.version>1.8</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.6.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

The response times with embedded Tomcat are the same, ca 500ms.

JMeter

Why is Spring Boot so slow by default? All I found about performance usualy mentions only startup speed, memory fottprints etc. What is wrong with this simple example?

I'm running it on Win 10, JDK 1.8.144, Tomcat 8.5.20.

Kousalik
  • 3,111
  • 3
  • 24
  • 46
  • 3
    It's not. Something is probably wrong on your network or machine. The same example takes 5ms. to get the response here (in Chrome). An ab load test shows 1ms on average, with 4ms. max. – JB Nizet Sep 01 '17 at 11:09
  • [This guy](https://stackoverflow.com/a/35713866/7212399) has total different opinion. – Pratik Ambani Sep 01 '17 at 11:09
  • that other post is about startup time, not response time. @JBNizet is right, I think. – Brian Clozel Sep 01 '17 at 11:19
  • @JBNizet thanks for comparison! You are right. It's the Bitdefender antivirus. Disabling it gets the response times to 1-2ms. Thanks – Kousalik Sep 01 '17 at 11:25
  • BTW, according to this article - [Tomcat vs. Jetty vs. Undertow: Comparison of Spring Boot Embedded Servlet Containers](https://examples.javacodegeeks.com/enterprise-java/spring/tomcat-vs-jetty-vs-undertow-comparison-of-spring-boot-embedded-servlet-containers/), Undertow has the best performance with Tomcat and Jetty. – LHCHIN Oct 17 '17 at 05:49

0 Answers0