concept thread in category lucene

appears as: threads, thread
Lucene in Action, Second Edition

This is an excerpt from Manning's book Lucene in Action, Second Edition.

Table 2.2. Lucene’s several core Directory implementations

Directory

Description

SimpleFSDirectory A simplistic Directory that stores files in the file system, using java.io.* APIs. It doesn’t scale well with many threads.
NIOFSDirectory A Directory that stores files in the file system, using java.nio.* APIs. This does scale well with threads on all platforms except Microsoft Windows, due to a longstanding issue with Sun’s Java Runtime Environment (JRE).
MMapDirectory A Directory that uses memory-mapped I/O to access files. This is a good choice on 64-bit JREs, or on 32-bit JREs where the size of the index is relatively small.
RAMDirectory A Directory that stores all files in RAM.
FileSwitchDirectory A Directory that takes two directories in, and switches between these directories based on file extension.

Lucene has great out-of-the-box performance, but for some demanding applications, this is still not good enough. Fear not! There are many fun ways to tune for performance. Adding threads to your application is often effective, but the added complexity can make it tricky. We’ll show you some simple drop-in classes that hide this complexity. Most likely you can tune Lucene to get the performance you need. We’ll explore using hands-on examples for measuring performance.

Listing 11.2. Indexing with threads, compound, extra RAM, and larger mergeFactor

The full source code is shown in listing 11.3. Specify how many threads to use, as well as the size of the queue, when you instantiate the class. Test different values to find the sweet spot for your application, but a good rule of thumb for numThreads is one plus the number of CPU cores in your computer that you’d like to consume on indexing, and then 4*numThreads for maxQueueSize. As you use more threads for indexing, you’ll find that a larger RAM buffer size should help even more, so be sure to test different combinations of number of threads and RAM buffer size to reach your best performance. Check process monitor tools, like top or ps on Unix, Task Manager on Windows, or Activity Monitor on Mac OS X to verify that CPU utilization is near 100 percent.