【发布时间】:2016-01-11 03:48:48
【问题描述】:
我有一个在 GAE 中运行的 Java Web 应用程序。我使用 Spring 进行 servlet 调度。我使用它是为了可以使用注解来定义我的 servlet 中的调用,并让它完成所有的参数解析和结果转换。 GAE 中 Web 应用程序的加载时间约为 10 秒,我想知道是否有办法缩短它。谢谢。
这是我的 web.xml
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>publisher-servlet</servlet-name>
<servlet-class>
com.example.webapp.PublisherServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>publisher-servlet</servlet-name>
<url-pattern>/publisher</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>
<context-param>
<param-name>contextClass</param-name>
<param-value>com.example.webapp.CustomXmlWebApplicationContext</param-value>
</context-param>
还有我的 mvc-dispatcher-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<mvc:annotation-driven />
<bean class="com.y2apps.quoteformessenger.webapp.ClientController">
</bean>
这是启动服务器的第一次调用的服务器日志
I 2015-10-13 14:19:54.937 200 119.69 KB 10.98 s I 14:19:59.222 I 14:20:05.916 /getallcategorylists?typeId=2
84.229.82.245 - - [13/Oct/2015:04:19:54 -0700] "GET /getallcategorylists?typeId=2 HTTP/1.1" 200 122562 - "okhttp/2.2.0" "iron-core-93812.appspot.com" ms=10978 cpu_ms=13017 cpm_usd=0.01369737 instance=00c61b117c057f572d9967e34ef8e65bb7cbfdcd app_engine_release=1.9.27 trace_id=-
I 14:19:59.222 javax.servlet.ServletContext log: Initializing Spring FrameworkServlet 'mvc-dispatcher'
I 14:20:05.916 This request caused a new process to be started for your application, and thus caused your application code to be loaded for the first time. This request may thus take longer and use more CPU than a typical request for your application.
【问题讨论】:
-
你考虑过Warmup Request吗?它不会缩短加载时间,而是将其隐藏:“在任何实时请求到达该实例之前,预热请求将应用程序代码加载到新实例中。”
-
假设你也有一个
COntextLoaderListener停止加载你的 bean 两次。 -
启动应用引擎需要一段时间,这取决于运气/负载,而且 spring 本身也不是最快的,特别是如果你让它做很多自动的事情,比如类路径扫描。你做的动态越少,它应该越快。您可以在本地进行测试。
-
谢谢安迪。我在下面回复了 Patrice,为什么这不能解决我的问题。
-
谢谢 M. Deinum。你是什么意思?我如何加载 bean 两次?
标签: java xml spring google-app-engine spring-mvc