lucene/solr FSDirectory NIOFSDirectory 性能测试对比与Http11NioProtocol

原文出处:http://blog.chenlb.com/2009/05/lucene-solr-fsdirectory-niofsdirectory-performance-and-http11nioprotocol.html

lucene 2.4 开始有一个 NIOFSDirectory 实现,使用 java.nio's FileChannel 读取文件。官方说:在大多数非 windows 平台下,多个线程共用单个 searcher 比 FSDirectory(在同一时刻只能一个线程使用 searcher)可以提高查询的吞吐量。

lucene 2.4 的 CHANGE.TXT 说明:

21. LUCENE-753: Added new Directory implementation
org.apache.lucene.store.NIOFSDirectory, which uses java.nio's
FileChannel to do file reads. On most non-Windows platforms, with
many threads sharing a single searcher, this may yield sizable
improvement to query throughput when compared to FSDirectory,
which only allows a single thread to read from an open file at a
time. (Jason Rutherglen via Mike McCandless)
下面来测试下 NIOFSDirectory 能带来多少的提高,在solr 1.3里测试。在基本相同情况下,分别对 FSDirectory 、NIOFSDirectory 、NIOFSDirectory + Http11NioProtocol(tomcat)进行测试。用 jmeter 开100个线程的测试结果:

FSDirectory 的


FSDirectory,点击放大
NIOFSDirectory 的

NIOFSDirectory ,点击放大
NIOFSDirectory + Http11NioProtocol(tomcat)

NIOFSDirectory + Http11NioProtocol(tomcat),点击放大
吞吐量一一提高,关于 jmeter 测试报告的说明请看:http://blog.chenlb.com/2009/03/jmeter-report-explain.html
单纯从数字上看,NIOFSDirectory 比 FSDirectory 提高了 (80.7-67.2)/67.2=20%,并且平均的响应时间也有提高,提高了:1313-1086=227ms。效果还是不错的。使用 Http11NioProtocol(tomcat)可以进一步地提高吞吐量。

延伸:

1、在 lucene/solr 中使用 NIOFSDirectory ,因程序或 solr 编写代码时是用 FSDirectory ,很难对修改代码来指定使用 NIOFSDirectory ,幸好 lucene 作者们已经考虑到这个问题,可以用系统属性(System property) org.apache.lucene.FSDirectory.class 指定使用那个 FSDirectory,如tomcat的启动脚本 bin/startup.sh 最上面加:

JAVA_OPTS="$JAVA_OPTS -Dorg.apache.lucene.FSDirectory.class=org.apache.lucene.store.NIOFSDirectory"

export JAVA_OPTS
2、tomcat 使用 Http11NioProtocol。在conf/server.xml里修改,如下:

<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="100" connectionTimeout="10000" redirectPort="8443"
enableLookups="false" minSpareThreads="16" maxSpareThreads="64" acceptCount="0" debug="0"
useURIValidationHack="false" URIEncoding="UTF-8"/>
注意:官方不推荐在 windows 开台下用 NIOFSDirectory ,因为 windows 下 java 的 NIO 有个 bug:http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6265734
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值