skypaladin 发表于 2016-12-16 06:15:15

三种solr提交(commit)索引的方式

三种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一般的配置如下:

<updateHandler class="solr.DirectUpdateHandler2">
<autoCommit>
<maxTime>2000</maxTime>
<openSearcher>false</openSearcher>
</autoCommit>
<autoSoftCommit>
<maxTime>10000</maxTime>
</autoSoftCommit>
<updateLog>
<str name="dir">${solr.shard.data.dir:}</str>
</updateLog>
</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);
  参考:http://wiki.apache.org/solr/CommitWithin
页: [1]
查看完整版本: 三种solr提交(commit)索引的方式