【问题标题】:Small Application Taking Time To Load需要时间加载的小型应用程序
【发布时间】:2011-05-25 08:24:13
【问题描述】:

我有一个使用 Icefaces 1.8.2 和 jsf 1.1 开发的小型 Web 应用程序,它部署到 Oracle 应用服务器 10.1.3。我注意到最初加载应用程序需要一段时间,一旦加载速度令人满意。

如何提高应用程序的初始加载时间?

更新 1

我在后端需要 2-3 秒的查询,但是当我在前端渲染相同的查询时,它需要将近 7 秒。行数只有 1080。我在数据表中呈现这些记录。这可能是什么原因?

更新 2

web.xml

<web-app xmlns="http://java.sun.com/xml/ns/j2ee/web-app_2_3.xsd">
    <context-param>
        <param-name>com.icesoft.faces.debugDOMUpdate</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
        <description>State saving method: "client" or "server" (= default) See JSF Specification
                     2.5.2</description>
    </context-param>
    <context-param>
        <param-name>com.icesoft.faces.concurrentDOMViews</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>com.icesoft.faces.synchronousUpdate</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>com.icesoft.faces.connectionTimeout</param-name>
        <param-value>100000</param-value>
    </context-param>
    <context-param>
        <param-name>com.icesoft.faces.standardRequestScope</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <param-name>org.apache.myfaces.redirectTracker.POLICY</param-name>
        <param-value>org.apache.myfaces.custom.redirectTracker.policy.FullRedirectTrackPolicy</param-value>
    </context-param>
    <context-param>
        <param-name>webAppRootKey</param-name>
        <param-value>app1</param-value>
    </context-param>
    <!-- Faces Servlet -->
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>Persistent Faces Servlet</servlet-name>
        <servlet-class>com.icesoft.faces.webapp.xmlhttp.PersistentFacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>Blocking Servlet</servlet-name>
        <servlet-class>com.icesoft.faces.webapp.xmlhttp.BlockingServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <!-- extension mapping -->
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Persistent Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Persistent Faces Servlet</servlet-name>
        <url-pattern>*.jspx</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Persistent Faces Servlet</servlet-name>
        <url-pattern>*.iface</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Persistent Faces Servlet</servlet-name>
        <url-pattern>/xmlhttp/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Blocking Servlet</servlet-name>
        <url-pattern>/block/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>10000</session-timeout>
    </session-config>
    <!-- Welcome files -->
    <welcome-file-list>
        <welcome-file>index.jsf</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
    <listener>
        <listener-class>com.icesoft.faces.util.event.servlet.ContextEventRepeater</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!-- Spring Security -->
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

applicationContext.xml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:security="http://www.springframework.org/schema/security"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd   http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.2.xsd">    
    <security:authentication-manager alias="_authenticationManager" />   
    <bean id="authenticationProvider"
          class="com.icesoft.icefaces.security.UserDetailsAuthenticationProvider">
        <security:custom-authentication-provider/>
        <property name="userDetailsService" ref="userDetailsService"/>
    </bean>
    <bean id="userDetailsService" class="com.icesoft.icefaces.security.UserDetailsServiceImpl">      
         <constructor-arg ref="userRepository"/>
    </bean>
    <bean id="userRepository"
          class="com.icesoft.icefaces.security.UserDaoImpl"/>
    <bean id="ntlmFilter" class="org.springframework.security.ui.ntlm.NtlmProcessingFilter">
        <security:custom-filter position="NTLM_FILTER"/>
        <property name="stripDomain" value="true"/>
    <property name="defaultDomain" value="XYZ"/>
    <property name="authenticationManager" ref="_authenticationManager" />
    </bean>
    <bean id="ntlmEntryPoint"
          class="org.springframework.security.ui.ntlm.NtlmProcessingFilterEntryPoint">
        <property name="authenticationFailureUrl" value="/accessDenied.jspx"/>
    </bean>
    <bean id="exceptionTranslationFilter"
          class="org.springframework.security.ui.ExceptionTranslationFilter">
        <property name="authenticationEntryPoint" ref="ntlmEntryPoint"/>
    </bean>
    <security:http access-denied-page="/denied.xhtml" entry-point-ref="ntlmEntryPoint"
                   servlet-api-provision="false">
        <security:intercept-url pattern="/accessDenied.jspx" filters="none"/>
        <security:intercept-url pattern="/**" access="ROLE_USER"/>
    </security:http>
</beans>

感谢任何帮助。 谢谢

【问题讨论】:

  • 你测试了哪些浏览器? MSIE 存在严重的 HTML 表格呈现问题。
  • 我在 MSIE 和 Firefox 中进行了测试,这两种浏览器几乎都需要 7 秒来加载页面。
  • 好的,不包括客户端。留下带宽(除了在单个页面中一次显示 1K 行的奇怪要求之外,谁会查看它们全部?)。容器 GZIP 压缩是否开启?
  • @BalusC 我不知道 GZIP 压缩,这是我们需要在应用服务器中打开它的东西?
  • 是的。它可以节省高达 70% 的带宽,并且每个自尊的网络浏览器都支持它。例如,在 Tomcat 中,只需在/conf/server.xml&lt;Connector&gt; 元素中设置compression="on"。试一试。

标签: web-applications jsf icefaces


【解决方案1】:

最好在数据库端使用分页,而不是一次获取所有记录。最终用户一次最多只能在屏幕上看到 10-20 条记录,并且可能会忽略大部分结果。

您还可以在特定列上引入排序,以便用户可以更好地找到结果。让用户直接从找到的所有结果页面迁移到特定的结果页面,而不需要遍历每个结果页面。

这将减少从数据库中获取不必要的记录,并且可以提高许多用户访问时的性能。

【讨论】:

  • @Nayan,我只有 1080 条记录,所以您认为这可能与数据库负载或记录数高有关吗?我严重怀疑。最重要的是,该应用程序处于测试阶段,目前只有一个用户在访问该应用程序。
  • 正如另一篇文章中所建议的,我认为没有任何理由选择应用程序服务器,您还提到它是一个小型应用程序。根据提供的详细信息,即数据和服务器,我可以说尝试使用网络服务器。也可以从数据库中检索数据,但要保持与视图不同——不要在页面上显示,这样可以发现数据检索速度慢还是在页面上显示需要时间。
  • 如果数据库和应用服务器在同一个网络上,一次从数据库中获取所有记录不会减慢速度。使用数据表分页时,只有该“页面”上的记录从应用服务器传输到客户端的浏览器。应用服务器和数据库之间的传输时间可以忽略不计。但是,如果两者都在不同的网络上或者之间的链接速度较慢,那么您可以使用数据库分页
  • @Ali 无论性能是否受到影响,实现分页都是一种很好的做法。将来,可能会有服务器迁移,然后改变事情是不利的。
  • 我设法减少了获取记录的时间。现在唯一剩下的就是加载应用程序的时间了。不知道如何提高加载小应用程序的速度。
【解决方案2】:

您是否尝试过在不同的应用服务器上进行测试?我没有使用过 Oracle Application Server,但我发现在 jetty 上运行的应用程序的启动速度比在 Tomcat 上运行的相同应用程序要慢得多。 我建议尝试 Tomcat。即使这不是您的实际部署选项,这至少应该有助于诊断。

【讨论】:

  • 应用服务器的变化有什么不同吗?
  • 您可能对此comparison of app servers 感兴趣,该comparison of app servers 引用自另一个stackoverflow question。虽然我的测试使用的是 Tomcat 7,而本次调查仅涵盖 Tomcat 6。但是,它清楚地表明 Tomcat 和 Jetty 的重新部署和应用启动时间都比 Oracle 应用服务器更快。
  • 我很欣赏你提到的。但是,除了 Oracle Apps Sever,我们没有其他选择。经理不同意改变容器。
【解决方案3】:

通过重写一些代码和sql语句,我已经将应用程序的性能提高到了令人满意的水平。

感谢大家的帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-21
    • 2018-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多