68
Full Speed XPages Performanceoptimierung 11. – 13..03.2013 Maritim Hotel, Gelsenkirchen Ulrich Krause, BCC Unternehmensberatung GmbH Entwicklercamp 2013

XPages Performance

Embed Size (px)

DESCRIPTION

Slides from session at EntwicklerCamp 2013 ( 13-MAR-2013 )

Citation preview

Page 1: XPages Performance

Full Speed XPages Performanceoptimierung

11. – 13..03.2013 Maritim Hotel, Gelsenkirchen

Ulrich Krause, BCC Unternehmensberatung GmbH

Entwicklercamp 2013 Entwicklercamp 2013

Page 2: XPages Performance

Lotus Notes / Domino Administrator & Entwickler seit 1993 Senior Software Architect

OpenNTF Contributor OpenNTF Board of Directors

IBM Champion 2011/2012/2013 Blog http://www.eknori.de Notes Forum (http://www.atnotes.de)

Über: Ulrich Krause

Page 3: XPages Performance

Performance, was kann bremsen ? Java vs. JavaScript Daten vorbereiten, ViewNavigator vs. GetNextDocument Stringbuilder vs. Concat (+) JSF Lifecycle Listener Partial Update / Partial Execute Variable Resolver Werkzeuge

Agenda

Page 4: XPages Performance

XPages Request

Page 5: XPages Performance

Die verwendete Hardware hat einen nicht unerheblichen Einfluß auf die Performance. Es gibt 3 Kernelemente• CPU • Arbeitsspeicher• Festplatten

Hardware

Page 6: XPages Performance

CPU • Anzahl Kerne / Taktrate / Cache • Schlechte Antwortzeiten

Arbeitsspeicher• Obergrenze durch das Betriebssystem vorgegeben• Skalierbarkeit

Schwache CPU und zu kleiner Arbeitsspeicher führen zu• Schlechter Gesamtperformance• Schlechten Antwortzeiten• Server “hängt”

Hardware

Page 7: XPages Performance

Bandbreite• Geschwindigkeit, mit der Daten übertragen werden

Latenz• Beanspruchte Zeit einer Datenübertragung zwischen mehreren Computer

an einem Netzwerk Je größer die Bandbreite und je kleiner die Latenz desto "besser"

ist die Verbindung

Netzwerk

Page 8: XPages Performance

Hardware Wie viele Daten requests / responses werden übertragen Wie viele Daten werden übertragen ( Größe ) Wie werden Resourcen gecached Wie viel CSJS wird ausgeführt Größe / Komplexität des CSS Komplexität des Seitenaufbau

Client & Browser

Page 9: XPages Performance

Berechnungen während der JSF Lifecycle Phasen reduzieren• Wenn möglich, partial update verwenden• Wenn möglich, partial execute verwenden• Wenn möglich, disableValidators & immediate verwenden

Berechnungen für „Sichtbar“ reduzieren• „Loaded“ Eigenschaft verwenden um „Rendered“ zu berechnen• Ergebnis der Berechnung zwischenspeichern ( scopedVariable)• VariableResolver verwenden

Repeats & Views• viewEntry.getColumnValue antelle von viewEntry.getDocument.getColumn• View data source dataCache property

XPages Design Optimizations

Page 10: XPages Performance

Browser / HTTP Server• Netzwerk: Latenz, Bandbreite, Dateigröße• Browser: Anzahl gleichzeitiger Downloads (IE7 = 2 , IE8 = 6 )

HTTP Server / App Server• HTTP Server JVM Memory Allocation (heap size) & Garbage Collector• CPU Time• Anzahl Threads, DEFAULT: 40 , konfigurierbar in Domino Administrator

App Server / Domino context• Lesen von Designelementen (Xpage, .class files, jar files, etc)• Je mehr Design Elemente, desto mehr Netzwerkanfragen• Anzahl Backend API Calls, insbesondere bei großen Datenmengen

Performancebeeinträchtigungen

Page 11: XPages Performance

Servlet / JSF Lifecycle• Persitence mode Zugriffe auf das Dateisystem • Serialisierung von Anfragen ( multiple partial update )• Neuberechnung von Werten in allen Phasen des JSF Lifecycle

Browser/ Client JavaScript/ Dojo• Inline JavaScript verhindert die Ausführung von weiteren HTML• AJAX requests an Dojo Module, die nicht geladen sind

Performancebeeinträchtigungen

Page 12: XPages Performance

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

• sollte auf ¼ des verfügbaren RAM gesetzt werden

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

Generell hat das Debug Einfluß auf die Performance• JavaEnableDebug=1• JavaDebugOptions=transport=dt_socket,server=y,suspend=n,address=8000• JavascriptEnableDebug=1 ( ab Version 9 )

General Performance options

Page 13: XPages Performance

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 Utilization

Page 14: XPages Performance

Loadtime vs Runtime• Loaded vs Rendered• ExtLib Dynamic Content

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

CSS & browser JS • Kein inline CSS / JS • Auslagern in entsprechende Designelemente• Dateien so klein wie möglich halten

Bilder• Größe nicht zur Laufzeit berechnen• CSS Image Sprites verwenden, wenn möglich

XPages Design Optimizations

Page 15: XPages Performance

Faßt mehrere DOJO Module, CSS / JS files in einer einzigen Datei zusammen• Weniger Anfragen vom Browser an den Server• Wirkt sich in Netzwerken mit hoher Latenz Performance steigernd aus• Performanteres Parsen von CSS / JS• Weniger Verbindungen zum Server

JavaScript/CSS Aggregation

Auf dem Server: xsp.properties:xsp.resources.aggregate=true

Page 16: XPages Performance

JavaScript/CSS Aggregation

Page 17: XPages Performance

XPagesPreload=1 Neues Feature in Notes / Domino 8.5.3 Server und 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-Load

Page 18: XPages Performance

• XPagesPreloadDB=Server!!Db.nsf/XPage.xsp, myLocalDb.nsf• Arbeitet auf Applikationsebene

• Die Anwendung wird beim Client/Serverstart in den Speicher geladen. Dies passiert auch, wenn die Anwendung erstmalig im Browser geöffnet wird

• Für jeden Eintrag in der notes.ini Variable wird eine XPage URL generiert und an den Server geschickt

• Die Anwendung wird geladen und das HTML generiert• Die XPages Runtime verwirft das HTML, behält aber die Anwendung im

Speicher

XPages Pre-Load

Page 19: XPages Performance

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 Variables

Page 20: XPages Performance

Caching und Application Scope

Page 21: XPages Performance

A Java design element is created just like you create any other design element.

Categorization in the Designer views is shown by using the "/" character to demark levels

In the virtual file system, the class file appears separate from the .java file, under WebContent\WEB-INF\classes

JAVA Design Element (8.5.3)

Page 22: XPages Performance

Work with packaged Java code/libraries that are included in the application NSF

Frees you from having to deploy the JARS to a server and/or include the source files uniquely in the application database

Automatically manages the classpath and places the JAR file into web-inf/lib

Only available to XPages applications• automatically loaded by the

XPages runtime

JAR Design Element ( V9 )

Page 23: XPages Performance

# • Wird jedes Mal ausgeführt, wenn die Seite gerendert wird• Wenn Werte sich ändern. (Computed values / Abhängigkeiten )

$• Wird nur beim ersten Seitenaufbau ausgeführt.• Wenn sich Werte nicht ändern ( Label )

When to Execute - # vs $

Page 24: XPages Performance

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

DataContext

Page 25: XPages Performance

Problem beim data context und dynamischen binding• 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 - Pitfall

Page 26: XPages Performance

DataContext - Pitfall

Page 27: XPages Performance
Page 28: XPages Performance

JSF Lifecycle

Page 29: XPages Performance

XPages Masterclass

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

Page 30: XPages Performance

XPages Lifecycle Listener

Was passiert in den einzelnen Phasen des JSF Lifecycle

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

Page 31: XPages Performance

Reduzierung der Berechnungen im renderResponse• Weniger Rechenaufwand auf dem Server

Kleinere Datenmengen, die vom Server übertragen werden• Reduzierung der Datenmenge im Netzwerk

Bessere User / Browser experience• Während der Aktualisierung bleibt die Seite weiterhin sichtbar• Das Aktualisieren von nur kleinen Bereichen einer Webseite ist schneller

als der vollständige Neuaufbau

Partial Refresh / Update (Pro)

Page 32: XPages Performance

Abhängigkeiten ausserhalb der refreshID• Bereiche, die eine Abhängigkeit zu dem neu berechneten Bereich haben,

werden nicht aktualisiert• Vorsicht, wenn das partial Update für Bereiche aktiviert wird, die bisher

vollständig aktualisiert wurden Es kann nur eine refreshID angegeben werden

• Diesem Restriktion kann mit CSJS umgangen werden, allerdings werden die einzelnen Aktualisierungen seriell abgearbeitet

Partial Refresh / Update (Contra)

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

Page 33: XPages Performance

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 Execution

Page 34: XPages Performance

execMode erst ab 8.5.1 Setzen der execId in V8.5.1 und V9

Partial Execution

Page 35: XPages Performance

disableValidators• JSF Lifecycle durchläuft alle Phasen (1-6)• es findet aber keine Validierung der Daten statt• Converters funktionieren weiterhin.• Items in Dokumenten werden aktualisiert

• Sven Hasselbach – “Disable all validators at once” (http://hasselba.ch/blog/?p=1106)

Immediate• JSF Lifecycle durchläuft nur Phasen (1, 2, 6)• Keine Datenverarbeitung • Items in Dokumenten werden nicht aktualisiert• Event Handler onclick scripts und renderResponse Berechnungen werden

ausgeführt

disableValidators / immediate

Page 36: XPages Performance

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 computation

Page 37: XPages Performance

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 computation

Page 38: XPages Performance

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 rendered

Page 39: XPages Performance

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

Images

Page 40: XPages Performance

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 llocation 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 Sprites

Page 41: XPages Performance

CSS Image Sprite Sample

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

Page 42: XPages Performance

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 Toolbox

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

Page 43: XPages Performance

XPages Toolbox

Page 44: XPages Performance

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

HTTPJVMMaxHeapSizeSet=1 HTTPJVMMaxHeapSize=256M

XPages Toolbox

Page 45: XPages Performance

Heapdump / Javadump Analyzer

Page 46: XPages Performance

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 Tools

Page 47: XPages Performance

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 Tools

Page 48: XPages Performance

Demo

Page 49: XPages Performance

JSON Daten{"@unid":"00065A23B16A0E5EC1257AEB00315D53","FirstName":"Concetta","LastName":"Galloway","State":"AZ","City":"Mesa"},{"@unid":"000C0B447A8D3FEBC1257AEB00314648","FirstName":"Annmarie","LastName":"Crosby","State":"TX","City":"El Paso"}, ...

Page 50: XPages Performance

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

XAgent – SSJS

Page 51: XPages Performance

XAgent – SSJS

Page 52: XPages Performance

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 Item

Page 53: XPages Performance

XAgent – SSJS – UNID from Item

Page 54: XPages Performance

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 - SingleItem

Page 55: XPages Performance

XAgent – SSJS - SingleItem

Page 56: XPages Performance

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

XAgent – SSJS – ViewNavigator

Page 57: XPages Performance

XAgent – SSJS – ViewNavigator

Page 58: XPages Performance

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.concat

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

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

Page 59: XPages Performance

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.concat

http://kaioa.com/node/59

Page 60: XPages Performance

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

XAgent – SSJS – ViewNavigator + StringBuilder

Page 61: XPages Performance

XAgent – SSJS – ViewNavigator + StringBuilder

Page 62: XPages Performance

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 – Java

Page 63: XPages Performance

XAgent – Java

Page 64: XPages Performance

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 to extend

• webstandard, notes, oneUI

Themes

Page 65: XPages Performance

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

Themes

Page 66: XPages Performance

Global Application / Configuration properties

Ressourcen im Theme laden

Page 67: XPages Performance

Q + A

• Mail: [email protected]• Blog: http://www.eknori.de• Sametime: bleedyellow.com• Twitter: eknori

Page 68: XPages Performance