xwiki管理指南-性能

目录

集群

独立出Solr

unix随机数

gzip压缩和静态页面缓存

Mod Deflate 配置

Mod Expire 配置

Mod Proxy AJP 配置

内存

数据库索引

面板

Robots.txt

统计

文档缓存

缓存宏

LESS缓存

渲染缓存

基于配置

合并CSS文件

设置Nginx

反向链接

版本控制

自定义映射

LDAP

禁用LDAP子组搜索

性能树

废弃

监控插件

1.0 使用velocity渲染文件内容缓存

XWiki语法1.0(wiki语法)


下面是一些贴士来帮助提升XWiki的性能

集群

如果你需要高可用性,或者您的XWiki实例负荷过高则可以配置集群实现分散负载

独立出Solr

默认情况下XWiki使用嵌入式Solr,主要是为了方便开发。但是如果页面开始多起来,搜索变得很慢,那么应该试下使用外部Solr实例(独立出solr)。Solr 需要使用大量内存,一个独立的solr实例查询速度优等于嵌入式。另外,Solr索引位于存储介质的速度也是非常重要的。例如把它放在一个固态硬盘可能会有一个明显的提升。您还可以在https://wiki.apache.org/solr/SolrPerformanceProblems 找到更多solr性能相关的详细信息。
独立的Solr还附带了一个非常漂亮的用户界面,以及监控和测试工具。

unix随机数

linux或者部分unix系统提供随机数设备是/dev/random 和/dev/urandom ,两个有区别,urandom安全性没有random高,但random需要时间间隔生成随机数。jdk默认调用random。
dev/random在不能产生新的随机数时会阻塞程序,直到根据熵池产生新的随机字节之后才返回,所以使用/dev/random比使用/dev/urandom产生大量随机数的速度要慢。
可以通过以下命令查看是否你的系统会出现伪随机数提供等待:

head -n 1 /dev/random

如果命令直接返回结果,那么可以直接用JDK默认的/dev/random。如果没有直接返回结果而且等待时间比较长,那么用以下步骤配置JVM为/dev/urandom:

  1. 用文本编辑器打开$JAVA_HOME/jre/lib/security/java.security
  2. 找到这行:
       securerandom.source=file:/dev/random
        to read:
       securerandom.source=file:/dev/urandom
  3. 保存更改

gzip压缩和静态页面缓存

为了提升xwiki的页面响应速度,推荐的解决方案是在Servlet容器前建立一个Apache Web Server作为HTTP服务器,安装/配置以下模块

  • mod-deflate模块提供了DEFLATE输出过滤器,允许服务器在将输出内容发送到客户端以前进行压缩,以节约带宽
  • mod-expire允许通过配置文件控制HTTP的"Expires:"和"Cache-Control:"头内容
  • mod-proxy-ajp mod_proxy的扩展,提供Apache JServ Protocol支持

修改你的Apache配置文件来加载不同的模块:

LoadModule expires_module /usr/lib/apache2/modules/mod_expires.so
LoadModule deflate_module /usr/lib/apache2/modules/mod_deflate.so
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
# Depends: proxy
LoadModule proxy_ajp_module /usr/lib/apache2/modules/mod_proxy_ajp.so

root用户登录执行以下命令

a2enmod deflate
a2enmod proxy_ajp
a2enmod expires

按下所述配置不同的模块:

Mod Deflate 配置

vwwwpro-1:~# cat /etc/apache2/conf.d/deflate
<Location />
   # Insert filter
   SetOutputFilter DEFLATE

   # Netscape 4.x has some problems...
   BrowserMatch ^Mozilla/4 gzip-only-text/html

   # Netscape 4.06-4.08 have some more problems
   BrowserMatch ^Mozilla/4.0[678] no-gzip

   # MSIE masquerades as Netscape, but it is fine
   # BrowserMatch bMSIE !no-gzip !gzip-only-text/html

   # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
   # the above regex won't work. You can use the following
   # workaround to get the desired effect:
   BrowserMatch bMSI[E] !no-gzip !gzip-only-text/html

   # Don't compress images
   SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary

   # Make sure proxies don't deliver the wrong content
   #Header append Vary User-Agent env=!dont-vary
</Location>

在debian系统apache2的配置文件位于/etc/apache2/mods-enabled/deflate.conf

Mod Expire 配置

vwwwpro-1:~# cat /etc/apache2/conf.d/expires
<Location /xwiki/skins/>
       ExpiresActive on
       ExpiresDefault "access plus 1 day"
</Location>

<Location /xwiki/bin/skin/>
       ExpiresActive on
       ExpiresDefault "access plus 1 day"
</Location>

Mod Proxy AJP 配置

ProxyRequests Off
   <Proxy *>
       Order deny,allow
       Allow from all
   </Proxy>
   ProxyPreserveHost On
   ProxyPass /xwiki ajp://192.168.1.181:8009/xwiki

ajp://192.168.1.181:8009/xwiki 指的是你运行xwiki的servlet服务器地址

如果你启用Tomcat7那么需要启用/etc/tomcat7/server.xml里面AJP连接配置,注释掉以下面代码里的 <!-- -->. 

    <!-- disable to use ajp connector instead
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               URIEncoding="UTF-8"
               redirectPort="8443" />
    -->

注释掉以下面代码里的<!-- -->并添加URIEncoding="UTF-8" 

<!-- Activate ajp connector for apache proxy_ajp -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8"/>

内存

您需要配置您的Servlet容器,这样XWiki才有足够的内存。你需要根据你的需求调整值。您应检查日志,看看是否有任何“内存不足”的错误。这里有一些可参考的默认值:  

  • Small installs: 最小512MB堆内存和196MB永久保存区域大小(-Xmx512m -XX:MaxPermSize=196m)
  • Medium installs: 堆内存1024MB和196MB永久保存区域大小(-Xmx1024m -XX:MaxPermSize=196m)
  • Large installs: 堆内存2048MB (或以上)和196MB永久保存区域大小(-Xmx2048m -XX:MaxPermSize=196m)

你不应该增加超过你所需要的内存,因为会有更多的对象存在内存中而JVM的垃圾收集器必须更加努力地清理,它会导致XWiki性能下降(因为Full GC暂停应用会花更长的时间)

需要注意的是默认存储附件是存储在数据库,该存储机制是非常占用内存的。

另外需要注意的是,上传了大量的页面会由于scheduled watchlist jobs(在Scheduler应用下面)引发出的内存(OOM)的错误。例如上传百万页,甚至JVM堆空间配置为2GB会引发OOM错误。对于此类负荷,我们建议上传页面之前禁用(取消调度)的监视列表中的工作(在/xwiki/bin/view/Scheduler/)

以下是xwiki.org网站的配置:

CATALINA_OPTS="-server -Xms800m -Xmx1480m -XX:MaxPermSize=222m -Dfile.encoding=utf-8 -Djava.awt.headless=true -XX:+UseParallelGC -XX:MaxGCPauseMillis=100"

数据库索引

确保你设置数据库索引。当你wiki数量比较大,这个设置就尤为重要了。

面板

某些面板需要更多的资源。举例来说,导航面板不应该被用于有很多文件的wiki,因为它显示wiki所有文件。在未来这个面板应当对性能改善,但并非现在。更好的方法是使用“快速链接面板”,因为我们现在已经建立了1.1版本

Robots.txt

如果您的维基是在互联网上公开,它会被搜索机器人被抓取(如Googlebot等)。网站通过Robots协议告诉搜索引擎哪些页面可以抓取,哪些页面不能抓取。为此设置robots.txt文件如下,把它放在你的web服务器: 

User-agent: *
Disallow: /xwiki/bin/attach/
Disallow: /xwiki/bin/cancel/
Disallow: /xwiki/bin/commentadd/
Disallow: /xwiki/bin/delattachment/
Disallow: /xwiki/bin/delete/
Disallow: /xwiki/bin/dot/
Disallow: /xwiki/bin/download/
Disallow: /xwiki/bin/downloadrev/
Disallow: /xwiki/bin/edit/
Disallow: /xwiki/bin/export/
Disallow: /xwiki/bin/get/
Disallow: /xwiki/bin/inline/
Disallow: /xwiki/bin/lifeblog/
Disallow: /xwiki/bin/login/
Disallow: /xwiki/bin/loginerror/
Disallow: /xwiki/bin/logout/
Disallow: /xwiki/bin/objectremove/
Disallow: /xwiki/bin/pdf/
Disallow: /xwiki/bin/preview/
Disallow: /xwiki/bin/propadd/
Disallow: /xwiki/bin/propdelete/
Disallow: /xwiki/bin/propupdate/
Disallow: /xwiki/bin/register/
Disallow: /xwiki/bin/save/
Disallow: /xwiki/bin/skin/
Disallow: /xwiki/bin/status/
Disallow: /xwiki/bin/upload/
Disallow: /xwiki/bin/viewattachrev/
Disallow: /xwiki/bin/viewrev/
Disallow: /xwiki/bin/xmlrpc/
# It could be also usefull to block certain spaces from crawling,
# especially if this spaces doesn't provide new content
Disallow: /xwiki/bin/view/Main/
Disallow: /xwiki/bin/view/XWiki/
# on the other hand you would like to have your recent (public) changes included
Allow: /xwiki/bin/view/Main/Dashboard

注意:

对于的tomcat6的robots.txt文件在 $TOMCAT/webapps/ROOT中,应有644权限。

-rw-r--r--  1 root  www  1478 Jan  8 15:52 robots.txt

统计

从XE1.4M2开始,统计放在一个队列,并在不同线程写入数据库,从而降低开销

统计模块默认是关闭的,因为它是相当密集的数据库。如果你不需要它,你应该把它关掉。

文档缓存

您可以调整xwiki.cfg配置文件中的Document cache(文件缓存)。该值取决于你有多少内存。越高越好。一个良好的合理值为:

xwiki.store.cache.capacity=1000

缓存宏

可以通过使用缓存宏进行选择性的内容缓存,如:

{{cache id="..." timeToLive="..." maxEntries="..."}}
content to cache here...
{{/cache}}

LESS缓存

LESS是一个预处理用于生成皮肤和扩展皮肤的CSS文件。 
默认情况下,LESS缓存是在维基启动时清洁。如果要保留以前运行时的缓存,你可以在xwiki/WEB-INF/cache/infinispan/config.xml:中增加如下设置:

<!-- LESS CSS cache -->
<local-cache name="lesscss.skinfiles.cache">
  <persistence>
    <file-store purge="false">
      <!-- Let XWiki cache module set the proper location -->
    </file-store>
  </persistence>
</local-cache>

渲染缓存

有些是复杂的渲染(例如汇总外部的数据或进行复杂而缓慢的查询)。对于这些的网页,你可以使用渲染缓存。

基于配置

页面可以缓存(即它们的渲染内容缓存)以加速显示。配置xwiki.properties 以下选项: 

#-# [Since 2.4M1]
#-# Indicate if the rendering cache is enabled.
#-# Default value is false.
# core.renderingcache.enabled=true

#-# [Since 2.4M1]
#-# A list of Java regex patterns matching full documents reference.
# core.renderingcache.documents=wiki:Space\.Page
# core.renderingcache.documents=wiki:Space\..*

#-# [Since 2.4M1]
#-# The time (in seconds) after which data should be removed from the cache when not used.
#-# Default value is 300 (5 min).
# core.renderingcache.duration=300

#-# [Since 2.4M1]
#-# The size of the rendering cache. Not that it's not the number of cached documents but the number of cached results.
#-# (For a single document several cache entries are created, because each action, language and request query string
#-# produces a unique rendering result)
#-# Default value is 100.
# core.renderingcache.size=100

你可以在URL使用refresh=1强制页面刷新

从6.2以来,可以以编程方式使用com.xpn.xwiki.internal.cache.rendering.RenderingCache组件更新任何文件缓存:

@Inject
private RenderingCache renderingCache;

...

renderingCache.flushWholeCache();
renderingCache.flushCache(new DocumentReference("xwiki", "MySpace", "MyCachedDocument"));

合并CSS文件

为了减少请求和文件从浏览器或客户端下载的数量,可以把所有的CSS文件合并成一个单一的文件。查看Merge CSS Script了解更多信息

设置Nginx

如果你的xwiki遇到高负载,您可以尝试使用nginx

Nginx是用于获取静态内容:图像,JavaScript,styles等,但它也可以被用来作为一个反向代理传递请求到Web容器(如Tomcat 8080端口)

和Apache不一样,Apache为每个静态文件实例化一个新的进程,而Nginx的使用相同的进程来获取所有静态数据,从而性能更好

反向链接

保持反向链接对文件保存时间和对文档加载时间的影响很小。如果你觉得你的wiki不需要反向链接,你可以放心地将其禁用,修改xwiki.cfg如下:

xwiki.backlinks=0

版本控制

任何wiki系统的主要特点,版本控制大大影响了数据库的大小和文档更新时间。如果您确定您的wiki并不需要保留所有的变化轨迹或者永远不需要恢复的文件到以前的版本,那么您修改xwiki.cfg屏蔽版本控制:

xwiki.store.versioning=0

自定义映射

在某些情况下,你可能不想依靠XWiki的通用数据库模式存储XClass数据,而你想提供自己的优化过的表。对于这些使用情况下,你可以使用自定义映射 

LDAP

禁用LDAP子组搜索

默认情况下加载LDAP组时,每个成员搜索和加载的时候要弄清楚它是否是一个组或者不是(再加载子组成员)。从7.2开始,如果你知道在你的LDAP没有子组,那么可以禁用它加快了速度。
可以修改 xwiki.cfg配置文件中的xwiki.authentication.ldap.group_sync_resolve_subgroups

性能树

从7.1开始可以通过debug模式直接获得每一个请求的时间花费,以树的方式呈现

废弃

监控插件

面向开发者的功能,XWiki可以监控其自己的代码,报告一个请求中激活每个子组件的时间。虽然监管代码不费时,但它增加了内存消耗,而创建/开始/停止/日志/销毁调用分布各地的代码,你需要通过禁用这个功能节省了大量的方法调用。你可以通过设置xwiki.cfg:

xwiki.monitor=0

1.0 使用velocity渲染文件内容缓存

在文件渲染后您可以添加以下内容。注意,每当文件内容改变会被刷新,所以它是非常安全的添加较长的缓存持续时间的不包含从wiki获得数据的所有文档。例如缓存60秒,如下:

$context.setCacheDuration(60)

从1.5M2开始,您可以在xwiki.cfg为所有页面设置默认渲染缓存持续时间:

## cache all rendered documents for one hour
xwiki.rendering.defaultCacheDuration=3600

设置默认缓存持续时间为一个较大的值,并手动禁用动态页面会加快wiki缓存,因为渲染是最耗费时间的过程之一

XWiki语法1.0(wiki语法)

如果您使用的是XWiki 1.0语法,不打算使用所有的标记功能,如删除线过滤器,自动HTTP链接过滤器,SVG,Laszlo 或style宏,你可以在 xwiki-core-*.jar/META-INF/services/com.xpn.xwiki.render.*禁用它们。

现在,这不会有任何影响,如果你使用的是其他的语法,就像XWiki 2.x语法 

  • 31
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 27
    评论
评论 27
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lovelife110

你的鼓励是我创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值