Wiki source code of Performance

Version 32.1 by kayasaman on 2012/01/09

Hide last authors
HDirkSchmitt 22.1 1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc/}}
3 {{/box}}
Silvia Macovei 20.1 4
Niels Mayer 17.1 5 Here are some tips to increase XWiki's performance.
Vincent Massol 10.1 6
Silvia Macovei 20.2 7 = Gzip compression and caching of static pages =
Vincent Massol 14.1 8
Silvia Macovei 20.1 9 We're working on making these features part of the XWiki core (see [[XWIKI-2022>>http://jira.xwiki.org/jira/browse/XWIKI-2022]]). While waiting for this to be natively implemented, the recommended solution is to set up an Apache Web Server in front of your servlet container and install/configure the following modules:
Vincent Massol 14.1 10
Silvia Macovei 20.1 11 * [[mod-deflate>>http://httpd.apache.org/docs/2.0/mod/mod_deflate.html]]
12 * [[mod-expire>>http://httpd.apache.org/docs/2.0/mod/mod_expires.html]]
13 * [[mod-proxy-ajp>>http://httpd.apache.org/docs/2.2/mod/mod_proxy_ajp.html]] (note that this depends on [[mod-proxy>>http://httpd.apache.org/docs/2.2/mod/mod_proxy.html]] that you also need to install)
14
Vincent Massol 14.1 15 Modify your Apache configuration file to load the different modules:
16
Silvia Macovei 20.1 17 {{code language="none"}}
Vincent Massol 14.1 18 LoadModule expires_module /usr/lib/apache2/modules/mod_expires.so
19 LoadModule deflate_module /usr/lib/apache2/modules/mod_deflate.so
20 LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
21 # Depends: proxy
22 LoadModule proxy_ajp_module /usr/lib/apache2/modules/mod_proxy_ajp.so
Silvia Macovei 20.1 23 {{/code}}
Vincent Massol 14.1 24
25 And configure your different modules as described below.
26
Silvia Macovei 20.2 27 == Mod Deflate Configuration ==
Vincent Massol 14.1 28
Silvia Macovei 20.1 29 {{code language="none"}}
Vincent Massol 14.1 30 vwwwpro-1:~# cat /etc/apache2/conf.d/deflate
31 <Location />
32 # Insert filter
33 SetOutputFilter DEFLATE
34
35 # Netscape 4.x has some problems...
36 BrowserMatch ^Mozilla/4 gzip-only-text/html
37
38 # Netscape 4.06-4.08 have some more problems
Silvia Macovei 20.1 39 BrowserMatch ^Mozilla/4.0[678] no-gzip
Vincent Massol 14.1 40
41 # MSIE masquerades as Netscape, but it is fine
Silvia Macovei 20.1 42 # BrowserMatch bMSIE !no-gzip !gzip-only-text/html
Vincent Massol 14.1 43
44 # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
45 # the above regex won't work. You can use the following
46 # workaround to get the desired effect:
Silvia Macovei 20.1 47 BrowserMatch bMSI[E] !no-gzip !gzip-only-text/html
Vincent Massol 14.1 48
49 # Don't compress images
Silvia Macovei 20.1 50 SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
Vincent Massol 14.1 51
52 # Make sure proxies don't deliver the wrong content
53 #Header append Vary User-Agent env=!dont-vary
54 </Location>
Silvia Macovei 20.1 55 {{/code}}
Vincent Massol 14.1 56
Silvia Macovei 20.2 57 == Mod Expire Configuration ==
Vincent Massol 14.1 58
Silvia Macovei 20.1 59 {{code language="none"}}
Vincent Massol 14.1 60 vwwwpro-1:~# cat /etc/apache2/conf.d/expires
61 <Location /xwiki/skins/>
62 ExpiresActive on
63 ExpiresDefault "access plus 1 day"
64 </Location>
65
66 <Location /xwiki/bin/skin/>
67 ExpiresActive on
68 ExpiresDefault "access plus 1 day"
69 </Location>
Silvia Macovei 20.1 70 {{/code}}
Vincent Massol 14.1 71
Silvia Macovei 20.2 72 == Mod Proxy AJP Configuration ==
Vincent Massol 14.1 73
Silvia Macovei 20.1 74 {{code language="none"}}
75 ProxyRequests Off
Vincent Massol 14.1 76 <Proxy *>
77 Order deny,allow
78 Allow from all
79 </Proxy>
80 ProxyPreserveHost On
81 ProxyPass /xwiki ajp://192.168.1.181:8009/xwiki
Silvia Macovei 20.1 82 {{/code}}
Vincent Massol 14.1 83
Silvia Macovei 20.1 84 where ##ajp:~/~/192.168.1.181:8009/xwiki## is the internal address of your Servlet container where XWiki is running.
Vincent Massol 14.1 85
Silvia Macovei 20.2 86 = Memory =
Vincent Massol 9.1 87
88 You need to configure your Servlet container so that XWiki has enough memory. You'll need to tune the value to your need. You should check the logs and see if there are any out of memory errors. A good default value is 384MB (-Xmx384m).
89
Vincent Massol 13.1 90 Here are the values used for xwiki.org's web site:
Silvia Macovei 20.1 91
92 {{code language="none"}}
kuchumovn 19.1 93 CATALINA_OPTS="-server -Xms128m -Xmx1024m -XX:MaxPermSize=128m -Dfile.encoding=utf-8 -Djava.awt.headless=true -XX:+UseParallelGC -XX:MaxGCPauseMillis=100"
Silvia Macovei 20.1 94 {{/code}}
Vincent Massol 13.1 95
Silvia Macovei 20.2 96 = Database Indexes =
Vincent Massol 1.1 97
Silvia Macovei 20.1 98 Make sure you've set [[Database indexes>>Database Administration||target=""]]. This is especially important when you start having lots of documents.
Vincent Massol 1.1 99
Silvia Macovei 20.2 100 = Panels =
Vincent Massol 1.1 101
Niels Mayer 17.1 102 Some Panels take more resources than others. For example the Navigation panel should NOT be used for wikis with a lot of documents since it displays all documents in the wiki. In the future that Panel should be improved for performance but that's not the case right now. Originally this Panel was only meant as a starting point. A better approach is to use a Quick Links Panel as we've now set up in the default XWiki Enterprise wiki version 1.1 (we've removed the default usage of the Navigation Panel in that version).
Vincent Massol 1.1 103
Silvia Macovei 20.2 104 = Robots.txt =
Vincent Massol 15.1 105
Silvia Macovei 20.1 106 If your wiki is open on the Internet, it'll be crawled by search robots (like GoogleBot, etc). They will call all the URLs and especially ones that are resource hungry like exports (PDF/RTF). You need to protect against this. To do so configure a ##robots.txt## file like this one and put it in your webserver configuration:
Vincent Massol 15.1 107
Silvia Macovei 20.1 108 {{code language="none"}}
Vincent Massol 15.1 109 User-agent: *
HDirkSchmitt 22.1 110 Disallow: /xwiki/bin/attach/
111 Disallow: /xwiki/bin/cancel/
112 Disallow: /xwiki/bin/commentadd/
113 Disallow: /xwiki/bin/delattachment/
114 Disallow: /xwiki/bin/delete/
115 Disallow: /xwiki/bin/dot/
116 Disallow: /xwiki/bin/download/
117 Disallow: /xwiki/bin/downloadrev/
Vincent Massol 15.1 118 Disallow: /xwiki/bin/edit/
HDirkSchmitt 22.1 119 Disallow: /xwiki/bin/export/
120 Disallow: /xwiki/bin/get/
Vincent Massol 15.1 121 Disallow: /xwiki/bin/inline/
HDirkSchmitt 22.1 122 Disallow: /xwiki/bin/lifeblog/
123 Disallow: /xwiki/bin/login/
124 Disallow: /xwiki/bin/loginerror/
125 Disallow: /xwiki/bin/logout/
126 Disallow: /xwiki/bin/objectremove/
127 Disallow: /xwiki/bin/pdf/
Vincent Massol 15.1 128 Disallow: /xwiki/bin/preview/
129 Disallow: /xwiki/bin/propadd/
130 Disallow: /xwiki/bin/propdelete/
HDirkSchmitt 22.1 131 Disallow: /xwiki/bin/propupdate/
132 Disallow: /xwiki/bin/register/
133 Disallow: /xwiki/bin/save/
Vincent Massol 15.1 134 Disallow: /xwiki/bin/skin/
135 Disallow: /xwiki/bin/status/
HDirkSchmitt 22.1 136 Disallow: /xwiki/bin/upload/
137 Disallow: /xwiki/bin/viewattachrev/
Vincent Massol 15.1 138 Disallow: /xwiki/bin/viewrev/
HDirkSchmitt 22.1 139 Disallow: /xwiki/bin/xmlrpc/
140 # It could be also usefull to block certain spaces from crawling,
141 # especially if this spaces doesn't provide new content
142 Disallow: /xwiki/bin/view/Main/
143 Disallow: /xwiki/bin/view/XWiki/
144 # on the other hand you would like to have your recent (public) changes included
145 Allow: /xwiki/bin/view/Main/Dashboard
Silvia Macovei 20.1 146 {{/code}}
Vincent Massol 15.1 147
kayasaman 32.1 148
149 **Note**
150
151 For Tomcat6 the placement of the robots.txt file should be within the $TOMCAT/webapps/ROOT folder and should have permission 644 applied.
152
153 {{code}}
154 -rw-r--r-- 1 root www 1478 Jan 8 15:52 robots.txt
155 {{/code}}
156
157
158 In order to test if the robots.txt file is either accessable or working as desired this link is useful:
159
160 [[Robots Check>>http://http://www.frobee.com/robots-txt-check]]
161
Silvia Macovei 20.2 162 = Statistics =
Vincent Massol 1.1 163
Silvia Macovei 20.1 164 {{info}}
165 This is no longer true starting with XE 1.4M2 since statistics are now put on a queue and written in a different thread in the database in one go, thus reducing the overhead to a maximum.
166 {{/info}}
Vincent Massol 15.1 167
Vincent Massol 1.2 168 The statistics module is off by default since it's quite Database intensive. If you don't need it you should turn it off.
169
Silvia Macovei 20.2 170 = Monitoring =
Sergiu Dumitriu 7.1 171
Silvia Macovei 20.1 172 More a developer-oriented feature, XWiki can monitor its own code, reporting the time spent for each sub-component activated during a request. While the monitoring code isn't time consuming, it increases the memory consumption a bit, and the create/start/stop/log/destroy calls are spread all around the code, so you will save a lot of method calls by disabling this. You can do that by setting the following line in ##xwiki.cfg##:
173
174 {{code language="null"}}
kuchumovn 19.1 175 xwiki.monitor=0
Silvia Macovei 20.1 176 {{/code}}
Sergiu Dumitriu 7.1 177
Silvia Macovei 20.2 178 = Cache sizes =
Vincent Massol 1.2 179
Silvia Macovei 20.1 180 Tune the document cache in ##xwiki.cfg##. The value depends on how much memory you have. The higher the better. A good reasonable value is 1000.
Vincent Massol 2.1 181
Silvia Macovei 20.1 182 {{code language="none"}}
kuchumovn 19.1 183 xwiki.store.cache.capacity=1000
Silvia Macovei 20.1 184 {{/code}}
Vincent Massol 8.1 185
Vincent Massol 25.1 186 = Cache Macro =
187
Vincent Massol 26.1 188 It's possible to perform selective content caching by using the [[Cache Macro>>extensions:Extension.Cache Macro]].
Vincent Massol 25.1 189
Silvia Macovei 20.2 190 = Rendering cache =
Vincent Massol 2.1 191
Thomas Mortagne 30.1 192 Some pages are complex to render (they may aggregate outside data for example or do complex and slow queries). For theses pages you can use rendering cache.
193
Thomas Mortagne 29.1 194 == Configuration based ==
Vincent Massol 25.1 195
196 Pages can be cached (ie their rendered content cached) to speed up displaying. The configuration is done in ##xwiki.properties## with the following configuration options:
197
198 {{code language="none"}}
199 #-# [Since 2.4M1]
200 #-# Indicate if the rendering cache is enabled.
201 #-# Default value is false.
202 # core.renderingcache.enabled=true
203
204 #-# [Since 2.4M1]
205 #-# A list of Java regex patterns matching full documents reference.
206 # core.renderingcache.documents=wiki:Space\.Page
207 # core.renderingcache.documents=wiki:Space\..*
208
209 #-# [Since 2.4M1]
210 #-# The time (in seconds) after which data should be removed from the cache when not used.
211 #-# Default value is 300 (5 min).
212 # core.renderingcache.duration=300
213
214 #-# [Since 2.4M1]
215 #-# The size of the rendering cache. Not that it's not the number of cached documents but the number of cached results.
216 #-# (For a single document several cache entries are created, because each action, language and request query string
217 #-# produces a unique rendering result)
218 #-# Default value is 100.
219 # core.renderingcache.size=100
220 {{/code}}
221
Thomas Mortagne 31.1 222 You can force a page to refresh using ##refresh=1## in the URL.
Thomas Mortagne 30.1 223
Thomas Mortagne 28.1 224 == Enabled using velocity in document content itself (XWiki 1.0 syntax only) ==
Vincent Massol 25.1 225
Thomas Mortagne 30.1 226 You can add the following to their content to cache them after they are rendered. Note that the document is refreshed whenever the content of the document changes, and the cache takes into account the URL, so it is pretty safe to add a long cache duration for all documents that don't contain scripts gathering data from the wiki. For example to cache the rendered content for 60 seconds you would add:
Vincent Massol 2.1 227
Silvia Macovei 20.1 228 {{code language="none"}}
kuchumovn 19.1 229 $context.setCacheDuration(60)
Silvia Macovei 20.1 230 {{/code}}
Vincent Massol 2.1 231
Silvia Macovei 20.1 232 Since 1.5M2, you can set the default rendering cache duration for all pages in ##xwiki.cfg##:
233
234 {{code language="none"}}
Sergiu Dumitriu 16.1 235 ## cache all rendered documents for one hour
236 xwiki.rendering.defaultCacheDuration=3600
Silvia Macovei 20.1 237 {{/code}}
238
Sergiu Dumitriu 16.1 239 Setting the default cache duration to a large value, and manually disabling the cache in dynamic pages would really speed up the wiki, since the rendering is one of the most time consuming processes.
240
Silvia Macovei 20.2 241 = Merge the CSS files =
Vincent Massol 11.1 242
Vincent Massol 24.3 243 In order to reduce the number of requests and files that are downloaded from the browser or client, it could help to merge all XWiki CSS files into a single one. See the [[Merge CSS Snippet>>extensions:Extension.Merge CSS]]
Vincent Massol 11.1 244
Silvia Macovei 20.2 245 = Set up NginX =
kuchumovn 19.2 246
Silvia Macovei 20.2 247 If you experience //__heavy loads__// on your wiki, you could try using //NginX//.
kuchumovn 19.3 248
Silvia Macovei 20.1 249 //NginX// is used to fetch //static// content: //images, javascript, styles, etc.//
kuchumovn 19.2 250
Silvia Macovei 20.1 251 Unlike //Apache//, which instantiates a new //process// per every static file, //NginX// uses the same //process// to fetch all the static data, and thus gives you extra perfomance //"for free"//.
kuchumovn 19.2 252
Silvia Macovei 20.1 253 For more info on setting up //NginX// look [[here>>NginX]]
kuchumovn 19.2 254
Silvia Macovei 20.2 255 = Backlinks =
Sergiu Dumitriu 4.1 256
Silvia Macovei 20.1 257 While a pretty neat feature, keeping track of the backlinks has a medium impact on the document saving time and a minor impact on the document loading time. If you feel that your wiki does not need backlinks, you can safely disable them with the following line in ##xwiki.cfg##:
258
259 {{code language="none"}}
kuchumovn 19.1 260 xwiki.backlinks=0
Silvia Macovei 20.1 261 {{/code}}
Sergiu Dumitriu 5.1 262
Silvia Macovei 20.2 263 = Versioning =
Sergiu Dumitriu 5.1 264
Silvia Macovei 20.1 265 One of the key features of any wiki system, versioning greatly affects the database size and the document update time. If you are sure your wiki does not need to keep track of all the changes and you will never need to revert documents to a previous version, then you can add the following line in ##xwiki.cfg##
266
267 {{code language="none"}}
kuchumovn 19.1 268 xwiki.store.versioning=0
Silvia Macovei 20.1 269 {{/code}}
Sergiu Dumitriu 6.1 270
Vincent Massol 21.1 271 = Custom Mapping =
Sergiu Dumitriu 6.1 272
Vincent Massol 21.1 273 In some cases you may want not to rely on XWiki's generic database schema for storing XClass data and instead you'd like to provide your own optimized table. For these use cases you can use [[Custom Mapping>>platform:DevGuide.CustomMapping]].
274
275 = Wiki syntax features for XWiki Syntax 1.0 =
276
Silvia Macovei 20.2 277 If you don't plan to use all of the wiki features, like the --strikethrough-- filter, the automatic http links filter, the SVG, Laszlo or style macros, you can disable them in ##xwiki-core-*.jar/META-INF/services/com.xpn.xwiki.render.*##. The wiki rendering is the most costly operation in the rendering process, so any disabled feature counts.

Get Connected