简体   繁体   English

如何在Lucene中将FSdirectory索引文件加载为RAM目录?

[英]How to load an FSdirectory index file as a RAMdirectory in Lucene?

I have an index file in hard as FSdirectory which size is about 2GB. 我有一个硬盘索引文件作为FS目录,大小约为2GB。 I want to load it in ram to have a better search speed. 我想在ram中加载它以获得更好的搜索速度。 I use the code behind: 我使用后面的代码:

Directory dic=new RAMDirectory(FSDirectory.open(new File("file path")), IOContext.DEFAULT);

But I'm not sure if it work. 但我不确定它是否有效。 Do anyone know that it work or not? 有谁知道它的工作与否? Any other way better than this on? 还有什么方法比这更好吗?

I'll be glad of any suggestion.Thanks. 我会很高兴有任何建议。谢谢。

Yes you can construct RAMDirectory like that but it's strongly discouraged in your case. 是的,您可以像这样构建RAMDirectory,但在您的情况下强烈建议不要这样做。 RAMDirectory is not designed to be used with large data set (more than 100MB). RAMDirectory不适用于大型数据集(超过100MB)。 It will be very GC intensive, long to construct and consume precious JAVA Heap space. 它将非常GC密集,长期构建和消耗宝贵的JAVA堆空间。

If you have perf issues please make sure that you follow all the guidelines descibed in this lucene FAQ 如果您有性能问题,请确保遵循此lucene常见问题解答中描述的所有指导原则

Don't forget that to get descent search speed the os needs to cache some part of the index into memory. 不要忘记,为了获得下降搜索速度,操作系统需要将索引的某些部分缓存到内存中。 In order to do that you must let some free mem available to the OS. 为此,您必须为操作系统提供一些免费的mem。 If you have 16Gb of physical RAM and a 8gb index you should configure the jvm Xmx with 8g. 如果您有16Gb的物理RAM和8gb索引,则应该将jvm Xmx配置为8g。 A nice linux tool to check mem is htop, it will print RAM used for process as green (your heap space) and RAM used as filecache as yellow (the index data). 检查mem的一个不错的linux工具是htop,它会将用于进程的RAM打印为绿色(您的堆空间),将RAM用作文件缓存作为黄色(索引数据)。

Some developpers perform warm up queries at application startup to prevent the first user from being stuck few seconds while the index gets loaded by os filecache. 一些开发人员在应用程序启动时执行预热查询,以防止第一个用户在索引由os filecache加载时被卡住几秒钟。

Then if you still think you can get better perf you can try some tricks with RAMfs. 然后,如果你仍然认为你可以获得更好的性能,你可以尝试一些RAMfs的技巧。 But I doubt that you can get better performances than a well tuned os and jvm with MMapDirectory. 但是我怀疑你可以获得比MMapDirectory更好的表现更好的表现和jvm。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM