设为首页 收藏本站
查看: 730|回复: 0

[经验分享] Lucene/Solr Dev 2 : Indexing and Searching Simultaneously

[复制链接]

尚未签到

发表于 2016-12-17 06:11:11 | 显示全部楼层 |阅读模式
  Abstract
  First i give my conclusion: Lucene can index and search simultaneously, what's more, we can only index one document and then we can search this document at once. Sounds cool, but to do like this is necessary or useful? The answer is NO.  To account for the detail reason, we should first delve into Lucene Buffering and Flushing mechanism.
  Lucene Buffering and Flushing
  
DSC0000.png
 

  As shown in the above figure, when new Documents are add to a Lucene Index, or deletions are pending, they're initially buffered in memory instead of being immediately written to the disk. This is done for performance, to minimize disk IO. Periodcally, this changes are flushed to the index Directory as a new segment. The flush can be triggered by IndexWriter according to the below three criteria:
  1. To flush when the buffer has consumed more then a pre-set amount of RAM, we can use the below method to set the buffer size:

IndexWriter writer = getWriter();
writer.setRAMBufferSizeMB(10);
  2. If your IndexWriter called the setMaxBufferedDocs() Method, the flush will be triggered when the specific number of Documents has added,like the below code:

IndexWriter writer = getWriter();
writer.setMaxBufferedDocs(100);
  3. Like the Criteria 2 if your IndexWriter called setMaxBufferedDeleteTerms():

IndexWriter writer = getWriter();
writer.setMaxBufferedDeleteTerms(100);
  In addition, by deffault , IndexWriter flushs only when RAM usage is 16MB.
  By now you may be have a question, while the flush has be triggered and the IndexReader can Search this flushed Document? actually, when a flush occurs, the writer creates new segment and deletion files in the Directory. However,these files are neither visible nor usable to a newly opened IndexReader until the writer commits the changes and the reader is reopened. It’s important to understand this difference. Flushing is done to free up memory consumed by buffered changes to the index, whereas committing is done to make all changes(buffered or already flushed) persistent and visible in the index. This means IndexReader always sees the starting state of the index (when IndexWriter was opened), until the writer commits.
  Turn to this Articles Topic,if you want to index and search simultaneously, or even if you want to index one document and then search this document at once, your IndexWriter must call commit() method when your IndexWriter only add a Document. To continue explain Lucene index and search simultaneously, we should delve into Lucene index commits.
  Lucene index commits
  At the begin of this article, we do not need to commit frequently during a indexing, because commit is a costly operation, and doing so frequently will slow down your indexing throughput.
  I have made a experiment, indexing 100MB resource File that means adding almost 68768 Dcuments to index directory, and i got the following results
  1. if we can not call IndexWriter's commit() Method during the whole indexing process, it only need25 seconds
  2. if we call commit() method frequemtly,  i called the commit() after every added a Documment to index directory, means i do commit 68768 times during indexing the same 100 MB resource file, and the indexing time ismore than 2 hours. it is obvious that do index commit more frequent is not a good choice.
  3. if we call commit method while 5000 Documents has added to the index directory, we also indexing 100 MB resouece file, add 68768 Documents. in this condition, we call commit method 13 times, and the final indexing time is  31 seconds.
  4. and if we call commit method while 500 Documents has added, the final indexing time is 46 seconds
  5. and while 100 Documents has added the indexing time is 115 seconds.
  To sum up this results to a table, it might more strightforward:

indexing 100MB resource file, adding 68768 documents to index directory
call commit frequencydo commit timesindexing time 
never025 seconds 
5000 documents has added1331 seconds 
500 documents has added13746 seconds 
100 documents has added687115 seconds 
50 documents has added1375210 seconds 
1 document has added68768more than 2 hours 
  through the table we can get the conclusion.
  Conclusion
  Lucene indexing and searching simultaneous is possible, only has the IndexWriter's commit() method called and the IndexReader is reopened. in order to keep lucene performance, we should not do commit more frequently, the best choice is more than 500 Documents has added to the index directory we call the commit method. 
  PS : for some reason, the most is my english is not so proficient, so some of my viewpoint is not state clearly, Welcome your comments to made the view more clearly.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-315182-1-1.html 上篇帖子: solr搭建第二步 下篇帖子: solr配置文件schema.xml需要注意的细节
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表