gpt4 book ai didi

solr - 如何提高 MapReduce 中 Solr 索引构建时间的速度

转载 作者:行者123 更新时间:2023-12-05 03:12:19 31 4
gpt4 key购买 nike

我编写了一个 mapreduce 作业来为我的数据生成 solr 索引。我是在reducer里面生成的。但是速度真的很慢。有什么办法可以提高速度吗?下面列出的代码是 reducer 内部的代码。是不是我的程序有什么问题,或者有什么办法可以提高生成索引的速度吗?

private SolrClient solr;
private UpdateResponse response;
private SolrInputDocument document;

@Override
public void reduce(Text inputKey, Iterable<Text> values, Context context) throws IOException, InterruptedException {

//process the values...
document = new SolrInputDocument();
document.addField("id", hid+"#"+refid);
document.addField();
.....
response = solr.add(document);
solr.commit();
}

public void setup(Context context) {
if(solrServerMode.equals("Cloud")){
solr = new CloudSolrClient(solrServerPath);
((CloudSolrClient) solr).setDefaultCollection("gettingstarted");
}
else if(solrServerMode.equals("Local")){
solr = new HttpSolrClient(solrServerPath);
}
}

@Override
public void cleanup(Context context) {
solr.close();
}

编辑一:有一个可疑的部分,可能导致速度很慢。如图所示,我刚刚更新了46,205个文件,但版本非常高。 enter image description here

最佳答案

执行更少或只执行一次提交

您在每个文档之后执行一次提交。这很昂贵并且会减慢索引过程。如果您的文档在索引过程中不需要对搜索可见,我建议按如下方式重写。

@Override
public void reduce(Text inputKey, Iterable<Text> values, Context context) throws IOException, InterruptedException {
// .....
response = solr.add(document);
}

@Override
public void cleanup(Context context) {
solr.commit();
solr.close();
}

请考虑这将在最后提交。只要这样,您将无法通过搜索找到文档。

调整自动提交设置

另一个起作用的因素是 the <autocommit> settings你可以调整你的 solrconfig.xml。如果达到未提交的待处理文档的特定阈值或达到未提交的待处理文档的特定时间阈值,这些将自动执行提交。增加这些值会进一步加快索引速度。

<autoCommit>
<maxDocs>10000</maxDocs>
<maxTime>1000</maxTime>
<openSearcher>false</openSearcher>
</autoCommit>

关于solr - 如何提高 MapReduce 中 Solr 索引构建时间的速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34078211/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com