title: Extremelly high CPU usage in JSF application
body: <p>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.</p>
  
  <p>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).</p>
  
  <p>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%)</p>
  
  <p>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. </p>
  
  <p>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. </p>
  
  <p>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: <a href="https://db.tt/Aw7L9ZYi" rel="nofollow">https://db.tt/Aw7L9ZYi</a> </p>
  
  <p>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. </p>
  
  <p>Thanks</p>