Skip to content

Apache Lucene open-source search software

Merged revision(s) 1305816 from lucene/dev/branches/branch_3x: LUCENE-3926: Improve documentation of RAMDirectory

Uwe Schindlera79cbb574670
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 7e12459bfa2..a3a4d60514e 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -994,7 +994,20 @@ Optimizations
Documentation
-* LUCENE-3597: Fixed incorrect grouping documentation. (Martijn van Groningen, Robert Muir)
+* LUCENE-3597: Fixed incorrect grouping documentation. (Martijn van Groningen,
+ Robert Muir)
+
+* LUCENE-3926: Improve documentation of RAMDirectory, because this
+ class is not intended to work with huge indexes. Everything beyond
+ several hundred megabytes will waste resources (GC cycles), because
+ it uses an internal buffer size of 1024 bytes, producing millions of
+ byte[1024] arrays. This class is optimized for small memory-resident
+ indexes. It also has bad concurrency on multithreaded environments.
+ It is recommended to materialize large indexes on disk and use
+ MMapDirectory, which is a high-performance directory implementation
+ working directly on the file system cache of the operating system,
+ so copying data to Java heap space is not useful. (Uwe Schindler,
+ Mike McCandless, Robert Muir)
Build
diff --git a/lucene/core/src/java/org/apache/lucene/store/RAMDirectory.java b/lucene/core/src/java/org/apache/lucene/store/RAMDirectory.java
index 2c9ddc5b5ec..8e9a78b7a1f 100644
--- a/lucene/core/src/java/org/apache/lucene/store/RAMDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/RAMDirectory.java
@@ -32,6 +32,18 @@ import java.util.concurrent.atomic.AtomicLong;
* A memory-resident {@link Directory} implementation. Locking
* implementation is by default the {@link SingleInstanceLockFactory}
* but can be changed with {@link #setLockFactory}.
+ *
+ * <p><b>Warning:</b> This class is not intended to work with huge
+ * indexes. Everything beyond several hundred megabytes will waste
+ * resources (GC cycles), because it uses an internal buffer size
+ * of 1024 bytes, producing millions of {@code byte[1024]} arrays.
+ * This class is optimized for small memory-resident indexes.
+ * It also has bad concurrency on multithreaded environments.
+ *
+ * <p>It is recommended to materialize large indexes on disk and use
+ * {@link MMapDirectory}, which is a high-performance directory
+ * implementation working directly on the file system cache of the
+ * operating system, so copying data to Java heap space is not useful.
*/
public class RAMDirectory extends Directory {
protected final Map<String,RAMFile> fileMap = new ConcurrentHashMap<String,RAMFile>();
@@ -54,10 +66,20 @@ public class RAMDirectory extends Directory {
* Creates a new <code>RAMDirectory</code> instance from a different
* <code>Directory</code> implementation. This can be used to load
* a disk-based index into memory.
- * <P>
- * This should be used only with indices that can fit into memory.
- * <P>
- * Note that the resulting <code>RAMDirectory</code> instance is fully
+ *
+ * <p><b>Warning:</b> This class is not intended to work with huge
+ * indexes. Everything beyond several hundred megabytes will waste
+ * resources (GC cycles), because it uses an internal buffer size
+ * of 1024 bytes, producing millions of {@code byte[1024]} arrays.
+ * This class is optimized for small memory-resident indexes.
+ * It also has bad concurrency on multithreaded environments.
+ *
+ * <p>For disk-based indexes it is recommended to use
+ * {@link MMapDirectory}, which is a high-performance directory
+ * implementation working directly on the file system cache of the
+ * operating system, so copying data to Java heap space is not useful.
+ *
+ * <p>Note that the resulting <code>RAMDirectory</code> instance is fully
* independent from the original <code>Directory</code> (it is a
* complete copy). Any subsequent changes to the
* original <code>Directory</code> will not be visible in the