首页 > 解决方案 > 在 k8s 中使用 spring 缓慢的初始 http 请求

问题描述

我有一个简单的 java 应用程序,它带有一个简单地返回一个 hello world jsp 的控制器。它在非 k8s 环境中按预期工作,但是在 k8s 上部署时,第一次请求页面时响应大约需要 15 秒。在第一次请求之后,性能会在瞬间恢复正常响应。我已经为 spring 启用了调试日志,但那里没有什么用处,只有 15 秒没有日志:

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

我想知道是否有人对可能发生的事情有任何建议,或者我该如何进一步调查?

标签: javaspringkubernetes

解决方案


推荐阅读