solr的软提交(softcommit)与硬提交(commit)的区别[看完这篇就懂了]

(一)数据在存入solr时,会有几种提交方式,这里主要记录下硬提交与软提交这两种方式:

硬提交(commit):

这种提交会把文档立即持久化到磁盘,并可以让你能立马查询到它,因为它会开启一个新的searcher,但是它缺点很明显,就是很耗性能,并会阻塞到提交任务完成.简单的理解就是它是把数据一条一条的插入solr中,效率较慢,耗费资源较多.

软提交(softcommit):

这种提交不会立即把数据写到磁盘,但它可以使你能立即查询到它,软提交的方式可以把较多的一批数据同时插入到solr中,效率较快.

上面简单地理解下两者的概念差别,具体的可以查看官方文档:这里截取部分内容:

================================================================================

A commit operation makes index changes visible to new search requests. A hard commit also calls fsync on the index files to ensure they have been flushed to stable storage and no data loss will result from a power failure.

A soft commit is much faster since it only makes index changes visible and does not fsync index files or write a new index descriptor. If the JVM crashes or there is a loss of power, changes that occurred after the last hard commit will be lost. Search collections that have near-real-time requirements (that want index changes to be quickly visible to searches) will want to soft commit often but hard commit less frequently.

=================================================================================

  • 软提交: solrService.commit(true,true,true)
  • 硬提交: solrService.commit()

里面的参数解释如下:

  • waitFlush = "true" | "false" — default is true — block until index changes are flushed to disk Solr1.4 At least in Solr 1.4 and later (perhaps earlier as well), this command has no affect.
  • waitSearcher = "true" | "false" — default is true — block until a new searcher is opened and registered as the main query searcher, making the changes visible.
  • softCommit = "true" | "false" — default is false — perform a soft commit - this will refresh the 'view' of the index in a more performant manner, but without "on-disk" guarantees

软提交和硬提交前两个参数都采用默认true,第三个参数便是开启软提交还是硬提交,硬提交默认为false.

(二)上面区分了软硬提交,接下来说一下另外两个:<autoCommit> 和<autoSoftCommit>

这是在solrconfig.xml里面的配置信息<autoCommit>:自动硬提交  <autoSoftCommit>自动软提交

 <autoCommit> 
       <maxTime>${solr.autoCommit.maxTime:30000}</maxTime> 
       <openSearcher>false</openSearcher> 
 </autoCommit>

注: <openSearcher> 是否打开新的搜索,当为true会加大消耗的性能,根据实际情况选择

<autoSoftCommit> 
  <maxTime>${solr.autoSoftCommit.maxTime:5000}</maxTime> 
</autoSoftCommit>

总结接到这了,我也是看了很多的文章,把一些比较重要的内容总结一下,以供大家和自己参考和学习.

参考文档:

https://blog.csdn.net/aiyueqingfeng/article/details/51803590

https://blog.csdn.net/htw2012/article/details/17136781

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值