+ All Categories
Home > Technology > Life In The FastLane: Full Speed XPages

Life In The FastLane: Full Speed XPages

Date post: 16-Nov-2014
Category:
Upload: ulrich-krause
View: 4,684 times
Download: 9 times
Share this document with a friend
Description:
Using XPages out of the box lets you build good looking and well performing applications. However, as XPage applications become bigger and more complex, performance can become an issue and, if it comes to scalability and speed optimization, there are a couple of things to take into consideration. Learn how to use partial refresh and partial execution mode and how to monitor its execution using a JSF LifeCycle monitor to avoid multiple re-calculation of controls. We will show tools that can allow you to profile your code, readily available from OpenNTF, along with a demonstration of how to use them to improve the speed of your code. Still writing SSJS and encounter a significant slow down when using Script Libraries? See, how you can improve the speed of your application using JAVA instead of JS, JSON and even @formulas.
Popular Tags:
65
Life In The Fast Lane Full Speed XPages March , 21. – 22. 2013 Faculty Club, Leuven, Belgium Ulrich Krause, BCC Unternehmensberatung GmbH Matthew Fyleman, We4IT
Transcript
Page 1: Life In The FastLane: Full Speed XPages

Life In The Fast Lane Full Speed XPages

March , 21. – 22. 2013Faculty Club, Leuven, Belgium

Ulrich Krause, BCC Unternehmensberatung GmbHMatthew Fyleman, We4IT

Page 2: Life In The FastLane: Full Speed XPages

Lotus Notes/Domino Developer since 1993 Senior Developer at We4IT GmbH

Recently focused entirely on XPages development

Working on We4IT's XPages framework Also on Offline capabilities for We4IT’s mobile

framework

About: Matthew FylemanAbout: Matthew Fyleman

Page 3: Life In The FastLane: Full Speed XPages

Lotus Notes/Domino Developer since 1993 Senior Software Architect at BCC

OpenNTF Contributor OpenNTF Board of Directors IBM Champion 2011/2012/2013 Blog http://www.eknori.de Notes Forum (http://www.atnotes.de)

About: Ulrich KrauseAbout: Ulrich Krause

Page 4: Life In The FastLane: Full Speed XPages

Performance, what factors affect it? Java vs. JavaScript Looping through Documents, ViewNavigator vs.

GetNextDocument Stringbuilder vs. Concat (+) JSF Lifecycle Listener Partial Update / Partial Execute Variable Resolver Tools

AgendaAgenda

Page 5: Life In The FastLane: Full Speed XPages

XPages Request XPages Request

Page 6: Life In The FastLane: Full Speed XPages

The hardware used has a significant influence on performance. There are 3 key elements:• CPU • Main Memory• Hard Disk

HardwareHardware

Page 7: Life In The FastLane: Full Speed XPages

CPU • Cores / Clock / Cache• Poor response time

Main Memory• Limit defined by the operating system• Scalability

Weak CPU AND Low Memory• Poor overall performance• Poor response times• Server "hangs"

HardwareHardware

Page 8: Life In The FastLane: Full Speed XPages

Latency• Time taken for data transmission between multiple computers on a

network Bandwidth

• Rate of transmission of data

Greater Bandwidth

+ Lower Latency --------------------------------= Better Connection

NetworkNetwork

Page 9: Life In The FastLane: Full Speed XPages

Hardware How many data requests / responses are transmitted How much data is transferred (size) Caching of resources How much CSJS runs Size / complexity of the CSS Complexity of the site structure

Client & BrowserClient & Browser

Page 10: Life In The FastLane: Full Speed XPages

Browser / HTTP server• Network latency – distance/time to server. Bandwidth – size of files.• Browser limits on concurrent downloads; <= IE7 allows 2 downloads, IE8

allows 6 HTTP Server / App Server

• HTTP Server JVM memory allocation (heap size) & garbage collector• CPU time, competition between threads, gives slower response times• Threads, limited to 40 by default, configurable in Domino Administrator

App Server / Domino context• Read design elements from the NSF (XPage .class files, form structure, etc)• Backend API calls may be expensive, especially for large data sets.• Design elements may be network requests.

Limiting factors on performanceLimiting factors on performance

Page 11: Life In The FastLane: Full Speed XPages

Servlet / Lifecycle• Restore control tree – file system read. Control tree locking – no concurrent

access.• Rendered re-evaluated for every control for most phases

Browser/Client JavaScript/Dojo• Inline JavaScript blocks insertion of later HTML elements into the DOM tree• Dojo does AJAX requests for .js files for dojo modules that are not loaded

Limiting factors on performanceLimiting factors on performance

Page 12: Life In The FastLane: Full Speed XPages

notes.ini• HTTPJVMMaxHeapSizeSet=1• HTTPJVMMaxHeapSize=256M

• Should be set to ¼ of the available RAM

Domino Administrator• HTTP server "Enable logging to" disabled• HTTP server thread count – defaults to 40

Remember, enabling the debugger affects performance• JavaEnableDebug=1• JavaDebugOptions=transport=dt_socket,server=y,suspend=n,address=8000• JavascriptEnableDebug=1 ( Version 9 )

General Performance OptionsGeneral Performance Options

Page 13: Life In The FastLane: Full Speed XPages

xsp.persistence.mode= 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)

Reducing Memory UtilizationReducing Memory Utilization

Page 14: Life In The FastLane: Full Speed XPages

Simple actions vs links or button with window.location JS Reduce server phase processing

• Use partial update where possible• Use partial execute where possible• Use disableValidators & immediate event

Minimize work in rendered / visible computations• Use variable resolver

Repeats & Views• Use viewEntry.getColumnValue instead of viewEntry.getDocument.getColumn• Use Domino View data source dataCache property where possible

XPages Design OptimizationsXPages Design Optimizations

Page 15: Life In The FastLane: Full Speed XPages

Load-time vs Runtime• Using loaded vs rendered• ExtLib Dynamic Content

– allows partial re-loading so more use of load-time optimizations

Loading resources in the browser• CSS & browser JS

– extract to separate files. Minify & compress files

• Images– use correct size & format. Use CSS Image Sprites as possible

XPages Design OptimizationsXPages Design Optimizations

Page 16: Life In The FastLane: Full Speed XPages

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

JavaScript/CSS AggregationJavaScript/CSS Aggregation

On the Server: xsp.properties:xsp.resources.aggregate=true

Page 17: Life In The FastLane: Full Speed XPages

JavaScript/CSS AggregationJavaScript/CSS Aggregation

Page 18: Life In The FastLane: Full Speed XPages

XPagesPreload=1 New Feature in Notes / Domino 8.5.3 Server and Client

Java classes from the XPages runtime plug-ins • loaded from a fixed list of runtime classes ( 435 in ND 8.5.3 )• com.ibm.xsp.core, common utility, JS wrapper, FSF runtime classes

Java classes referenced in *-faces.config.xml• XPages control renderer, data sources, complex types

XPages Pre-LoadXPages Pre-Load

Page 19: Life In The FastLane: Full Speed XPages

• XPagesPreloadDB=Server!!Db.nsf/XPage.xsp, myLocalDb.nsf• Works at the application level

• The application is loaded on the client / server startup into memory. This happens even when the application is first opened in the browser

• For each entry in the notes.ini variable, an XPage URL is generated and sent to the server

• The application is loaded, and the HTML generated• The XPages runtime discards the HTML, but retains the application in

memory

XPages Pre-LoadXPages Pre-Load

Page 20: Life In The FastLane: Full Speed XPages

applicationScope• Are visible for all users of one application. Expires some time after the last user

used an applicationScope variable. That means applicationScope variables are NOT persistent forever.

sessionScope• Is valid through the session of the current user. A user session expires after

some time of inactivity. Uses don't have access to the sessionScope variables of other users.

viewScope• Is visible for views on the current page only. Useful for transporting a search

query to a view.

requestScope• Is valid through one request of the current user. That includes refreshing of a

page.

Scoped VariablesScoped Variables

Page 21: Life In The FastLane: Full Speed XPages

Caching with Application ScopeCaching with Application Scope

Page 22: Life In The FastLane: Full Speed XPages

JSF LifecycleJSF Lifecycle

Page 23: Life In The FastLane: Full Speed XPages

XPages Lifecycle ListenerXPages Lifecycle Listener

What happens in each phase of the JSF lifecycle?

Ulrich Krause: http://openntf.org/XSnippets.nsf/snippet.xsp?id=a-simple-lifecyclelistener-

Page 24: Life In The FastLane: Full Speed XPages

XPages MasterclassXPages Masterclass

http://www.openntf.org/internal/home.nsf/project.xsp?action=openDocument&name=XPages%20Masterclass

Page 25: Life In The FastLane: Full Speed XPages

# • Executed every time the page is rendered• Use for values that are likely to change

$• Executed when the page is first loaded• Use for values that don't change

When to Execute - # vs $When to Execute - # vs $

Page 26: Life In The FastLane: Full Speed XPages

dataContexts can be thought of as global variables dataContext's value can be computed dynamically or on page load

• So you can use ${javascript:@Today()} and run it once rather than running a function each time.

dataContexts can be scoped to any level that datasources can• XPage, Custom Control or Panel• you can set a dataContext in a panel in a repeat control, to avoid multiple

references to a NotesDocument's item dataContexts are referenced using EL

• So at no point in the references do you run SSJS, so it's not having to go through the SSJS parser

DataContextDataContext

Page 27: Life In The FastLane: Full Speed XPages

Issue with data context variables if they are bound dynamically.• They will be recomputed again and again, even when in Partial Execution

mode and if they are not in use (http://hasselba.ch/blog/?p=1112)

DataContext - PitfallDataContext - Pitfall

Page 28: Life In The FastLane: Full Speed XPages

DataContext - PitfallDataContext - Pitfall

Page 29: Life In The FastLane: Full Speed XPages

Reduced control processing in the render response phase• Means less work on the server

– render response is the most intensive phase

Smaller response from server.• means reduced network usage

Better browser experience• rest of the page is still visible while waiting for a response• inserting small sections into the page is much faster than reloading a full page.

Partial Refresh / Update (Pro)Partial Refresh / Update (Pro)

Page 30: Life In The FastLane: Full Speed XPages

Dependancy outside of the partial update area• Other areas of the control tree are not processed,so any SSJS scripts in those

other controls will not be run.• Enabling Partial Update where it was previously full update may lead to

functional problems

Only one area may be partial updated by default• In CSJS you can schedule later partial updates of related areas, but any

concurrent requests will wait for exclusive access to the server-side control tree before processing on the server

Partial Refresh / Update (Cons)Partial Refresh / Update (Cons)

http://www.timtripcony.com/blog.nsf/d6plinks/TTRY-84B6VP

Page 31: Life In The FastLane: Full Speed XPages

Reduced control processing in the 3 data-processing phases• Means less work on the server, faster response times

Dependancy on Edit Box values outside of the exec area• Submitted values from Edit Boxes and/or other input controls in other areas of

the control tree are not processed, so any control values and document fields in those other areas will not be updated. Enabling Partial Exec where it was previously full execution may lead to functional problems where values are out-of date in the onclick script or in the redisplayed page.

onclick Event Handler must be in the exec area• The applyRequestValues phase prepares for the invokeApplication phase.The

onclick simple action or SSJS script won't occur if outside the partial exec area

Partial ExecutionPartial Execution

Page 32: Life In The FastLane: Full Speed XPages

execMode only added in 8.5.1 (not in 8.5.0) execId slightly difficult to select in Designer

• Select your button, in the Outline view, toggle open the button, select the child Event Handler control, then set the execId property on the Event Handler.

• [Better UI proposed in Notes/Domino Next – in the Events tab]

Partial ExecutionPartial Execution

Page 33: Life In The FastLane: Full Speed XPages

disableValidators• JSF life cycle through all phases (1-6)• But requests will not validate the data• Converters continue to work.• Items in documents will be updated• Sven Hasselbach - "Disable all validators at once" (

http://hasselba.ch/blog/?p=1106)• Immediate

• JSF Lifecycle processes only phases (1, 2, 6)• No data processing• Items in documents are not updated• Onclick event handler scripts and render response calculations are

performed

disableValidators / immediatedisableValidators / immediate

Page 34: Life In The FastLane: Full Speed XPages

Most properties, like CSS “style” are only computed in the renderResponse

Edit Box and input “value” properties are used in Data Processing phases & renderResponse

Data Source properties are computed during renderResponse & results are cached for the next request's Data Processing & invokeApplication phases

Minimize work in rendered / visible computationMinimize work in rendered / visible computation

Page 35: Life In The FastLane: Full Speed XPages

The rendered property is computed in all 5 lifecycle phases Avoid re-computing values in every rendered property

• @DbLookup, @DbColumn, getDocumentByKey• In the rendered property, save the computed boolean to a viewScope

variable

Minimize work in rendered / visible computationMinimize work in rendered / visible computation

Page 36: Life In The FastLane: Full Speed XPages

Loaded• is only computed once in the createView phase

• not re-computed in the 5 usual phases

• false means the control is not created. So it can never be rendered.• true means the control is added to the control tree.

• You can still compute rendered when loaded evaluates to true.

Compute the loaded property on conditions• where you could compute the rendered property and save it to the view

scope• it would never need to be recomputed for the rest of the interaction with

this page

Using loaded vs renderedUsing loaded vs rendered

Page 37: Life In The FastLane: Full Speed XPages

Use correct file type depending on content• JPEG for complexed detailed images

• PNG/GIF for simple images, fonts, transparencies• Use the HTML <img> tag “width” and “height” attributes

• For faster HTML layout in the browser• Size the image to size you intend to use• Resizing using html attributes height and width will delay the rendering of your

page• Images larger than necessary will waste bandwidth

ImagesImages

Page 38: Life In The FastLane: Full Speed XPages

Use CSS Image Sprites• If you have multiple small images, make a single larger image containing

the smaller images• And use CSS to display just the relevant subset image at a location in the

page• For semantically significant sprites, provide an accessibility “title” attribut

(as sprites don't use the IMG “alt” attribute, but you still want to assist blind users)

• There's no specific XPages support for sprites, but they're used in the XPages OneIU themes

CSS Image SpritesCSS Image Sprites

Page 39: Life In The FastLane: Full Speed XPages

CSS Image Sprite SampleCSS Image Sprite Sample

http://www.w3schools.com/css/tryit.asp?filename=trycss_sprites_img

Page 40: Life In The FastLane: Full Speed XPages

XPages based Application• Runs on the Domino server or the Notes client• An NSF needs to be installed on the Domino server/Notes client• A profiler jar file should be added to the JVM launch options

Measures the CPU performance and the memory allocation Available from OpenNTF.org

• Free open source project• Search for “XPages Toolbox”

Extended in 8.5.2 to support Backend classes profiling

XPages ToolboxXPages Toolbox

http://www.openntf.org/internal/home.nsf/project.xsp?action=openDocument&name=XPages%20Toolbox

Page 41: Life In The FastLane: Full Speed XPages

XPages ToolboxXPages Toolbox

Page 42: Life In The FastLane: Full Speed XPages

Generate a heap dump of the JVM running in the HTTP task• A button in the XPages profiler generates the heap dump• From the Domino console

• 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• http://www.eclipse.org/mat/• http://www.ibm.com/developerworks/java/jdk/tools/dtfj.html

XPages ToolboxXPages Toolbox

Page 43: Life In The FastLane: Full Speed XPages

Heapdump / Javadump AnalyzerHeapdump / Javadump Analyzer

Page 44: Life In The FastLane: Full Speed XPages

Print statements• In rendered/visible computations to see how often executed

– print("panel2 evaluating rendered property");• In the XPages root control events:

– before/afterPageLoad, afterRestoreView, before/afterRenderResponse.• Custom control root events:

– before/afterPageLoad.• In the document data source events:

– queryNewDocument, postSaveDocument, etc.

Task Manager and/or Process Explorer• Shows CPU usage & process memory usage as it happens• Heap memory usage will be a subset of process memory, but heap dumps are

only a snapshot

More ToolsMore Tools

Page 45: Life In The FastLane: Full Speed XPages

Browser developer tools • for watching network transactions, partial updates, response times• BROWSER: Firebug, Developer Tools• XPiNC: FirebugLite from ExtLib

Java / Javascript Debugging• Degrades performance but can inspect objects, step into code. • Use the Eclipse Java debugger.• In Domino\notes.ini add these 2 options:

• JavaEnableDebug=1• JavaDebugOptions=transport=dt_socket,server=y,suspend=n,address=8000

More ToolsMore Tools

Page 46: Life In The FastLane: Full Speed XPages

Demo - Step-By-Step OptimizationDemo - Step-By-Step Optimization

Page 47: Life In The FastLane: Full Speed XPages

Get all „Contacts“ into a NotesDocumentCollection, loop the collection and build the JSON by reading the values from items in the document

XAgent – SSJS XAgent – SSJS

Page 48: Life In The FastLane: Full Speed XPages

XAgent – SSJS XAgent – SSJS

Page 49: Life In The FastLane: Full Speed XPages

Get all „Contacts“ into a NotesDocumentCollection, loop the collection and build the JSON by reading the values from items in the document. Also UNID is stored in document

XAgent – SSJS – UNID from ItemXAgent – SSJS – UNID from Item

Page 50: Life In The FastLane: Full Speed XPages

XAgent – SSJS – UNID from ItemXAgent – SSJS – UNID from Item

Page 51: Life In The FastLane: Full Speed XPages

Get all „Contacts“ into a NotesDocumentCollection, loop the collection and get the JSON from an item on the document. The JSON is calculated on document save

XAgent – SSJS - SingleItemXAgent – SSJS - SingleItem

Page 52: Life In The FastLane: Full Speed XPages

XAgent – SSJS - SingleItemXAgent – SSJS - SingleItem

Page 53: Life In The FastLane: Full Speed XPages

loop thru a view and get the JSON from a view column.

XAgent – SSJS – ViewNavigatorXAgent – SSJS – ViewNavigator

Page 54: Life In The FastLane: Full Speed XPages

XAgent – SSJS – ViewNavigatorXAgent – SSJS – ViewNavigator

Page 55: Life In The FastLane: Full Speed XPages

Concatenation of Strings is very easy in Java - all you need is a '+‘ Each time you append something via '+' (String.concat()) a new

String is created, the old stuff is copied, the new stuff is appended, and the old String is thrown away. The bigger the String gets the longer it takes - there is more to copy and more garbage is produced.

Accordingly to Arno Unkrig the optimal strategy is to use String.concat() for 2 or 3 operands, and StringBuilder for 4 or more operands

StringBuilder vs String.concatStringBuilder vs String.concat

String text= "line 1\n"+ "line 2\n"+ "line 3";

System.out.println("x:"+x+" y:"+y);

Page 56: Life In The FastLane: Full Speed XPages

When to use StringBuilder over '+' (String.concat()) ?• use StringBuilder whenever you assemble a String in a loop• Just keep in mind that '+' isn't always a good idea

StringBuilder vs String.concatStringBuilder vs String.concat

http://kaioa.com/node/59

Page 57: Life In The FastLane: Full Speed XPages

loop thru a view and get the JSON from a view column. Use a StringBuilder to concat the JSON

XAgent – SSJS – ViewNavigator + StringBuilderXAgent – SSJS – ViewNavigator + StringBuilder

Page 58: Life In The FastLane: Full Speed XPages

XAgent – SSJS – ViewNavigator + StringBuilderXAgent – SSJS – ViewNavigator + StringBuilder

Page 59: Life In The FastLane: Full Speed XPages

loop thru a view and get the JSON from a view column. Use a StringBuilder to concat the JSON + use Java instead of SSJS

XAgent – JavaXAgent – Java

Page 60: Life In The FastLane: Full Speed XPages

XAgent – JavaXAgent – Java

Page 61: Life In The FastLane: Full Speed XPages

Single Document Containing References to all your CSS Resources• resource sections reference the CSS files used • control section define what CSS classes are applied to specific controls

XML Based and Easy To Learn• creating a new theme document prefills sample content

Can Extend Other Themes• <theme extends="webstandard">• will automatically include all the resource and control definitions from that

theme built-in themes • webstandard, notes, oneUI

ThemesThemes

Page 62: Life In The FastLane: Full Speed XPages

Create your own themes from scratch. Creating a theme that extends from the webstandard or another

supplied theme will include extra stylesheets and styles that you might not need.

Be prepared to spend more time writing css though

ThemesThemes

Page 63: Life In The FastLane: Full Speed XPages

Global Application / Configuration properties

Load Resources from ThemeLoad Resources from Theme

Page 64: Life In The FastLane: Full Speed XPages
Page 65: Life In The FastLane: Full Speed XPages

Recommended