【发布时间】:2014-11-02 16:41:01
【问题描述】:
我们的 Webflow (2.3.1) 应用程序为我们通过浏览器打开的每个新流申请大量内存。
下面的屏幕截图显示了我们应用程序的内存使用情况。当应用程序启动时,它需要初始 400 Mb。之后,我们在浏览器中打开 4 个单独的、相同的 Webflow TEST 页面,每个页面都声称需要大约 90Mb 的额外内存。
每个测试页面都是从它自己的简单流程定义开始的:
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/webflow"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd" start-state="start">
<view-state id="start" view="test/test1">
</view-state>
<end-state id="end"/>
<bean-import resource="../flow-beans.xml"/>
</flow>
JSP测试页面也很简单,就是空一行文字。
当我们当前将 JVM 内存设置为 1.5Gb 时,应用程序在打开大约 15 个不同的流后最终在服务器上崩溃并出现 OutOfMemoryExceptions。考虑到我们屏幕的低复杂性,1.5 Gb 似乎有点多..
我们想知道 Webflow 为这些简单的流/页面要求的内存量是否是预期的,因此我们是否应该为服务器 JVM 分配更多内存。如果没有,我们想知道如何减少这种内存使用量。
下面是我们的整个 webflow 配置。
我们尝试添加一个 flow-execution-repository 标记并使用 max-executions-snapshots 和 max-executions 值,但即使是最保守的设置也不会改变我们看到的内存使用情况。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:webflow="http://www.springframework.org/schema/webflow-config"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/webflow-config
http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!-- Launches new flow executions and resumes existing executions. -->
<webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry">
</webflow:flow-executor>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:our.properties" />
<property name="placeholderPrefix" value="$xxxx"></property>
</bean>
<tx:annotation-driven transaction-manager="$xxxx{txManager}" />
<!-- Creates the registry of flow definitions for this application -->
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<webflow:flow-location-pattern value="classpath:flows/**/*-flow.xml" />
</webflow:flow-registry>
<bean id="viewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
<property name="viewResolvers" ref="viewResolver" />
</bean>
<bean id="expressionParser" class="org.springframework.expression.spel.standard.SpelExpressionParser">
<constructor-arg name="configuration">
<bean class="org.springframework.expression.spel.SpelParserConfiguration">
<constructor-arg name="autoGrowCollections" value="true" />
<constructor-arg name="autoGrowNullReferences" value="false" />
</bean>
</constructor-arg>
</bean>
<bean id="webflowExpressionParser" class="org.springframework.webflow.expression.spel.WebFlowSpringELExpressionParser">
<constructor-arg name="expressionParser" ref="expressionParser" />
</bean>
<webflow:flow-builder-services id="flowBuilderServices" view-factory-creator="viewFactoryCreator" validator="validator" expression-parser="webflowExpressionParser"/>
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
<bean id="projectVersion" class="our.company.versions.ProjectVersionUtil">
<property name="xxxxVersion" value="$xxxx{xxxx.version}" />
<property name="systemConfigurationDao">
<ref bean="SystemConfigurationDao"/>
</property>
</bean>
</beans>
【问题讨论】:
-
我怀疑您每次需要时基本上都在重新加载单例。我怀疑您的
flow-beans.xml包含应该是应用程序单例但为每个流实例重新加载的 bean。 -
我只是在一个活页夹的构造函数中放了一个断点,它会在我们访问的每个新流中命中,所以看起来你是对的。我将对此进行进一步调查,稍后会回来提供更多信息。非常感谢。
-
另外,展示如何配置 web.xml 和 *-flow xmls。
-
@M.Deinum:我们现在正在从 web.xml 加载 flow-beans.xml 作为正常的应用程序上下文,并且我们已经从流定义中删除了所有 bean-import 标签。结果:内存使用量减少 60-70%。您能否将您的答案复制到新答案中,然后我将其标记为解决方案。再次感谢。
标签: memory out-of-memory spring-webflow