Are your XPages applications performing like a Florida senior citizen driving in the left lane at 55 mph? A key to speeding up your XPages applications is knowledge of the JSF lifecycle, partial refresh and partial execution. This session will cover these concepts and then apply them to optimizing an XPages application. Learn how to use tools to measure the performance of your XPages and determine where the bottlenecks are. Several sample applications will be analyzed along with alternative programming choices to improve their performance. Learn how to dramatically increase your XPages performance and make your users happy - you might even get a speeding ticket after this session!
A healthy diet for your Java application Devoxx France.pdf
Connect 2016-Move Your XPages Applications to the Fast Lane
1. AD-1094 : Move Your XPages
Applications to the Fast Lane
Howard Greenberg, Partner, TLCC
February 1, 2016
2. Move your XPages Applications to the Fast Lane
2
Are your XPages Apps are like this???
3. Your Presenter Today – Howard Greenberg
• Certified Lotus Instructor since R3
• Co-founded TLCC in 1997
• IBM Champion
• Prior to that 12 years at IBM in the PC group
• Also…
– Certified Public Accountant
– Certified Information Systems Auditor (CISA)
– Certified Flight Instructor
3
4. Agenda
• What affects XPages Peformance
• XPages Lifecycle
• Partial Refresh vs. Partial Execution
• Tools to Analyze Peformance
• Case Studies
• Questions???
4
5. What affects XPages Performance?
5
Client:
Browser
OS
CPU
Hard drive
Memory
Network
Speed and
Latency Server:
Hardware
OS
Application (Domino)
6. What’s Involved on the Server...
• Server HW and OS pass network request to Domino
• Domino networking and HTTP Task
• XPages runtime engine
– Restore state (might read from disk)
– Java code builds HTML, etc. that gets sent to
browser
• Uses the JSF Lifecycle (more on this later)
• Calls Backend Domino objects if needed
• Domino passes response (HTML, CSS, JS, etc.) to OS
and via network to client
6
8. JSF Life Cycle - Post
8
Restore View
•Restore component tree
•Events:
•afterRestoreView
Apply Request
Values
•Copy data to Editable
controls
Process Validations
•Validations
•Converters
Update Model
Values
•Move values to data
source
Invoke Application
•Application logic
•Events:
•onClientLoad (XPage,
etc)
•on… events of button,
etc.
Render Response
•Convert to HTML, etc.
•Events:
•beforeRenderReponse
•afterRenderResponse
Request
Response
9. Lifecycle1 XPage – Initial Page Load (GET Request)
9
Render Response
•Rendered property for id: label1
•Label property for id: label1
•Rendered property for id: inputText1
•Default value property for id: inputText1
•Rendered property for id: label2
•Rendered property for id: comboBox1
•values property for id: comboBox1
•values property for id: comboBox1
•Rendered property for id: computedField1
•Value property for id: computedField1
•Rendered property for id: computedField2
•Value property for id: computedField2
12 SSJS Calls
10. Lifecyle1 – Submit POST Request (Full Update)
Restore View Apply Request Values (8)
•Rendered property for id: label1
•Rendered property for id: inputText1
•Rendered property for id: inputText1
•Rendered property for id: label2
•Rendered property for id: comboBox1
•Rendered property for id: comboBox1
•Rendered property for id: computedField1
•Rendered property for id: computedField2
Process Validations (11)
•Rendered property for id: label1
•Rendered property for id: inputText1
•Rendered property for id: inputText1
•Validation for inputText1
•Default value property for id: inputText1
•Rendered property for id: label2
•Rendered property for id: comboBox1
•Rendered property for id: comboBox1
•values property for id: comboBox1
•Rendered property for id: computedField1
•Rendered property for id: computedField2
Update Model Values (8)
•Rendered property for id: label1
•Rendered property for id: inputText1
•Rendered property for id: inputText1
•Rendered property for id: label2
•Rendered property for id: comboBox1
•Rendered property for id: comboBox1
•Rendered property for id: computedField1
•Rendered property for id: computedField2
Invoke Application (1)
•OnClick event for id: button1
Render Response (11)
•Rendered property for id: label1
•Label property for id: label1
•Rendered property for id: inputText1
•Rendered property for id: label2
•Rendered property for id: comboBox1
•values property for id: comboBox1
•values property for id: comboBox1
•Rendered property for id: computedField1
•Value property for id: computedField1
•Rendered property for id: computedField2
•Value property for id: computedField239 SSJS Calls
10
11. When to Execute - # vs $
• # is Compute dynamically
– Executed every time the page is
rendered
– Use for values that are likely to change
• $ is Compute on Page Load
– Executed when the page is first loaded
– Use for values that don't change
11
<xp:label id="label1">
<xp:this.value>
<![CDATA[#{javascript:return “My
Label”;}]]>
</xp:this.value>
</xp:label>
12. Lifecyle2 – Submit (Full Update) - On Page Load
12
Restore View Apply Request Values
•Rendered property for id: label1
•Rendered property for id: inputText1
•Rendered property for id: inputText1
•Rendered property for id: label2
•Rendered property for id: comboBox1
•Rendered property for id: comboBox1
•Rendered property for id: computedField1
•Rendered property for id: computedField2
Process Validations (2)
•Rendered property for id: label1
•Rendered property for id: inputText1
•Rendered property for id: inputText1
•Validation for inputText1
•Default value property for id: inputText1
•Rendered property for id: label2
•Rendered property for id: comboBox1
•Rendered property for id: comboBox1
•values property for id: comboBox1
•Rendered property for id: computedField1
•Rendered property for id: computedField2
Update Model Values
•Rendered property for id: label1
•Rendered property for id: inputText1
•Rendered property for id: inputText1
•Rendered property for id: label2
•Rendered property for id: comboBox1
•Rendered property for id: comboBox1
•Rendered property for id: computedField1
•Rendered property for id: computedField2
Invoke Application (1)
•OnClick event for id: button1
Render Response (3)
•Rendered property for id: label1
•Label property for id: label1
•Rendered property for id: inputText1
•Rendered property for id: label2
•Rendered property for id: comboBox1
•values property for id: comboBox1
•values property for id: comboBox1
•Rendered property for id: computedField1
•Value property for id: computedField1
•Rendered property for id: computedField2
•Value property for id: computedField2
6 SSJS Calls, saved 33
Changed all Rendered and
Values (comboBox) to only
compute on Page Load
13. Options for dynamically computing the Rendered:
• Scoped variables
– Still get calculated but do the heavy lifting once and then
read the scoped variable in the Rendered property
• DataContexts
– Compute a value at the Xpage or Panel level once
– Refer to the value using EL (much faster than SSJS)
13
But I need dynamic Rendering!
14. DataContext - Pitfall
• Be careful binding data context variables dynamically
– They will be recomputed multiple times, even when in
partial execution mode and if they are not in use (six times!)
• Apply Request Values
• Process Validations
• Update Model Values
• Invoke Application
• Twice in Render Response!
• If computed on page load only computed when page loads
• See Paul Withers blog entry to learn how to set a data context
value via code
14
15. Partial Refresh vs. Partial Execution?
• Partial Refresh (Update)
– Computes entire XPage, only sends back
what is in the partial refresh id (refreshId)
• Partial Execution
– Only calculates what is in the area
specified (execId)
15
16. Partial Refresh Demo - Results
16
Restore View Apply Request Values (8)
•Rendered property for id: label1
•Rendered property for id: inputText1
•Rendered property for id: inputText1
•Rendered property for id: label2
•Rendered property for id: comboBox1
•Rendered property for id: comboBox1
•Rendered property for id: computedField1
•Rendered property for id: computedField2
Process Validations (11)
•Rendered property for id: label1
•Rendered property for id: inputText1
•Rendered property for id: inputText1
•Validation for inputText1
•Default value property for id: inputText1
•Rendered property for id: label2
•Rendered property for id: comboBox1
•Rendered property for id: comboBox1
•values property for id: comboBox1
•Rendered property for id: computedField1
•Rendered property for id: computedField2
Update Model Values (8)
•Rendered property for id: label1
•Rendered property for id: inputText1
•Rendered property for id: inputText1
•Rendered property for id: label2
•Rendered property for id: comboBox1
•Rendered property for id: comboBox1
•Rendered property for id: computedField1
•Rendered property for id: computedField2
Invoke Application (1)
•OnClick event for id: button1
Render Response (2)
•Rendered property for id: label1
•Label property for id: label1
•Rendered property for id: inputText1
•Rendered property for id: label2
•Rendered property for id: comboBox1
•values property for id: comboBox1
•values property for id: comboBox1
•Rendered property for id: computedField1
•Value property for id: computedField1
•Rendered property for id: computedField2
•Value property for id: computedField2
30 SSJS Calls, saved 9
Only Savings
were here!
17. Partial Refresh Pros and Cons
• Pros
– Reduced control processing in the render response phase
– Smaller response from server
• Means reduced network usage
– Better UI experience
• Rest of the page is still visible while waiting for a response
• Cons
– Controls like computed fields outside refresh area don’t refresh
– Be careful turning this on for a completed XPage (TEST!)
– Can only update one area (one id)
• Workaround from Tim Tripcony on XPages Wiki
17
18. Partial Execution Demo - Results
18
Restore View Apply Request Values (1)
•Rendered property for id: label1
•Rendered property for id: inputText1
•Rendered property for id: inputText1
•Rendered property for id: label2
•Rendered property for id: comboBox1
•Rendered property for id: comboBox1
•Rendered property for id: computedField1
•Rendered property for id: computedField2
Process Validations (1)
•Rendered property for id: label1
•Rendered property for id: inputText1
•Rendered property for id: inputText1
•Validation for inputText1
•Default value property for id: inputText1
•Rendered property for id: label2
•Rendered property for id: comboBox1
•Rendered property for id: comboBox1
•values property for id: comboBox1
•Rendered property for id: computedField1
•Rendered property for id: computedField2
Update Model Values (1)
•Rendered property for id: label1
•Rendered property for id: inputText1
•Rendered property for id: inputText1
•Rendered property for id: label2
•Rendered property for id: comboBox1
•Rendered property for id: comboBox1
•Rendered property for id: computedField1
•Rendered property for id: computedField2
Invoke Application (1)
•OnClick event for id: button1
Render Response (12)
•Rendered property for id: label1
•Label property for id: label1
•Rendered property for id: inputText1
•Default value property for id: inputText1
•Rendered property for id: label2
•Rendered property for id: comboBox1
•values property for id: comboBox1
•values property for id: comboBox1
•Rendered property for id: computedField1
•Value property for id: computedField1
•Rendered property for id: computedField2
•Value property for id: computedField2
16 SSJS Calls
Saved 13
19. Partial Execution Pros and Cons
• Pros
– Reduced processing in the 3 data-processing phases
• Cons
– Control with onClick event has to be inside the execId area
– Editable values outside of the executed area do not get
submitted/updated (reset to default values)
– Existing XPages need analysis/testing before using this
• Current onclick events might refer to controls where the data
is not submitted
– ExecMode available in 8.5.1
– Have to use source to enter ExecId in 8.5 (9.0 has Designer UI)
19
20. Partial Refresh AND Execution Demo - Results
Restore View Apply Request Values (1)
•Rendered property for id: label1
•Rendered property for id: inputText1
•Rendered property for id: inputText1
•Rendered property for id: label2
•Rendered property for id: comboBox1
•Rendered property for id: comboBox1
•Rendered property for id: computedField1
•Rendered property for id: computedField2
Process Validations (1)
•Rendered property for id: label1
•Rendered property for id: inputText1
•Rendered property for id: inputText1
•Validation for inputText1
•Default value property for id: inputText1
•Rendered property for id: label2
•Rendered property for id: comboBox1
•Rendered property for id: comboBox1
•values property for id: comboBox1
•Rendered property for id: computedField1
•Rendered property for id: computedField2
Update Model Values (1)
•Rendered property for id: label1
•Rendered property for id: inputText1
•Rendered property for id: inputText1
•Rendered property for id: label2
•Rendered property for id: comboBox1
•Rendered property for id: comboBox1
•Rendered property for id: computedField1
•Rendered property for id: computedField2
Invoke Application (1)
•OnClick event for id: button1
Render Response (2)
•Rendered property for id: label1
•Label property for id: label1
•Rendered property for id: inputText1
•Rendered property for id: label2
•Rendered property for id: comboBox1
•values property for id: comboBox1
•values property for id: comboBox1
•Rendered property for id: computedField1
•Value property for id: computedField1
•Rendered property for id: computedField2
•Value property for id: computedField2
6 SSJS Calls,
saved 33
20
21. Using the loaded Property
• Loaded = true
– In component tree
• Loaded = false
– Control is not created
– Can never be rendered
or accessed
– Saves memory too
21
Loaded only computed once in the createView phase
22. Watch Out for @DbLookup
• @DbLookup about 3-4 times slower than SSJS
– res = @DbLookup(db,"CustomersByNameView",names[i], "phone");
vs.
– doc = vw.getDocumentByKey(names[i], true);
res = doc.getItemValueString("phone");
• Five lookups repeated 100 times
– @DbLookup averaged about 1728ms
– getDocumentByKey averaged 510ms
• Other @Functions not tested
22
23. Life Cycle Performance Suggestions
• Most properties, like CSS “style” are
only computed in the
RenderResponse phase
• Watch and minimize:
– Rendered property (when dynamic)
• Computed multiple times!
• Use dataContexts or scoped variables
when able
• Use both Partial Refresh (Update)
and Partial Execute when able
23
24. Tools to Test/Debug Performance Issues
• Print statements
– In rendered/visible computations to see how often executed
• print("panel2 evaluating rendered property");
– In the XPages events such as:
• before/afterPageLoad, afterRestoreView,
before/afterRenderResponse
– In the document data source events:
• queryNewDocument, postSaveDocument, etc.
– Or use the Debug Toolbar (don‘t have to view server
console)
• http://www.openntf.org/main.nsf/project.xsp?r=project/
XPage%20Debug%20Toolbar
24
25. More Tools
• Server OS tools to monitor CPU, memory and network
• Browser developer tools
– for watching network transactions, partial updates, response
times
– BROWSER: Firebug, Chrome, etc. developer tools
– XPiNC: FirebugLite from ExtLib
• Java / Javascript Debugging
– Degrades performance but can inspect objects
• Use the Eclipse Java debugger
25
26. XPages Toolbox
• XPages based Application
– Runs on the Domino server or the Notes client
– An NSF needs to be installed on the server/Notes client
– A profiler jar file is added to the JVM directory
– Modify the security policy file
– Notes.ini is modified (all in the documentation!)
• Measures CPU performance and memory allocation
• Available from OpenNTF.org
– Free open source project
– http://www.openntf.org/main.nsf/project.xsp?r=project/XPa
ges%20Toolbox
26
27. XPages Toolbox Functionality
• Measures CPU and Wall time
• Back end Domino object profiling
• Run time monitor (memory)
• Session dumps (XML file)
• Heap dump of the JVM running in the HTTP task
– Or from the Domino console (or from your code)
• tell http xsp heapdump (triggers com.ibm.jvm.Dump.HeapDump())
• tell http xsp javadump (triggers com.ibm.jvm.Dump.JavaDump())
– Analyze the heap dump using the Eclipse memory analyzer (need to also
install the IBM dump tool)
http://www.eclipse.org/mat/
http://www.ibm.com/developerworks/java/jdk/tools/dtfj.html
• Thread Monitoring
27
30. • Simple Repeat – what could be wrong?
– Configuration Lookups to get other nsf names
– Lookups to get “role” of user
– Opening Notes document to get values
– Computed view value
– Complicated rendered formula in repeat
Case Study 1 - Repeat
30
31. • Add Application Scope variables to store database
names
• Or (better yet) create an ApplicationBean in Java
Case Study 1 – First Step add scoped variable for Config (db names)
31
To retrieve:
32. Improvement – Repeat_Config
32
Xpage Calls Time CPU Time Calls(%)
BE
Time(%)
CPU
Time(%)
Start 3564 1547 1688
Cache Config 2499 733 1016 143% 211% 166%
33. • Add App Scope variable to store user roles
• No more @DbLookup in rendered
– Pulls value from memory - much faster!
Case Study 1 – Next add scoped variable for User Information
33
To retrieve:
34. Improvement – Repeat_User
34
All previous changes are cumulative....
Xpage Calls Time CPU Time Calls(%)
BE
Time(%)
CPU
Time(%)
Start 3564 1547 1688
Cache Config 2499 733 1016 143% 211% 166%
Cache User 1992 265 469 179% 584% 360%
35. • Avoid opening NotesDocument object to get values
not in the view
– Created a new view with missing columns
– Changed reference to use EL for all but two
columns that need to lookup in another DB
Case Study 1 – Next create a new view
35
36. Improvement – Repeat_BetterView
36
All previous changes are cumulative....
Xpage Calls Time CPU Time Calls(%)
BE
Time(%)
CPU
Time(%)
Start 3564 1547 1688
Cache Config 2499 733 1016 143% 211% 166%
Cache User 1992 265 469 179% 584% 360%
Better View 1656 283 375 215% 547% 450%
37. • Avoid doing the @Dblookup to get the sales person
based on the region
• Use a Bean to cache Region/Salesperson data
– HashMap: key is region name, value is salesperson
– Application scope (shared by all users)
Lookup the Sales Person from a Bean
37
38. Improvement – Repeat_CacheRegion
38
All previous changes are cumulative....
Xpage Calls Time CPU Time Calls(%)
BE
Time(%)
CPU
Time(%)
Start 3564 1547 1688
Cache Config 2499 733 1016 143% 211% 166%
Cache User 1992 265 469 179% 584% 360%
Better View 1656 283 375 215% 547% 450%
Cache Region 1614 93 250 221% 1663% 675%
39. • Store Sales Total by Customer in HashMap
– viewScope Managed Bean
• Caches sales total, key is customer name
• Also use ViewNavigator to get totals via
getNextCategory()
– Fast initialization of HashMap
Next Try: Use Java to Cache Sales Lookup
39
SSJS call to Bean
40. Improvement – Repeat_ComputeSalesJava
40
All previous changes are cumulative....
Xpage Calls Time CPU Time Calls(%)
BE
Time(%)
CPU
Time(%)
Start 3564 1547 1688
Cache Config 2499 733 1016 143% 211% 166%
Cache User 1992 265 469 179% 584% 360%
Better View 1656 283 375 215% 547% 450%
Cache Region 1614 93 250 221% 1663% 675%
Compute Sales - Java 816 16 172 437% 9669% 981%
41. • CustomerBean
– passes Collection of customer objects to Repeat
– The scope could be request, view, or application
• CacheBean
– Long lived information
– Config settings (database path and name)
– User profile (manager, sales rep or user)
– Region information (get Sales person for region)
– Application Scope
Do Everything in Java!
41
43. Improvement – Repeat_AllJava
43
Xpage Calls Time CPU Time Calls(%)
BE
Time(%)
CPU
Time(%)
Start 3564 1547 1688
Cache Config 2499 733 1016 143% 211% 166%
Cache User 1992 265 469 179% 584% 360%
Better View 1656 283 375 215% 547% 450%
Cache Region 1614 93 250 221% 1663% 675%
Compute Sales - Java 816 16 172 437% 9669% 981%
All Java (request scope) 401 47 141 889% 3291% 1197%
All Java (view scope) 6 0 109 59400% NA 1549%
44. Performance Improvement for Case Study 1
44
0
500
1000
1500
2000
2500
3000
3500
4000
AxisTitle
Calls Time CPU Time
45. Case Study 2: Partial Refresh and Execution
• Added a lookup to compute sales by region
– Full Update/Exec
– Partial Refresh
– Partial Exec
– Both
45
Xpage Calls Time CPU Time Calls (%)
BE
Time (%)
CPU
Time(%)
Start 1918 1109 1375
Refresh 516 672 781 691% 230% 216%
Exec 1414 610 688 252% 254% 245%
Both 12 31 78 29700% 4990% 2164%
0
500
1000
1500
2000
2500
Start Refresh Exec Both
Calls Time CPU Time
46. Case Study 3: Data Contexts
• Compare Data Context (on page load vs. dynamic)
– Two data context variables
46
Xpage Calls Time Wall Time Calls (%)
BE
Time (%) CPU Time(%)
Dynamic 24 47 467
On Page Load 2 16 99 1200% 293% 472%
47. Recap
• Think about performance when designing
– JSF Lifecycle
• Avoiding computations in rendered
– Cache whenever possible
• Scoped variables
• Beans
• Measure performance
– Part of your testing processes
– Look for ways to improve
47
48. • TLCC Performance Webinar with Ulrich Krause and
myself from October, 2013
– YouTube and Slides
• Paul Withers blog (each link below is different)
– Part 1, Part 2, Part 3
• Tony McGuckin’s Video - XPages Master class
– 4 videos plus sample applications
• IBM article on JSF (non XPages)
• My Performance Webinar from October, 2015
– YouTube and Slides
48
Homework Time – Further References
49. 49
Email: howardg@tlcc.com
Twitter: @TLCCLtd
Web: www.tlcc.com
Download the Sample Application and presentation at:
http://www.tlcc.com/connect
Please do the online survey for this session!
THANK YOU IN ADVANCE!
50. Other Server Settings
50
The next slides contain other server
settings you may want to review with
your admin...
51. Server Performance Variables
• Hardware
– CPU, Network, Memory, and Hard Drive
• Operating System (Use 64 bit OS!)
• Domino:
– Memory Settings
• HTTPJVMMaxHeapSize
• Use HTTPJVMMaxHeapSizeSet=1 to prevent
changes
– Number of threads
• See this article from IBM
– Encryption (HTTPS)
51
52. Optimizing Memory Utilization
• xsp.persistence.mode - Set in XSP Properties file
– Defines the persistence mode for the JSF pages
• file: All the pages are persisted on disk
• fileex: All the pages are persisted on disk except the current one,
which stays in memory
• <else>: All the pages stay in memory (tree mode)
52
53. JavaScript/CSS Aggregation
• Groups many DOJO, CSS / JS files into a single file
– Less requests from the browser to the server
– Performance improvements on networks with high
latency
– Enhanced performance parsing CSS / JS
– Fewer connections to the server
53
On the Server: xsp.properties:
xsp.resources.aggregate=true
54. Acknowledgements and Disclaimers
Availability. References in this presentation to IBM products, programs, or services do not imply that they will be available in all countries in which IBM
operates.
The workshops, sessions and materials have been prepared by IBM or the session speakers and reflect their own views. They are provided for informational
purposes only, and are neither intended to, nor shall have the effect of being, legal or other guidance or advice to any participant. While efforts were made to
verify the completeness and accuracy of the information contained in this presentation, it is provided AS-IS without warranty of any kind, express or implied. IBM
shall not be responsible for any damages arising out of the use of, or otherwise related to, this presentation or any other materials. Nothing contained in this
presentation is intended to, nor shall have the effect of, creating any warranties or representations from IBM or its suppliers or licensors, or altering the terms
and conditions of the applicable license agreement governing the use of IBM software.
All customer examples described are presented as illustrations of how those customers have used IBM products and the results they may have achieved.
Actual environmental costs and performance characteristics may vary by customer. Nothing contained in these materials is intended to, nor shall have the effect
of, stating or implying that any activities undertaken by you will result in any specific sales, revenue growth or other results.