这与这个问题基本相同,但没有有用的答案,情况略有不同:
我们在 Windows 2008 R2 上运行 SOLR 5.5.0,JDK 版本为 1.8.0_77-b03。当运行我们的索引进程时,运行 SOLR 的 java 进程有一个私有(private)工作集,最终使用了机器上的所有 8 GB 内存。
我们正在使用我们使用 SOLRJ 客户端编写的 Spring Batch Starter 流程对 3M+ 文档进行索引。这是对我们收集的文档进行索引的代码:
log.info("Adding " + docList.size() + " documents to Solr index");
if(docList.size() == 0) {
log.warn("Was asked to index 0 records, but input size was " + items.size());
} else {
log.debug("Splitting list of size " + docList.size() + " into manageable chunks of " + batchCommitSize);
List<List<SolrInputDocument>> partitionedList = Lists.partition(docList, batchCommitSize);
SolrClient solrClient = (SolrClient) applicationContext.getBean("solrClient");
for (List<SolrInputDocument> chewableChunk : partitionedList) {
solrClient.add(chewableChunk);
solrClient.commit();
log.info(chewableChunk.size() + " documents committed.");
}
log.info("Finished batch indexing of " + docList.size() + " documents.");
}
SOLRJ 客户端的 Spring 配置:
@Value("${code.search.num.solr.threads}")
private int numSolrThreads;
@Bean(destroyMethod = "close")
public ConcurrentUpdateSolrClient solrClient() {
return new ConcurrentUpdateSolrClient(solrHost, 100, numSolrThreads);
}
//code.search.num.solr.threads=25
这是我们的架构定义。它真的很长,所以我只是剪切并粘贴了带有我们的字段定义的部分。如果需要的话我可以上传更多。大部分内容是从教程中的示例配置中复制的。
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<field name="_version_" type="long" indexed="true" stored="true"/>
<field name="_root_" type="string" indexed="true" stored="false"/>
<field name="_text_" type="text_general" indexed="true" stored="false" multiValued="true"/>
<copyField source="*" dest="_text_"/>
<field name="fileName" type="string" indexed="true" stored="true" required="true"/>
<field name="projectName" type="string" indexed="true" stored="true" required="true"/>
<field name="lastCommitAuthor" type="string" indexed="true" stored="true"/>
<field name="vcsUrl" type="string" indexed="true" stored="true"/>
<field name="teamCityUrl" type="string" indexed="true" stored="true"/>
<field name="jenkinsUrl" type="string" indexed="true" stored="true"/>
<field name="content" type="text_general" indexed="true" stored="true" required="true"/>
<field name="relativePath" type="string" indexed="true" stored="true" required="true"/>
<!-- Field to use to determine and enforce document uniqueness.
Unless this field is marked with required="false", it will be a required field
-->
<uniqueKey>id</uniqueKey>
上一个问题表明内存映射文件可能是罪魁祸首,但我们一直无法找到关闭它的方法。我们还尝试在每次提交时关闭并重新创建客户端,
有什么方法可以减少索引时 SOLR 使用的内存量吗?
最佳答案
我知道如何关闭 mmapcache
。在 solrConfig.xml
中搜索 directoryFactory
并将现有标记替换为下面给出的标记。
这将关闭 Mmapped 文件:
<directoryFactory name="DirectoryFactory"
class="${solr.directoryFactory:solr.SimpleFSDirectoryFactory.}"/>
由于此更改,您将无法进行接近实时的搜索。
关于java - SOLR 使用过多内存(第 2 部分),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36942515/