The controller service made by springboot takes a long time for the first request after a period of time

1. After accessing any interface, the access speed of this interface is normal in a short time. But after a period of time (about a few seconds) the first request access speed is very slow, the client display time is 3000ms, but the server printing time is normally 60ms.
2. This problem does not occur when debugging in the Windows environment of the local machine, but this problem occurs when it is deployed to the Linux system.

Problem:
Whether you use a browser, Postman, curl, or Python (requests) to access the interface, it is very time-consuming to get the first response, and the second access in a short period of time will be much faster;
the server printing time in the controller is always normal When the first response is very slow, the server-side printing time is still 60ms, but the client-side time is 3000ms. Network (client request code and server on the same machine), performance (test environment) and other issues can be ruled out.

solution:

The first : upgrade springboot, spring-boot-starter-parent is upgraded from version 1.4.2 to version 1.5.9. After the upgrade, the problem is solved. (We currently use this solution) If there is a problem that the jsp page cannot be accessed after the upgrade, please refer to http://blog.csdn.net/wwd0501/article/details/79609415 for processing

The second: Deploy the war package to a normal tomcat, the problem is solved. (The way of war package http://blog.csdn.net/wwd0501/article/details/79555215 )

The third: change the built-in Tomcat to undertow, the problem is solved.

Modify the pom file

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
	<exclusions>
		<exclusion>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-tomcat</artifactId>
		</exclusion>
		<exclusion>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-logging</artifactId>
		</exclusion>
	</exclusions>
</dependency>

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325961859&siteId=291194637