solr的三種提交方式

三種solr提交索引的方式

1. commit

通過api直接commit,這樣性能比較差,在我測試下,平均每條commit600ms

HttpSolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr/dtrace");

SolrInputDocument doc1 = new SolrInputDocument();

doc1.addField("id", i);

solrServer.add(doc1);

solrServer.commit();

 

2. AutoCommit

參考:http://wiki.apache.org/solr/SolrConfigXml

autoCommit一般的配置如下:

 

Xml代碼  收藏代碼
  1. <updateHandler class="solr.DirectUpdateHandler2">  
  2.       <autoCommit>  
  3.                <maxTime>2000</maxTime>  
  4.               <openSearcher>false</openSearcher>  
  5.       </autoCommit>  
  6.       <autoSoftCommit>  
  7.               <maxTime>10000</maxTime>  
  8.       </autoSoftCommit>  
  9.         <updateLog>  
  10.              <str name="dir">${solr.shard.data.dir:}</str>  
  11.         </updateLog>  
  12.    </updateHandler>   

 

4.0開始引入了autoSoftCommit和openSearcher的概念這個是什麼意思呢?

 

As of Solr 4.0, there is a new “soft commit” capability, and a new parameter for hard commits – openSearcher. Currently, there’s quite a bit of confusion about the interplay between soft and hard commit actions。

 

solr hard commit做的事情

 

1、生成一個新的tlog文件,刪除舊的tlog。

2、把內存中的索引文件fsync到磁盤,並創建一個index descriptor。這裏比較耗費機器資源。

這樣即使jvm崩潰或者宕機,也不影響這部分索引。

3、使得索引在searcher中可見。但是也需要重新打開searcher才行。

 

soft commit做的事情

1、把內存文件fsync到磁盤,但不創建index descriptor。

也就是說原索引和現在的索引還互不感知,所以如果jvm崩潰,那這部分索引就沒了。

2、可以重新打開searcher,使得新的索引可以被查找到。

 

更詳細的信息參考:http://searchhub.org/2013/08/23/understanding-transaction-logs-softcommit-and-commit-in-sorlcloud/

 

3. CommitWithin

簡單的說就是告訴solr在多少毫秒內提交,比如如果我指定<add commitWithin=10000>,將會高速solr在10s內提交我的document。用法

1.可以在add方法設置參數,比如 server.add(mySolrInputDocument, 10000);

2.

UpdateRequest req = new UpdateRequest();

req.add(mySolrInputDocument);

req.setCommitWithin(10000);

req.process(server);

發佈了27 篇原創文章 · 獲贊 17 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章