2016-04-29 245 views
0

這基本上是一樣的這個問題,但沒有有用的答案,情況略有不同:SOLR佔用內存過多(部分2)

Solr uses too much memory

我們正在運行SOLR 5.5。 0在JDK版本1.8.0_77-b03的Windows 2008 R2上。在運行我們的索引過程時,運行SOLR的java進程具有一個私有工作集,最終使用該框中的所有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使用的內存量?

+0

你爲你的Solr進程分配了多少內存? –

+0

4GB。內存選項爲-XX:+ UseG1GC^ -XX:SurvivorRatio = 4^ -XX:+ UseStringDeduplication -XX:+ AggressiveHeap' – Brad

回答

1

我知道如何關閉mmapcache。在solrConfig.xml中搜索directoryFactory並用下面給出的替換現有標籤。

這將關閉Mmapped文件:

<directoryFactory name="DirectoryFactory" 
class="${solr.directoryFactory:solr.SimpleFSDirectoryFactory.}"/> 

由於這種變化,你將無法得到近乎實時搜索。