简体   繁体   中英

Extremelly high CPU usage in JSF application

I wanted to ask for an advice for a possible performance improvements of a JSF based application. We are using Mojarra implementation 2.2.7. Along with it, we have Hibernate (4.2.7.Final), Spring (3.2.3.RELEASE), component library Proimefaces (4.0) and utility library Omnifaces (1.8), but they are not in the focus here. We are deploying everything on Jetty server 8.0.0.M0 for testing purpose, and on Tomcat 7,0 in production.

Our interface is relatively complex as it has many components and dialogs. We try to keep the code for all those distinct components in separate beans. We have used request scoped beans where possible, but ended up with many view scoped beans mostly for the reason we need to interact with the data inside those components and dialogs and the results of those interactions to be displayed immediately via ajax (for instance, when liking something, to update the like count; when following the person, to update the status etc.). In total, there are 25 view scoped beans used just on one page (I monitored their initialisation in a method annotated with @PostConstruct). Also, we sustained of having many Composite Components, only where necessary (around 15 of them, but several of them used multiple times).

We developed JMeter stress test to check the application performance. However, on Amazon m1.medium instance CPU load reached 100% with 4 parallel users, and some requests failed. In order to identify the problem, we profiled it locally with only one real user performing some basic application operations. Results indicate significant CPU usage on 2 methods: - javax.faces.application.ViewHandlerWrapper.restoreView (30-40%) - org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter (25-30%)

Looking at the JProfiler call graph, hot spots and call tree we didn't identify any of the custom methods that have significant influence on such CPU use.

These results were even worse at the beginning but after reading and applying some of the advices we found related to the JSF performance we managed to improve it slightly, and this was mainly as the result of changing the scopes of beans and removing some components that were not necessary.

We have also tried with setting javax.faces.STATE_SAVING_METHOD to both 'client' and 'server', but didn't get any improvements. This is our current web.xml: https://db.tt/Aw7L9ZYi

Comparing to CPU use, Heap use seems not to be a problem. To conclude with the question: is this issue related to possible bad design of our code or it is a performance issue that JSF (Mojarra implementation) has? Is the issue in having many different (view scoped) beans used on one page? Is there anything else that could affect CPU use and that we should try in order to fix the issue? I hope that somebody will have some advice, as we tried everything we could find on the web and don't have any idea what should we do next.

Thanks

Please try to add thoses params

<context-param>// must find the equivalent for majorra
    <param-name>org.apache.myfaces.CHECK_ID_PRODUCTION_MODE</param-name>
    <param-value>true</param-value>
</context-param>  
<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Production</param-value>
</context-param>
<context-param>// must find the equivalent for majorra
    <param-name>org.apache.myfaces.CACHE_OLD_VIEWS_IN_SESSION_MODE</param-name>
    <param-value>soft</param-value>
</context-param>
<context-param>
        <param-name>javax.faces.SERIALIZE_SERVER_STATE</param-name>
        <param-value>false</param-value>
</context-param>    
<context-param>
        <param-name>javax.faces.SERIALIZE_STATE_IN_SESSION</param-name>
        <param-value>false</param-value>
</context-param>       
<context-param>
  <param-name>facelets.REFRESH_PERIOD</param-name>
  <param-value>999999</param-value>
</context-param> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM