摘要:本篇是本人对Solr的使用进行的调研,具体包括
使用DataImportHandler从数据库中近实时同步数据、测试Solr创建索引的效率、以及测试Solr的搜索效率等。
具体的搜索引擎概念、Solr搭建方法、数据库mysql使用方法,假设读者已有了基础。
1. Solr
1.1 Solr从数据库中读取数据并创建索引速度(使用DataImportHandler)
l 一次性创建索引
在JVM内存配置为256M时,建立索引至1572865时出现Java heap异常;增加JVM内存配置至512M,设置系统环境变量:JAVA_OPTS -Xms256m -Xmx512m,能成功建立2112890条(花费2m 46s)。
平均索引创建速度为:12728/s(两个string字段,长度大约为20字符)。
l 增量创建索引
注意:近实时增量索引需要写数据库服务的时间与搜索引擎服务器时间同步(数据库服务时间先于搜索引擎服务器时间才行)。
使用默认的DIH创建增量索引速度较慢(50/s~400/s),不如全索引(1W/s),因为需要从数据库中读取多遍(1、要更新的IDs;2、每1ID去数据库中重取所有列)。
故需要更改DIH增量索引程序,以全索引的方式读数据;或采取全读出的方式,一次全读出所有列,具体文件配置如下:
<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
<dataSource name="mysqlServer"
type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
batchSize="-1"
url="jdbc:mysql://192.103.101.110:3306/locationplatform"
user="lpuser"
password="jlitpassok"/>
<document>
<entity name="locatedentity" pk="id"
query="select id,time from locationplatform.locatedentity where isdelete=0 and my_date > '${dataimporter.last_index_time}'"
deletedPkQuery="select id from locationplatform.locatedentity where isdelete=1 and my_date > '${dataimporter.last_index_time}'"
deltaQuery="select -1 id"
deltaImportQuery="select id,time from locationplatform.locatedentity where isdelete=0 and my_date > '${dataimporter.last_index_time}'">
<field column="id" name="id"/>
<field column="time" name="time"/>
</entity>
</document>
</dataConfig>
|
通过这样的配置可以达到增量索引9000/s(两个string字段)(数据库里对时间建立索引,对这里的性能影响不大)。
l 注意:作者不推荐使用DataImportHandler,有其它更好更方便的实现可以使用。
1.2 Solr创建索引效率
-
ConcurrentUpdateSolrServer使用http方式,embedded方式官方不推荐使用。ConcurrentUpdateSolrServer不需要commit,solrServer.add(doc)即可添加数据。SolrServer solrServer = newConcurrentUpdateSolrServer(solrUrl, 队列大小, 线程数)其需要与autoCommit、autoSoftCommit配置搭配使用,网上建议配置如下:
<autoCommit>
<maxTime>100000(1-10min)</maxTime>
<openSearcher>false</openSearcher>
</autoCommit>
<autoSoftCommit>
<maxTime>1000(1s)</maxTime>
</autoSoftCommit>
|
17个各种类型字段(原纯文本Size约为200B,SolrInputDocument对象Size约为930B),以只保存ID、每字段均建立索引的方式创建索引。
如需具体的测试代码可以联系本人。
数据量(W条)
|
线程数
|
队列大小
|
时间(s)
|
网络(MB/s)
|
速率(W条/s)
|
200
|
20
|
10000
|
88
|
-
10.0
|
-
2.27
|
200
|
20
|
20000
|
133
|
-
9.0
|
-
1.50
|
200
|
40
|
10000
|
163
|
-
10.0
|
-
1.22
|
200
|
50
|
10000
|
113
|
-
10.5
|
-
1.76
|
200
|
100
|
10000
|
120
|
-
10.5
|
-
1.67
|
-
速度:Solr创建索引速度与Solr机器CPU正相关,一般情况下CPU占用率能达到接近100%,内存占用率在默认情况下需达到接近100%,网络、磁盘占用率均小。因此创建索引的效率瓶颈在CPU及内存。当内存占用率维持在接近100%,索引大小达到物理内存大小时,插入新的数据容易出现OOM错误,这时需要使用ulimit –v unlimited命令更改virtual memory配置为unlimited再启动Solr便不会出现OOM错误。在64位机器系统上,官方推荐使用MMapDirectory。
-
NRTCachingDirectory速度偏慢,会在某一时间索引添加停滞,Size先大后小,减小后索引添加继续。
-
大小:1亿索引大小约为13-16GB,2亿索引大小约为30GB。
1.3 Solr搜索方式
1.4 亿级数据搜索速度
l精确搜索
数据量(亿条)
|
字段数
|
字段类型
|
时间(ms)
|
1
|
1
|
long
|
1
|
1
|
1
|
double
|
80-1400
|
1
|
1
|
string
|
7-800
|
1
|
1
|
date
|
2-400
|
1
|
2(OR)
|
long
|
2
|
1
|
2(OR)
|
double
|
200-2400
|
1
|
2(OR)
|
string
|
500-1000
|
1
|
2(OR)
|
date
|
5-500
|
数据量(亿条)
|
字段数
|
字段类型
|
时间(ms)
|
1
|
1
|
long
|
2000-10000
|
1
|
1
|
double
|
1000-17000
|
1
|
1
|
string
|
20-16000
|
1
|
1
|
date
|
/
|
1
|
2(OR)
|
long
|
3000-25000
|
1
|
2(OR)
|
double
|
7000-45000
|
1
|
2(OR)
|
string
|
3000-48000
|
1
|
2(OR)
|
date
|
/
|
数据量(亿条)
|
字段数
|
字段类型
|
时间(ms)
|
1
|
1
|
long
|
6-46000
|
1
|
1
|
double
|
80-11000
|
1
|
1
|
string
|
7-3000
|
1
|
1
|
date
|
1000-2000
|
1
|
2(OR)
|
long
|
100-13000
|
1
|
2(OR)
|
double
|
100-60000
|
1
|
2(OR)
|
string
|
3000-13000
|
1
|
2(OR)
|
date
|
7000-10000
|
范围越大,结果数据越多,搜索花费时间越长。
第一次搜索较慢,后来时间花费较少。
来自为知笔记(Wiz)
本人主要从事海量数据处理、搜索,系统消息处理,系统架构设计的工作。 喜欢写些文章,将自己近期的工作经验总结一下。欢迎转载,但转载时请说明出处。 也可以关注我的新浪微博http://weibo.com/aitanjupt,进行交流。
本文出自 “aitanjupt” 博客,请务必保留此出处http://aitanjupt.blog.51cto.com/2839166/1414964
分享到:
相关推荐
Solr(Cloudera)使用手册
lucene,solr的使用lucene,solr的使用lucene,solr的使用lucene,solr的使用lucene,solr的使用lucene,solr的使用lucene,solr的使用lucene,solr的使用lucene,solr的使用lucene,solr的使用lucene,solr的使用
本文介绍solr的功能使用及相关注意事项;主要包括以下内容:环境搭建及调试;两个核心配置文件介绍;维护索引;查询索引,和在查询中可以应用的高亮显示、拼写检查、搜索建议、分组统计、拼音检索等功能的使用方法。
solr使用和原理 简单明了的介绍了solr的使用和原理,及其部署方式,适合初学者第一次部署
solr的安装使用步骤
solr安装和使用
Solr调研总结
solr.warsolr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包...
Solr 3.*pdf使用手册,欢迎下载
centos7 环境 安装docker 并在docker 中部署solr 并使用
solr定时索引使用到的定时调度器jar包, 可使用于solr7.x版本
Solr的基础知识,笔者翻阅了很多网上的资料,自认为比较全面,涉及到Solr的安装使用与SolrJ的开发。
用于solr6.5的IK分词包,内含使用说明及配置文件
solr 使用官方指南,solr 使用官方指南solr 使用官方指南solr 使用官方指南
简单的描绘了使用easynet开发solr客户端,包括添加,修改,删除,查询功能。
solr
1.2.1 Solr使用Lucene并且进行了扩展 4 1.2.2 Schema(模式) 5 1.2.3 查询 5 1.2.4 核心 5 1.2.5 缓存 5 1.2.6 复制 6 1.2.7 管理接口 6 1.3 Solr服务原理 6 1.3.1 索引 6 1.3.2 搜索 7 1.4 源码结构 8 1.4.1 目录...
Solr基础使用
solr中文解析器以及使用文档,配合blog使用
solr