views:

247

answers:

2

Hi,

I need to improve performance of my Lucene search query. Can I use RAMDirectory?Does it optimize performance?Is there any index size limit for this? I would appreciate if someone could list pros and cons of using a RAMDirectory.

Thanks.

+2  A: 

A RAMDirectory is faster, but doesn't get written to the disk. It only exists as long as your program is running, and has to be created from scratch every time your program runs.

If your index is small enough to fit comfortably into RAM, and you don't update it frequently, you can maintain an index on the disk and then create a RAMDirectory from it using the RAMDirectory(Directory dir) constructor. Querying that should then be faster than querying the one on disk, once you've paid the penalty of loading it up. But do measure the difference - if the index can fit into memory as a RAMDirectory, then it can fit in the disk cache as well, so you might not see much difference.

RichieHindle
Thanks for ur inputs..may i know how small is "small enough"?
I would imagine smaller than your available physical RAM.
Dark Falcon
+1  A: 

You should profile the use of RAMDirectory. At least in Linux, using RAMDirectory is not any faster than using the default FSDirectory, due to the way the OS buffers I/O.

See

http://lucene.grantingersoll.com/2009/09/22/assumptions-in-apache-lucene-and-solr-and-pretty-much-everything-else-considered-harmful/

bajafresh4life