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 的
NIOFSDirectory 的
NIOFSDirectory + Http11NioProtocol(tomcat)
吞吐量一一提高,关于 jmeter 测试报告的说明请看:http://blog.chenlb.com/2009/03/jmeter-report-explain.html