Tuning JSF Applications - J-Spring 2008
Tuning JSF Applications - J-Spring 2008
And finally just one tiny little thin Java bean, Mr. Creosote?
First JSF production experience
Pilot with 30 users went great After 3 months a big media event was organized to train first 80 future users Dedicated hardware consisted of 2 production like machines (just to be sure) each serving 40 users Memory usage grew rapidly
Scope
Focus on JSF specific issues Application logic optimization and database tuning is out of scope
DOING ENTERPRISE JAVA RIGHT FROM THE START!
Contents
Introduction The essentials of JSF
JSF life cycle Component tree and view state saving
Improving performance
Performance tweaks Application guidelines
Conclusion
DOING ENTERPRISE JAVA RIGHT FROM THE START!
Introduction
Introduction
JSF is a relatively new technology, although
JSF JSF JSF JSF 1.0 released in Feb 2004 1.1 released in May 2004 1.2 released in Nov 2006 currently defacto standard for web applications
Advantages over other frameworks like ability to create reusable components maintaining own state but little is known about performance implications
Memory usage Bandwidth CPU usage
Why bother?
DOING ENTERPRISE JAVA RIGHT FROM THE START!
Component tree
JSF: Lifecycle
Response complete
Send Request
Restore View
Process Events
Response complete
Process Events
Render Response
Client
Response complete
Server
Response complete
Update Model
Render Page
Render Response
Process Events
Invoke Application
Process Events
Render Response
DOING ENTERPRISE JAVA RIGHT FROM THE START!
Render Response
Example
public Object saveState(FacesContextcontext) { Object values[] = new Object[3]; values[0] = super.saveState(context); values[1] = this.title; values[2] = this.text; return ((Object) (values)); }
DOING ENTERPRISE JAVA RIGHT FROM THE START!
Bottlenecks (1/2)
Memory
Session size caused by server side state saving Session scoped view beans
CPU
State saving and rendering due to high number of components
Bandwidth
Especially with client side state saving
Bottlenecks (2/2)
Quiz question
View state size? Time to process? Total page size?
Hints
Client side state saving Multiple forms No compression Encryption Role-based menu
Answer
Memory: 300kB view state CPU: 550ms Bandwidth: 1,5MB page size
DOING ENTERPRISE JAVA RIGHT FROM THE START!
Example
<ui:debug hotkey="V"/>
Improving performance
Performance improvements
Possibilities depend on framework used
MyFaces JSF RI 1.1/1.2 Ajax4JSF Facelets
Configuration parameters
State serialization Number of views
MyFaces: org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION
Example
<filter> <filter-name>ajax4jsf</filter-name> <filter-class>org.ajax4jsf.FastFilter</filter-class> <filter-class>org.ajax4jsf.webapp.TidyFilter</filter-class> <init-param> <param-name>forceparser</param-name> <param-value>false</param-value> </init-param> </filter>
Conclusion
Summary
JSF performance pitfalls
Memory consumption CPU usage Bandwidth
Discussion
Is JSF still a good choice? Yes,
Clean separation between component state/behavior and rendering Easy to use Standard With appropriate measures it can still perform right
Future enhancement might be to only save state thats different from default:
Facelets XHTML defines component tree with default values This tree is updated with delta state
Questions
References
Tools
JMeter - http://jakarta.apache.org/jmeter/ JAMon - http://jamonapi.sourceforge.net/ YSlow - https://addons.mozilla.org/en-US/firefox/addon/5369
Technologies
JBoss Serialization - http://labs.jboss.com/serialization/ Facelets - https://facelets.dev.java.net
Books
High Performance Web Sites, Steve Souders, http://developer.yahoo.com/performance/