uiComponent树内存使用情况

发布于 2024-10-15 06:26:03 字数 1945 浏览 6 评论 0原文

您好,

我有丰富的面孔应用程序(3.3.2.SR1)。该应用程序使用 ModelPanel 来查看实体。所有模式面板在我想要显示它们之前都不会渲染(rendered = false)。应用程序变得很大,并且使用一个面板到其他面板的大量关系。一切正常,但看起来 richfaces 在内存中为所有可能的情况创建 UIComponent 树(如果组件 rendred 为 true 或 false)。当我尝试检查应用程序的内存使用情况时(我使用 YourKit Java Profiler 来满足这些需求),我发现它在一个会话中使用了大量内存。

我将 Facelets 与 richfaces 一起使用,并且我尝试使用

<c:if test="rendred condition"... /> content </c:if>

它开始使用显着更少的内存,但是...... 当我使用面板重新渲染该区域时,父屏幕上的控件将停止工作。我怀疑这是因为每次更改组件树时,它都会重新创建整个树,并且我有不同步的客户端(html)和服务器(faces)部分。

有人可以建议我减少内存使用的方法吗?我有一个真正的问题,因为 HeapMemory 中的 StandardSession 对象使用 60-150Mb。几乎所有这些内存都用于 UIControl。

问题示例:

我的页面引用了 panel1、panel2、panel3。

面板是:

<rich:modalPanel >
    <a4j:outputPanel layout="block" 
             rendered="#{PanelBeanHolder.renderedViewScreen}">
        <ui:insert name="panelContent" />
    </a4j:outputPanel>
</rich:modalPanel>

仅当执行此操作时才渲染面板。并且在需要之前不想加载输出面板的 UI 控件。

先感谢您。

PS 我尝试执行以下操作来改善这种情况:

在 web.xml 中配置会话中的视图数

<context-param>
    <param-name>com.sun.faces.numberOfViewsInSession</param-name>
    <param-value>4</param-value>
</context-param>

<context-param>
    <param-name>com.sun.faces.numberOfLogicalViews</param-name>
    <param-value>4</param-value>
</context-param>

它必须改进 StateHolder 对象,但没有太大帮助。我做了测量,当这些数字增加时,内存使用量也会增加。但是,当我厌倦将它们设置为 1,1 时 - 有些页面停止工作。有时请求会转发到欢迎页面。 2,2 改善了情况,但转发到欢迎页面的问题仍然发生。

尝试在 javax.faces.STATE_SAVING_METHOD 中使用客户端模式。 UIComponent 模型仍然使用大量内存。即使对象被序列化并且必须以表单形式存储。

尝试重写stateManager 在faces.config中:

<state-manager>org.ajax4jsf.application.CompressAjaxStateManager</state-manager>

并重写buildViewState和restoreView以压缩流。 这没有多大帮助。

Greetings,

I have rich faces application (3.3.2.SR1). The application uses ModelPanel to view entities. All modal panels are not rendered until I want to show them (rendered = false). Application becomes to be big, and uses a lot relations from one panel to others. All works fine, but it looks like richfaces creates UIComponent tree in memory for all possible cases if component rendred is true or false. When I tried to check memory usage of application (I used YourKit Java Profiler for these needs) I see that it uses a lot of memory for one session.

I am using Facelets together with richfaces and I tried to use

<c:if test="rendred condition"... /> content </c:if>

It starts to use significantly less memory, but...
when I rerender the area with panel, controls on parent screen are stopped to work. I suspect that it is because of every time when component tree is changed it recreates whole tree, and I have unsynchronized client (html) and server (faces) parts.

Could somebody suggest me the way how to reduce memory usage? I have real problem with it as StandardSession object in HeapMemory uses 60-150Mb. And almost all of this memory used for UIControls.

Example of the problem:

I have page which has references to panel1, panel2, panel3.

Panel is:

<rich:modalPanel >
    <a4j:outputPanel layout="block" 
             rendered="#{PanelBeanHolder.renderedViewScreen}">
        <ui:insert name="panelContent" />
    </a4j:outputPanel>
</rich:modalPanel>

I am rendering panel only when action for this is performed. And do not want to load the UI controls for output panel until I need it.

Thank you in advance.

P.S. I tried to do the following to improve the situation

Configure number of views in session inside web.xml with:

<context-param>
    <param-name>com.sun.faces.numberOfViewsInSession</param-name>
    <param-value>4</param-value>
</context-param>

<context-param>
    <param-name>com.sun.faces.numberOfLogicalViews</param-name>
    <param-value>4</param-value>
</context-param>

It has to improve StateHolder object, but it doesn't help a lot. I did measuring and memory usage is grows when these number are grow. But, when i tired to set them to 1,1 - some pages stopped work. Sometimes request is forwarded to the welcome page. 2,2 improved the situation, but the issue with forwarding to welcome pages still happens.

Tried to use client mode in javax.faces.STATE_SAVING_METHOD. It still uses a lot of memory for UIComponent model. Even if objects are serialised and have to be stored in the form.

Tried to rewrite stateManager
in faces.config:

<state-manager>org.ajax4jsf.application.CompressAjaxStateManager</state-manager>

and rewrite buildViewState and restoreView for compressing the stream.
It doesn't help a lot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心在旅行 2024-10-22 06:26:03

JSF 使用在请求之间维护的有状态组件树。默认情况下,这通常在会话中维护。您可以使用一些功能来控制它。

配置状态保存参数

通常有特定于实现的参数来控制会话中存储的视图数量 - 根据您的应用程序的行为方式,这可能是一个轻松的胜利。

您可以使用 javax.faces.STATE_SAVING_METHOD 参数将状态保存在表单中。但是,请注意,每个请求都会发送更多信息,并且允许客户端决定服务器端状态存在安全风险(确保您对实现加密此数据的方式感到满意)。您需要检查与组件库(即 RichFaces)的兼容性,尤其是在使用 AJAX 时。

JSF 2 使用新的状态保存机制来减少会话开销;您的 faces-config.xml 需要更新到 2.0 版本。我相信这个想法来自 Apache Trinidad,所以你也许能够提取一个预-从那里开始 JSF 2 版本。

执行您自己的状态保存和/或视图创建

实现您自己的StateManager 和/或 ViewHandler 允许您以编程方式控制视图的处理方式。例如,您可以编写一个将视图持久保存到数据库的 StateManager(具有适当的超时和清理功能)。

使用组件绑定和瞬态控件

您可以通过编程方式控制组件的创建方式。从绑定规范来看:

  • 首次创建组件实例时(通常是通过 JSP 页面中的 UIComponentELTag 引用),JSF 实现将检索名称的 ValueExpression绑定,并对其调用 getValue() 。如果此调用返回一个非空 UIComponent 值(因为 JavaBean 已经以编程方式实例化并配置了一个组件),则该实例将被添加到正在创建的组件树中。如果调用返回 null,则将创建一个新的组件实例,并将其添加到组件树中,并且将在 ValueExpression 上调用 setValue()(这将导致属性在要设置为新创建的组件实例的 JavaBean 上)。
  • 在请求处理生命周期的“恢复视图”阶段重新创建组件树时,对于每个具有与名称“绑定”关联的 ValueExpression 的组件,setValue() 将被调用,传递重新创建的组件实例。


您可以将其与 一起使用子组件的瞬态属性以编程方式控制子组件的创建/销毁。这是手动的,有点混乱,但在极端情况下可能有效。

我确信这不是一个详尽的列表。

JSF uses a stateful component tree that is maintained between requests. By default, this is usually maintained in the session. There are features you can use to control this.

Configure state saving parameters

There are usually implementation-specific parameters to control the number of views stored in the session - depending on how your application behaves, this might be an easy win.

You can save the state in forms using the javax.faces.STATE_SAVING_METHOD parameter. However, be aware you're sending more information per request and there are security risks in allowing the client to dictate server-side state (ensure you are happy with how your implementation encrypts this data). You will need to check compatibility with your component libraries (i.e. RichFaces), especially if you're using AJAX.

JSF 2 uses a new state-saving mechanism that reduces the session overhead; your faces-config.xml will need to be updated to the 2.0 version. I believe this idea came from Apache Trinidad, so you may be able to extract a pre-JSF 2 version from there.

Do your own state saving and/or view creation

Implementing your own StateManager and/or ViewHandler lets you take programmatic control over how views are handled. For example, you could write a StateManager that persisted views to a database (with appropriate time-out and clean-up).

Use component binding and transient controls

You can take programmatic control over how components are created. From the spec on binding:

  • When a component instance is first created (typically by virtue of being referenced by a UIComponentELTag in a JSP page), the JSF implementation will retrieve the ValueExpression for the name binding, and call getValue() on it. If this call returns a non-null UIComponent value (because the JavaBean programmatically instantiated and configured a component already), that instance will be added to the component tree that is being created. If the call returns null, a new component instance will be created, added to the component tree, and setValue() will be called on the ValueExpression (which will cause the property on the JavaBean to be set to the newly created component instance).
  • When a component tree is recreated during the Restore View phase of the request processing lifecycle, for each component that has a ValueExpression associated with the name “binding”, setValue() will be called on it, passing the recreated component instance.

You could probably use this with the transient property on children to control programmatically control creation/destruction of child components. This is manual and a bit messy, but might work in extreme cases.

I'm sure this isn't an exhaustive list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文