Slow initial http requests with spring in k8s

8/4/2021

I have a simple java app with a controller that simply returns a hello world jsp. It works as expected deploying in a non-k8s environment, however when deploying on k8s it takes about 15 seconds to respond the first time the page is requested. After the first request, performance is back to normal responding in a split second. I've enabled debug logs for spring but nothing much useful there, just 15 seconds of no logs:

2021-08-04 16:38:16,856 DEBUG org.springframework.web.servlet.view.InternalResourceView: Forwarding to [/WEB-INF/jsp/test.jsp]
...
2021-08-04 16:38:31,452 DEBUG org.springframework.security.web.header.writers.HstsHeaderWriter: Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@5073a20b
2021-08-04 16:38:31,453 DEBUG org.springframework.security.web.context.HttpSessionSecurityContextRepository$SaveToSessionResponseWrapper: SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
2021-08-04 16:38:31,455 DEBUG org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor: Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
2021-08-04 16:38:31,459 DEBUG org.springframework.web.servlet.FrameworkServlet: Completed 200 OK
2021-08-04 16:38:31,459 DEBUG org.springframework.security.web.access.ExceptionTranslationFilter: Chain processed normally
2021-08-04 16:38:31,460 DEBUG org.springframework.security.web.context.SecurityContextPersistenceFilter: SecurityContextHolder now cleared, as request processing completed

I was wondering if anyone has any advice on what might be going on, or how I could investigate further?

-- James
java
kubernetes
spring

0 Answers