Wiki source code of Performance

Version 53.4 by JasperSiepkes on 2015/04/26

Show last authors
1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc/}}
3 {{/box}}
4
5 Here are some tips to increase XWiki's performance.
6
7 = Clustering =
8
9 If you need high availability or if the load on your XWiki instance is too high you can [[configure XWiki in a cluster>>platform:AdminGuide.Clustering]] to spread the load.
10
11 = Standalone Solr =
12
13 By default XWiki ships with an embedded Solr. If you have a lot of wiki pages (for example in a wiki farm with lots of subwikis), the embedded Solr may use up too much memory and CPU and in this case it's a good idea to externalize Solr on a different server. To do so:
14
15 * [[Download and install Solr>>https://cwiki.apache.org/confluence/display/solr/Installing+Solr]]
16 * [[Configure XWiki to use an external Solr instance>>extensions:Extension.Solr Search API||anchor="HConfiguration"]]
17
18 = Slow random number generation on UNIX =
19
20 The library used for random number generation in Sun's JVM relies on ##/dev/random## by default for UNIX platforms.
21
22 Although ##/dev/random## is more secure, it's possible to use ##/dev/urandom## if the default JVM configuration instead.
23
24 To determine if your operating system exhibits this behavior, try displaying a portion of the file from a shell prompt:
25
26 {{code language="bash"}}
27 head -n 1 /dev/random
28 {{/code}}
29
30 If the command returns immediately, you can use ##/dev/random## as the default generator for SUN's JVM. If the command does not return immediately, use these steps to configure the JVM to use ##/dev/urandom##:
31
32 1. Open the ##$JAVA_HOME/jre/lib/security/java.security## file in a text editor.
33 1. Change the line:
34 {{code language="properties"}} securerandom.source=file:/dev/random{{/code}}
35 to read:
36 {{code language="properties"}} securerandom.source=file:/dev/urandom{{/code}}
37 1. Save your change and exit the text editor.
38
39 = Gzip compression and caching of static pages =
40
41 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:
42
43 * [[mod-deflate>>http://httpd.apache.org/docs/2.0/mod/mod_deflate.html]]
44 * [[mod-expire>>http://httpd.apache.org/docs/2.0/mod/mod_expires.html]]
45 * [[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)
46
47 Modify your Apache configuration file to load the different modules:
48
49 {{code language="none"}}
50 LoadModule expires_module /usr/lib/apache2/modules/mod_expires.so
51 LoadModule deflate_module /usr/lib/apache2/modules/mod_deflate.so
52 LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
53 # Depends: proxy
54 LoadModule proxy_ajp_module /usr/lib/apache2/modules/mod_proxy_ajp.so
55 {{/code}}
56
57 //Alternatively you can run the following commands as root (sudo)//
58
59 {{code language="bash"}}
60 a2enmod deflate
61 a2enmod proxy_ajp
62 a2enmod expires
63 {{/code}}
64
65 and configure your different modules as described below:
66
67 == Mod Deflate Configuration ==
68
69 {{code language="none"}}
70 vwwwpro-1:~# cat /etc/apache2/conf.d/deflate
71 <Location />
72 # Insert filter
73 SetOutputFilter DEFLATE
74
75 # Netscape 4.x has some problems...
76 BrowserMatch ^Mozilla/4 gzip-only-text/html
77
78 # Netscape 4.06-4.08 have some more problems
79 BrowserMatch ^Mozilla/4.0[678] no-gzip
80
81 # MSIE masquerades as Netscape, but it is fine
82 # BrowserMatch bMSIE !no-gzip !gzip-only-text/html
83
84 # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
85 # the above regex won't work. You can use the following
86 # workaround to get the desired effect:
87 BrowserMatch bMSI[E] !no-gzip !gzip-only-text/html
88
89 # Don't compress images
90 SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
91
92 # Make sure proxies don't deliver the wrong content
93 #Header append Vary User-Agent env=!dont-vary
94 </Location>
95 {{/code}}
96
97 //On debian apache2 the config file for deflate is located under /etc/apache2/mods-enabled/deflate.conf//
98
99 == Mod Expire Configuration ==
100
101 {{code language="none"}}
102 vwwwpro-1:~# cat /etc/apache2/conf.d/expires
103 <Location /xwiki/skins/>
104 ExpiresActive on
105 ExpiresDefault "access plus 1 day"
106 </Location>
107
108 <Location /xwiki/bin/skin/>
109 ExpiresActive on
110 ExpiresDefault "access plus 1 day"
111 </Location>
112 {{/code}}
113
114 == Mod Proxy AJP Configuration ==
115
116 {{code language="none"}}
117 ProxyRequests Off
118 <Proxy *>
119 Order deny,allow
120 Allow from all
121 </Proxy>
122 ProxyPreserveHost On
123 ProxyPass /xwiki ajp://192.168.1.181:8009/xwiki
124 {{/code}}
125
126 where ##ajp:~/~/192.168.1.181:8009/xwiki## is the internal address of your Servlet container where XWiki is running.
127
128 If you use Tomcat(7) you need to enable the ajp connector in the /etc/tomcat7/server.xml. Comment out the following line with adding {{code}}<!-- -->{{/code}}. //Maybe give a comment why you did it.//
129
130 {{code}}
131 <!-- disable to use ajp connector instead
132 <Connector port="8080" protocol="HTTP/1.1"
133 connectionTimeout="20000"
134 URIEncoding="UTF-8"
135 redirectPort="8443" />
136 -->
137 {{/code}}
138
139 Uncomment the following line by removing the {{code}}<!-- -->{{/code}} and add {{code}}URIEncoding="UTF-8"{{/code}} to it.Maybe give a comment too.
140
141 {{code}}
142 <!-- Activate ajp connector for apache proxy_ajp -->
143 <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8"/>
144 {{/code}}
145
146 = Memory =
147
148 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. Here are some good default values:
149
150 * Small installs: A minimum of 512MB of heap memory and 196MB of permGen (##-Xmx512m -XX:MaxPermSize=196m##)
151 * Medium installs: 1024MB for the heap and 196MB of permGen (##-Xmx1024m -XX:MaxPermSize=196m##)
152 * Large installs: 2048MB (or beyond) for the heap and 196MB of permGen (##-Xmx2048m -XX:MaxPermSize=196m##).
153
154 {{info}}
155 You should not increase the memory beyond what you need because increasing it means that there's more Objects in memory at any time and the automatic JVM Garbage Collector has to work harder to clean itself, which can results in performance degradation in XWiki (since a full GC will pause the application for a longer time).
156 {{/info}}
157
158 {{warning}}
159 Note that storing attachments with the default (in database) storage mechanism is very memory intensive. See the [[administrators guide to attachments>>platform:AdminGuide.Attachments]] for more information about memory cost and the alternative filesystem based attachment store.
160
161 Also note that uploading a lot of pages can trigger out of memory (OOM) errors due to scheduled watchlist jobs. For example uploading 1 million pages will trigger OOM errors even when the JVM is configured to run with 2GB of heap space. For such kind of load we recommend to disable (unschedule) the Watchlist jobs (in ##/xwiki/bin/view/Scheduler/##) before uploading the pages.
162 {{/warning}}
163
164 For your information here are the values used for the xwiki.org site:
165
166 {{code}}
167 CATALINA_OPTS="-server -Xms800m -Xmx1480m -XX:MaxPermSize=222m -Dfile.encoding=utf-8 -Djava.awt.headless=true -XX:+UseParallelGC -XX:MaxGCPauseMillis=100"
168 {{/code}}
169
170 = Database Indexes =
171
172 Make sure you've set [[Database indexes>>Database Administration]]. This is especially important when you start having lots of documents.
173
174 = Panels =
175
176 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).
177
178 = Robots.txt =
179
180 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 the 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:
181
182 {{code language="none"}}
183 User-agent: *
184 Disallow: /xwiki/bin/attach/
185 Disallow: /xwiki/bin/cancel/
186 Disallow: /xwiki/bin/commentadd/
187 Disallow: /xwiki/bin/delattachment/
188 Disallow: /xwiki/bin/delete/
189 Disallow: /xwiki/bin/dot/
190 Disallow: /xwiki/bin/download/
191 Disallow: /xwiki/bin/downloadrev/
192 Disallow: /xwiki/bin/edit/
193 Disallow: /xwiki/bin/export/
194 Disallow: /xwiki/bin/get/
195 Disallow: /xwiki/bin/inline/
196 Disallow: /xwiki/bin/lifeblog/
197 Disallow: /xwiki/bin/login/
198 Disallow: /xwiki/bin/loginerror/
199 Disallow: /xwiki/bin/logout/
200 Disallow: /xwiki/bin/objectremove/
201 Disallow: /xwiki/bin/pdf/
202 Disallow: /xwiki/bin/preview/
203 Disallow: /xwiki/bin/propadd/
204 Disallow: /xwiki/bin/propdelete/
205 Disallow: /xwiki/bin/propupdate/
206 Disallow: /xwiki/bin/register/
207 Disallow: /xwiki/bin/save/
208 Disallow: /xwiki/bin/skin/
209 Disallow: /xwiki/bin/status/
210 Disallow: /xwiki/bin/upload/
211 Disallow: /xwiki/bin/viewattachrev/
212 Disallow: /xwiki/bin/viewrev/
213 Disallow: /xwiki/bin/xmlrpc/
214 # It could be also usefull to block certain spaces from crawling,
215 # especially if this spaces doesn't provide new content
216 Disallow: /xwiki/bin/view/Main/
217 Disallow: /xwiki/bin/view/XWiki/
218 # on the other hand you would like to have your recent (public) changes included
219 Allow: /xwiki/bin/view/Main/Dashboard
220 {{/code}}
221
222
223 **Note:**
224
225 For Tomcat6 the placement of the ##robots.txt## file should be within the //$TOMCAT/webapps/ROOT// folder and should have permission 644 applied.
226
227 {{code}}
228 -rw-r--r-- 1 root www 1478 Jan 8 15:52 robots.txt
229 {{/code}}
230
231 In order to test if the ##robots.txt## file is either accessable or working as desired use this [[checker>>http://www.frobee.com/robots-txt-check]].
232
233 = Statistics =
234
235 {{info}}
236 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.
237 {{/info}}
238
239 The statistics module is off by default since it's quite database intensive. If you don't need it you should turn it off.
240
241 = Monitoring =
242
243 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##:
244
245 {{code language="null"}}
246 xwiki.monitor=0
247 {{/code}}
248
249 = Document Cache =
250
251 You can tune the Document cache in the ##xwiki.cfg## configuration file. The value depends on how much memory you have. The higher the better. A good reasonable value is 1000.
252
253 {{code language="none"}}
254 xwiki.store.cache.capacity=1000
255 {{/code}}
256
257 = Cache Macro =
258
259 It's possible to perform selective content caching by using the [[Cache Macro>>extensions:Extension.Cache Macro]].
260
261 = LESS Cache =
262
263 [[LESS>>extensions:Extension.LESS Module]] is a preprocessor used to generate CSS files for skins and skin extensions. See the [[Performance section>>extensions:Extension.LESS Module||anchor="HPerformances"]] of the LESS module documentation to learn more about how to optimize this cache for performances.
264
265 = Rendering cache =
266
267 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.
268
269 == Configuration based ==
270
271 Pages can be cached (i.e. their rendered content cached) to speed up displaying. The configuration is done in ##xwiki.properties## with the following configuration options:
272
273 {{code language="none"}}
274 #-# [Since 2.4M1]
275 #-# Indicate if the rendering cache is enabled.
276 #-# Default value is false.
277 # core.renderingcache.enabled=true
278
279 #-# [Since 2.4M1]
280 #-# A list of Java regex patterns matching full documents reference.
281 # core.renderingcache.documents=wiki:Space\.Page
282 # core.renderingcache.documents=wiki:Space\..*
283
284 #-# [Since 2.4M1]
285 #-# The time (in seconds) after which data should be removed from the cache when not used.
286 #-# Default value is 300 (5 min).
287 # core.renderingcache.duration=300
288
289 #-# [Since 2.4M1]
290 #-# The size of the rendering cache. Not that it's not the number of cached documents but the number of cached results.
291 #-# (For a single document several cache entries are created, because each action, language and request query string
292 #-# produces a unique rendering result)
293 #-# Default value is 100.
294 # core.renderingcache.size=100
295 {{/code}}
296
297 You can force a page to refresh using ##refresh=1## in the URL.
298
299 Since 6.2 it's also possible to programmatically refresh any document cache using ##com.xpn.xwiki.internal.cache.rendering.RenderingCache## component:
300
301 {{code language="java"}}
302 @Inject
303 private RenderingCache renderingCache;
304
305 ...
306
307 renderingCache.flushWholeCache();
308 renderingCache.flushCache(new DocumentReference("xwiki", "MySpace", "MyCachedDocument"));
309 {{/code}}
310
311 == Enabled using velocity in document content itself (XWiki 1.0 syntax only) ==
312
313 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:
314
315 {{code language="none"}}
316 $context.setCacheDuration(60)
317 {{/code}}
318
319 Since 1.5M2, you can set the default rendering cache duration for all pages in ##xwiki.cfg##:
320
321 {{code language="none"}}
322 ## cache all rendered documents for one hour
323 xwiki.rendering.defaultCacheDuration=3600
324 {{/code}}
325
326 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.
327
328 = Merge the CSS files =
329
330 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 Script>>extensions:Extension.Merge CSS]].
331
332 = Set up NginX =
333
334 If you experience //__heavy loads__// on your wiki, you could try using NginX.
335
336 NginX is used to fetch static content: images, javascript, styles, etc, but it can also be used as a reverse-proxy to pass requests down to the web container (e.g. Tomcat on port 8080).
337
338 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".
339
340 For more info on setting up NginX check [[this guide>>NginX]].
341
342 = Backlinks =
343
344 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##:
345
346 {{code language="none"}}
347 xwiki.backlinks=0
348 {{/code}}
349
350 = Versioning =
351
352 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##:
353
354 {{code language="none"}}
355 xwiki.store.versioning=0
356 {{/code}}
357
358 = Custom Mapping =
359
360 In some cases you may not want 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]].
361
362 = Wiki syntax features for XWiki Syntax 1.0 =
363
364 If you're using XWiki Syntax 1.0 and if you don't plan to use all of the markup 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.
365
366 Now this will have no effect if you're using another syntax, like XWiki Syntax 2.x.

Get Connected