用html5做课程教学网站,个人在百度上发广告怎么发,wap和app,企业建设网站专业服务简介 该文章基于业务需求背景#xff0c;因场景需求进行参数调优#xff0c;下文会尽可能针对段合并策略#xff08;SegmentMergePolicy#xff09;的全参数进行说明。
主要介绍TieredMergePolicy#xff0c;它是Lucene4以后的默认段的合并策略#xff0c;之前采用的合并…
简介 该文章基于业务需求背景因场景需求进行参数调优下文会尽可能针对段合并策略SegmentMergePolicy的全参数进行说明。
主要介绍TieredMergePolicy它是Lucene4以后的默认段的合并策略之前采用的合并策略为LogMergePolicy建议自行熟悉LogMergePolicy后再了解TieredMergePolicy这样对于两种段合并策略的优缺点就一目了然后续即可根据不同业务使用对应的策略下面对两种策略的差异做一个简单总结
LogMergePolicy总是合并相邻的段文件合并相邻的段文件Adjacent Segment描述的是对于IndexWriter提供的段集LogMergePolicy会选取连续的部分或全部段集区间来生成一个待合并段集TieredMergePolicy中会先对IndexWriter提供的段集进行排序然后在排序后的段集中选取部分可能不连续段来生成一个待合并段集即非相邻的段文件Non-adjacent Segment。
一句话描述TieredMergePolicy找出大小接近且最优的段集。下面对该概括进行详细分析。频繁且大量的段合并会造成进程CPU飙升。
TieredMergePolicy TieredMergePolicy的一些参数 合并类型MERGE_TYPE MERGE_TYPE中描述了IndexWriter在不同状态下调用合并策略的三种类型
NATURALIndexWriter对缩影执行变更操作后调用合并策略FORCE_MERGEIndexWriter需要需要将索引中包含所有的段集数量total set of segments in the index合并为指定数量FORCE_MERGE_DELETESIndexWriter需要将索引中包含所有的段中的被删除文件进行抹去expunge操作。
三中类型触发过程处理逻辑一致下文仅对NATURAL进行介绍。
maxMergeAtOnce可配置
maxMergeAtOnce的缺省值为10描述了在NATURAL类型下执行一次合并操作最多包含的段的个数Maximum number of segments to be merged at a time during normal mergin。
segsPerTier可配置
segsPerTier的默认值为10描述了每一层层级的概念类似LogMergePolicy这里不做赘述中需要包含segsPerTier个段才允许合并例外情况就是当段集中包含的被删除的文档数量达到某个值下文会介绍就不用考虑segsPerTier中的段的个数。
mergeFactor
mergeFactor描述了执行一次合并操作最多包含的段的个数该值计算方式如下
final int mergeFactor (int) Math.min(maxMergeAtOnce, segsPerTier);
段大小SegmentSize SegmentSize描述了一个段的大小他是该段中除去被删除文档的索引信息的所有索引文件的大小的综合。
maxMergedSegmentBytes可配置
maxMergedSegmentBytes缺省值为5G它有两个用途
限制合并段集大小总量待合并的段集大小总和不能超过该值限制大段Segment with huge size合并该值的一半即maxMergedSegmentBytes / 2.0用来描述某个段如果大小超过就不参与合并限制大段还要同时满足被删除文档的条件在下文会介绍
另外值得一提的是该值为内存杀手。内存有限的情况下该值为必配项5G的merge行为在非受控堆外将内存撑满如下pmap图可见一般 hitTooLarge
hitTooLarge是一个布尔值当OneMerge中所有段的大小总和接近maxMergedSegmentByteshitTooLarge会被置为true该值影响OneMerge的打分。
deletesPctAllowed可配置
deletesPctAllowed的默认值为33百分比自定义该值时允许的值域为[2050]该值有两个用途
限制大段合并需要满足该段的SegmentSize≥maxMergedSegmentBytes/2.0并且满足段集中的被删除文档的索引信息大小占总索引文件大小的比例totalDelPct≤deletedPctAllowed或该段中被删除文档的索引信息大小占段中索引文件大小的比例segDelPct≤deletesPctAllowed如下判断逻辑 (SegmentSize (maxMergedSegmentBytes / 2)) (totalDelPct deletesPctAllowed || segDelPct deletesPctAllowed) 计算allowedDelCount计算公式如下其中totalMaxDoc描述了段集中除去被删除文档的文档数量总和allowedDelCount的介绍见下文 int allowedDelCount (int) (deletesPctAllowed * totalMaxDoc / 100);
allowedSegCount、allowedDelCount
allowedSegCount该值描述了段集内每个段的大小SegmentSize是否比较接近segments of approximately equal size根据当前索引大小来估算当前索引中应该有多少个段如果实际的段个数小于估算值那么说明索引中的段不满足差不多都相同approximately equal size那么就不会选出OneMerge这里不赘述该名词含义见LogMergePolicy。allowedSegCount的最小值为segsPerTierallowedSegCount的值越大索引中会堆积更多的段说明IndexWriter提交的段集不包含大段中最大的段的MaxSegmentSize跟最小的段MinSegmentSize相差越大或者最小的段MinSegmentSize占段集总大小totalSegmentSize的占比特别低一个原因在于有些flush()或者commit()的文档数相差太大另一个原因是可配置参数floorSegmentBytes值设置的太小。allowedDelCount描述了IndexWriter提交的段集不包含大段中包含的被删除文档数量在NATURAL类型下当某个段集中的成员个数不满足allowedSegCount时但是如果该段集不包含大段中包含的被删除的文档数量大于allowedDelCount那么该段集还可以继续参与剩余的合并策略的处理因为执行段的合并的一个非常重要的目的就是干掉被删除的文档号否则就该段集此次不生成一个oneMerge。
floorSegmentBytes可配置重要
floorSegmentBytes缺省值为2MB(2 * 1024 * 1024)该值描述了段的大小segmentSize小于floorSegmentBytes的段他们的segmentSize都当做floorSegmentBytes。
源码原文Segments smaller than this are rounded up to this size, ie treated as equal (floor) size for merge selection
使计算出来的allowedSegCount较小这样能尽快的将小段tiny Segment合并另外该值还会影响OneMerge的打分(下文会介绍)。
设置了不合适的floorSegmentBytes后会发生以下的问题
floorSegmentBytes的值太小导致allowedSegCount很大allowedSegCountn*segsPerTierm 0≤m≤segsPerTier , n≥1特别是段集中最小的段MinSegmentSize占段集总大小totalSegmentSize的占比特别低最终使得索引中一段时间存在大量的小段因为段集的总数小于等于allowedSegCount是不会参与段合并的如果不满足allowedDelCount的条件。源码中解释floorSegmentBytes的用途的原文为 This is to prevent frequent flushing of tiny segments from allowing a long tail in the indexfloorSegmentBytes的值太大导致allowedSegCount很小最小值为segsPerTier即较大的段合并可能更频繁段越大合并开销(合并时间线程频繁占用)越大在后面的文章中会介绍索引文件的合并。
SegmentSize多小为小段tiny Segment这个定义取决于不同的业务如果某个业务中认为小于TinySegmentSize的段都为小段那么floorSegmentBytes的值大于TinySegmentSize即可。
段合并流程图 详细处理逻辑可以通过阅读Lucene源码得到org.apache.lucene.index.TieredMergePolicy#findMerges如下代码段为入口
public MergeSpecification findMerges(MergeTrigger mergeTrigger, SegmentInfos infos, MergeContext mergeContext) throws IOException {final SetSegmentCommitInfo merging mergeContext.getMergingSegments();// Compute total index bytes print details about the indexlong totIndexBytes 0;long minSegmentBytes Long.MAX_VALUE;int totalDelDocs 0;int totalMaxDoc 0;long mergingBytes 0;ListSegmentSizeAndDocs sortedInfos getSortedBySegmentSize(infos, mergeContext);IteratorSegmentSizeAndDocs iter sortedInfos.iterator();while (iter.hasNext()) {SegmentSizeAndDocs segSizeDocs iter.next();final long segBytes segSizeDocs.sizeInBytes;if (verbose(mergeContext)) {String extra merging.contains(segSizeDocs.segInfo) ? [merging] : ;if (segBytes maxMergedSegmentBytes) {extra [skip: too large];} else if (segBytes floorSegmentBytes) {extra [floored];}message( seg segString(mergeContext, Collections.singleton(segSizeDocs.segInfo)) size String.format(Locale.ROOT, %.3f, segBytes / 1024 / 1024.) MB extra, mergeContext);}if (merging.contains(segSizeDocs.segInfo)) {mergingBytes segSizeDocs.sizeInBytes;iter.remove();// if this segment is merging, then its deletes are being reclaimed already.// only count live docs in the total max doctotalMaxDoc segSizeDocs.maxDoc - segSizeDocs.delCount;} else {totalDelDocs segSizeDocs.delCount;totalMaxDoc segSizeDocs.maxDoc;}minSegmentBytes Math.min(segBytes, minSegmentBytes);totIndexBytes segBytes;}assert totalMaxDoc 0;assert totalDelDocs 0;final double totalDelPct 100 * (double) totalDelDocs / totalMaxDoc;int allowedDelCount (int) (deletesPctAllowed * totalMaxDoc / 100);// If we have too-large segments, grace them out of the maximum segment count// If were above certain thresholds of deleted docs, we can merge very large segments.int tooBigCount 0;iter sortedInfos.iterator();// remove large segments from consideration under two conditions.// 1 Overall percent deleted docs relatively small and this segment is larger than 50% maxSegSize// 2 overall percent deleted docs large and this segment is large and has few deleted docswhile (iter.hasNext()) {SegmentSizeAndDocs segSizeDocs iter.next();double segDelPct 100 * (double) segSizeDocs.delCount / (double) segSizeDocs.maxDoc;if (segSizeDocs.sizeInBytes maxMergedSegmentBytes / 2 (totalDelPct deletesPctAllowed || segDelPct deletesPctAllowed)) {iter.remove();tooBigCount; // Just for reporting purposes.totIndexBytes - segSizeDocs.sizeInBytes;allowedDelCount - segSizeDocs.delCount;}}allowedDelCount Math.max(0, allowedDelCount);final int mergeFactor (int) Math.min(maxMergeAtOnce, segsPerTier);// Compute max allowed segments in the indexlong levelSize Math.max(minSegmentBytes, floorSegmentBytes);long bytesLeft totIndexBytes;double allowedSegCount 0;while (true) {final double segCountLevel bytesLeft / (double) levelSize;if (segCountLevel segsPerTier || levelSize maxMergedSegmentBytes) {allowedSegCount Math.ceil(segCountLevel);break;}allowedSegCount segsPerTier;bytesLeft - segsPerTier * levelSize;levelSize Math.min(maxMergedSegmentBytes, levelSize * mergeFactor);}// allowedSegCount may occasionally be less than segsPerTier// if segment sizes are below the floor sizeallowedSegCount Math.max(allowedSegCount, segsPerTier);if (verbose(mergeContext) tooBigCount 0) {message( allowedSegmentCount allowedSegCount vs count infos.size() (eligible count sortedInfos.size() ) tooBigCount tooBigCount, mergeContext);}return doFindMerges(sortedInfos, maxMergedSegmentBytes, mergeFactor, (int) allowedSegCount, allowedDelCount, MERGE_TYPE.NATURAL,mergeContext, mergingBytes maxMergedSegmentBytes);
}
文章转载自: http://www.morning.gwjnm.cn.gov.cn.gwjnm.cn http://www.morning.grzpc.cn.gov.cn.grzpc.cn http://www.morning.zwpzy.cn.gov.cn.zwpzy.cn http://www.morning.dwgcx.cn.gov.cn.dwgcx.cn http://www.morning.hxxzp.cn.gov.cn.hxxzp.cn http://www.morning.nfdty.cn.gov.cn.nfdty.cn http://www.morning.kfstq.cn.gov.cn.kfstq.cn http://www.morning.pdtjj.cn.gov.cn.pdtjj.cn http://www.morning.psxwc.cn.gov.cn.psxwc.cn http://www.morning.zphlb.cn.gov.cn.zphlb.cn http://www.morning.snygg.cn.gov.cn.snygg.cn http://www.morning.kmcby.cn.gov.cn.kmcby.cn http://www.morning.knmby.cn.gov.cn.knmby.cn http://www.morning.pdxqk.cn.gov.cn.pdxqk.cn http://www.morning.lswgs.cn.gov.cn.lswgs.cn http://www.morning.jcfdk.cn.gov.cn.jcfdk.cn http://www.morning.kpwcx.cn.gov.cn.kpwcx.cn http://www.morning.rkfgx.cn.gov.cn.rkfgx.cn http://www.morning.nmkfy.cn.gov.cn.nmkfy.cn http://www.morning.bssjz.cn.gov.cn.bssjz.cn http://www.morning.tnjkg.cn.gov.cn.tnjkg.cn http://www.morning.bhxzx.cn.gov.cn.bhxzx.cn http://www.morning.qfdyt.cn.gov.cn.qfdyt.cn http://www.morning.sfwcb.cn.gov.cn.sfwcb.cn http://www.morning.qbmpb.cn.gov.cn.qbmpb.cn http://www.morning.fqqlq.cn.gov.cn.fqqlq.cn http://www.morning.mmclj.cn.gov.cn.mmclj.cn http://www.morning.tdnbw.cn.gov.cn.tdnbw.cn http://www.morning.fkyrk.cn.gov.cn.fkyrk.cn http://www.morning.stpkz.cn.gov.cn.stpkz.cn http://www.morning.wjwfj.cn.gov.cn.wjwfj.cn http://www.morning.hpkgm.cn.gov.cn.hpkgm.cn http://www.morning.knpbr.cn.gov.cn.knpbr.cn http://www.morning.bpds.cn.gov.cn.bpds.cn http://www.morning.kfwqd.cn.gov.cn.kfwqd.cn http://www.morning.huarma.com.gov.cn.huarma.com http://www.morning.flhnd.cn.gov.cn.flhnd.cn http://www.morning.fbylq.cn.gov.cn.fbylq.cn http://www.morning.mfjfh.cn.gov.cn.mfjfh.cn http://www.morning.jcwt.cn.gov.cn.jcwt.cn http://www.morning.bynf.cn.gov.cn.bynf.cn http://www.morning.trffl.cn.gov.cn.trffl.cn http://www.morning.uycvv.cn.gov.cn.uycvv.cn http://www.morning.gskzy.cn.gov.cn.gskzy.cn http://www.morning.txysr.cn.gov.cn.txysr.cn http://www.morning.pqypt.cn.gov.cn.pqypt.cn http://www.morning.ttcmdsg.cn.gov.cn.ttcmdsg.cn http://www.morning.ptmsk.cn.gov.cn.ptmsk.cn http://www.morning.pnjsl.cn.gov.cn.pnjsl.cn http://www.morning.rsnd.cn.gov.cn.rsnd.cn http://www.morning.qkdjq.cn.gov.cn.qkdjq.cn http://www.morning.zzbwjy.cn.gov.cn.zzbwjy.cn http://www.morning.khlxd.cn.gov.cn.khlxd.cn http://www.morning.qgmwt.cn.gov.cn.qgmwt.cn http://www.morning.kwdfn.cn.gov.cn.kwdfn.cn http://www.morning.lnnc.cn.gov.cn.lnnc.cn http://www.morning.tklqs.cn.gov.cn.tklqs.cn http://www.morning.ndpzm.cn.gov.cn.ndpzm.cn http://www.morning.npmcf.cn.gov.cn.npmcf.cn http://www.morning.uycvv.cn.gov.cn.uycvv.cn http://www.morning.sbwr.cn.gov.cn.sbwr.cn http://www.morning.dnydy.cn.gov.cn.dnydy.cn http://www.morning.ssfq.cn.gov.cn.ssfq.cn http://www.morning.ktpzb.cn.gov.cn.ktpzb.cn http://www.morning.czqqy.cn.gov.cn.czqqy.cn http://www.morning.ndhxn.cn.gov.cn.ndhxn.cn http://www.morning.czlzn.cn.gov.cn.czlzn.cn http://www.morning.fqnql.cn.gov.cn.fqnql.cn http://www.morning.hxycm.cn.gov.cn.hxycm.cn http://www.morning.cknsx.cn.gov.cn.cknsx.cn http://www.morning.gqbtw.cn.gov.cn.gqbtw.cn http://www.morning.jfjbl.cn.gov.cn.jfjbl.cn http://www.morning.nlkm.cn.gov.cn.nlkm.cn http://www.morning.iqcge.com.gov.cn.iqcge.com http://www.morning.27asw.cn.gov.cn.27asw.cn http://www.morning.hxgly.cn.gov.cn.hxgly.cn http://www.morning.ryxyz.cn.gov.cn.ryxyz.cn http://www.morning.syrzl.cn.gov.cn.syrzl.cn http://www.morning.nqdkx.cn.gov.cn.nqdkx.cn http://www.morning.hdrrk.cn.gov.cn.hdrrk.cn