狠狠撸

狠狠撸Share a Scribd company logo
微博实时搜索
xuanxi@mogujie.com
      汪亚军
大纲

介绍

近实时搜索

可增量段存储 AND 可中断查询

并发编程

Jessica 2.0
介绍


于我

菇街搜索

实时搜索场景
Lucene segment
    segment 1 segment 2 segment 3



 Map
                           mergepolicy
Reduce




               segment
Lucene 近实时搜索

IndexWriter.setRAMBufferSizeMB() 设置ram
buffer大小 LUCENE-843

IndexWriter.getReader() 将ram buffer刷回
RamDir 但不Commit LUCENE-1516

LUCENE-843 VS LUCENE-1516
Zoie


由linkedin   发并   源

提供一个在lucene之上的封装保证实时性

快速doci<=>uid双向对应方案
zoie
    Mem A + Disk                        Mem A + new Disk
1,Mem A 添加文档立刻更新的                   1,Mem A 添加文档立刻更新的
2,Disk在下次合并之前,一直使用                  2, 使用前面Mem A和Disk合并好
                                       的 new Disk




               Mem A +Mem B+ Disk
           1,Mem B 添加文档立刻更新的
            2,Mem A 只读 与Disk合并
              2,Disk 无变化 与Mem A合并
Zoie
RAM IndexWriter 定时reopen有效 10s

reopen一次 Disk缓存中docId<=>Object_id 对
应不对 都必须重建一次

fav:{ 100 to 1000} 这是个灾难

查询千万级     的数据 耗时在100ms级      (no
cache)
结论


为了实时搜索,常常刷新创建的segment,不可取

实时系统,缓存常常失效,这样我们没有办法在短
时间内,遍历所有的docId
解决办法


可增量的倒排索引

从新向旧遍历的倒排索引

可中断的查询
可增量倒排索引

term 字典

词频

text

PostingList
可增量倒排索引
      textpointe   frequency startPostingsPotine   endPostingsPotiner
a         r                           r

b
c                                            parralle
d                                           int arrays
...
...          Term
x
             字典
y
z
可增量倒排索引
      textpointe   frequency startPostingsPotiner endPostingsPotiner
a         r

b
c
d
...
...
x
y
z

                    PostingListStore
可增量倒排索引
      textpointe   frequency startPostingsPotiner endPostingsPotiner
a         r

b
c
d
...
...
x                         从新向旧遍历的倒排索引
y
z

                    PostingListStore
Lucene 倒排压缩算法
可增量倒排索引
      textpointe   frequency startPostingsPotiner endPostingsPotiner
a         r

b          lucene
c     的压缩算法无法从新向旧搜索
d
                    文档
...
...
x                         从新向旧遍历的倒排索引
y
z

                    PostingListStore
PostingListStore



docId

position (twitter 1-140 < 255 )
PostingListStore

docId

position (twitter 1-140 < 255 )

(docId <<8 ) | (position&0xFF)
PostingListStore


无压缩

通过位置信息和docId存储在一个int里面   少内
存   销
PostingListStore


int pool

auto expand

zero copy (do not like array)
PostingListStore
PostingListStore

  PostingListPointer
PostingListStore
单个Term的PostingList的所有Slice组成一个双向链表




                    prepointer data ...

      ...   data nextpointer
PostingListStore
单个Term的PostingList的所有Slice组成一个双向链表




                    prepointer data ...

      ...   data nextpointer


                双向链表的好处?
可增量倒排索引
可中断查询


我们最   心最近有更新的前n条数据

从新向老查询

超时立马返回(HashedWheelTimer)
智能二分查找算法

依次从新向旧找

记录上次二分查找时候各位置数据

对当前查找做智能直到

skipList search + smart search + binary
search
总结



中断查询 + 从新查找PostingStore = 实时搜索
并发编程


writer和reader wait free(JMM)

保证reader的数据一致性(版本号)
Writer AND Reader
v = 100;

thread a write v = 101;

thread b read v => 100;

数据一致性 java并不能保证a写了就立马能被b
看到

Lock Free
Java Memory Model


happen before

volatile

memory barrier

volatile 只能保证之前写的越过内存障碍*
内存屏障



PostingStore越过内存屏障 => 从Term的
PostingList 始指针向新查找
内存屏障
单个Term的PostingList的所有Slice组成一个双向链表




                    prepointer data ...

      ...   data nextpointer

             双向链表的好处
reader 数据一致性
版本号
Jessica 2.0

重写lucene

纯内存posting store

从日志系统重建索引

可中断查询

存储原始数据
Jessica 2.0

jessica 负责索引
               jessica   monica负责打分排序


  feeder                     monica
               jessica


feeder负责分词     jessica
感谢



twitter

Michael Busch
Ad

Recommended

微博实时搜索
微博实时搜索
亚军 汪
?
分布式系统缓存设计
分布式系统缓存设计
zhujiadun
?
分布式系统缓存设计
分布式系统缓存设计
aleafs
?
Redis 介绍 -田琪
Redis 介绍 -田琪
Shaoning Pan
?
惭别尘肠补肠丑别诲分享
惭别尘肠补肠丑别诲分享
princehaku
?
Tokyo Cabinet Key Value数据库及其扩展应用
Tokyo Cabinet Key Value数据库及其扩展应用
rewinx
?
手机腾讯网闯蝉资源版本增量更新方案飞3肠迟别肠丑
手机腾讯网闯蝉资源版本增量更新方案飞3肠迟别肠丑
luyongfugx
?
海量用户数据处理及其在一淘广告和推荐中的应用
海量用户数据处理及其在一淘广告和推荐中的应用
Shaoning Pan
?
Optimzing mysql
Optimzing mysql
liufabin 66688
?
蚕肠辞苍2011-54肠丑别苍-互联网分步式构架分享
蚕肠辞苍2011-54肠丑别苍-互联网分步式构架分享
zhen chen
?
MongoDB for C# developer
MongoDB for C# developer
dianming.song
?
互联网分布式系统架构分享-蚕肠辞苍2011
互联网分布式系统架构分享-蚕肠辞苍2011
Yiwei Ma
?
Linux 教育訓練
Linux 教育訓練
Bo-Yi Wu
?
云计算环境中厂蝉诲在肠补蝉蝉补苍诲谤补测试的性能表现
云计算环境中厂蝉诲在肠补蝉蝉补苍诲谤补测试的性能表现
july19850903
?
大话谤别诲颈蝉设计实现
大话谤别诲颈蝉设计实现
rfyiamcool
?
可用空间的管理
可用空间的管理
倩怡 賴
?
Heap exploitation
Heap exploitation
Angel Boy
?
Advanced heap exploitaion
Advanced heap exploitaion
Angel Boy
?
Openstack swift, how does it work?
Openstack swift, how does it work?
kao kuo-tung
?
Effective linux.1.(commandline)
Effective linux.1.(commandline)
wang hongjiang
?
贵迟苍存储设计
贵迟苍存储设计
gzterrytan
?
Linux command tutorial
Linux command tutorial
朋 陈
?
尘测蝉辩濒的字符串函数
尘测蝉辩濒的字符串函数
wensheng wei
?
MacOS memory allocator (libmalloc) Exploitation - Chinese Version
MacOS memory allocator (libmalloc) Exploitation - Chinese Version
Angel Boy
?
Storm
Storm
Phoenix Zhang
?
常用惭补肠/尝颈苍耻虫命令分享
常用惭补肠/尝颈苍耻虫命令分享
Yihua Huang
?
颁补蝉蝉补苍诲谤补介绍.辫辫迟
颁补蝉蝉补苍诲谤补介绍.辫辫迟
james tong
?
笔测迟丑辞苍速成指南
笔测迟丑辞苍速成指南
March Liu
?
搁颈补的强力后盾:谤别蝉迟+海量存储
搁颈补的强力后盾:谤别蝉迟+海量存储
zhen chen
?
狈辞蝉辩濒及其主要产物介绍
狈辞蝉辩濒及其主要产物介绍
振林 谭
?

More Related Content

What's hot (18)

Optimzing mysql
Optimzing mysql
liufabin 66688
?
蚕肠辞苍2011-54肠丑别苍-互联网分步式构架分享
蚕肠辞苍2011-54肠丑别苍-互联网分步式构架分享
zhen chen
?
MongoDB for C# developer
MongoDB for C# developer
dianming.song
?
互联网分布式系统架构分享-蚕肠辞苍2011
互联网分布式系统架构分享-蚕肠辞苍2011
Yiwei Ma
?
Linux 教育訓練
Linux 教育訓練
Bo-Yi Wu
?
云计算环境中厂蝉诲在肠补蝉蝉补苍诲谤补测试的性能表现
云计算环境中厂蝉诲在肠补蝉蝉补苍诲谤补测试的性能表现
july19850903
?
大话谤别诲颈蝉设计实现
大话谤别诲颈蝉设计实现
rfyiamcool
?
可用空间的管理
可用空间的管理
倩怡 賴
?
Heap exploitation
Heap exploitation
Angel Boy
?
Advanced heap exploitaion
Advanced heap exploitaion
Angel Boy
?
Openstack swift, how does it work?
Openstack swift, how does it work?
kao kuo-tung
?
Effective linux.1.(commandline)
Effective linux.1.(commandline)
wang hongjiang
?
贵迟苍存储设计
贵迟苍存储设计
gzterrytan
?
Linux command tutorial
Linux command tutorial
朋 陈
?
尘测蝉辩濒的字符串函数
尘测蝉辩濒的字符串函数
wensheng wei
?
MacOS memory allocator (libmalloc) Exploitation - Chinese Version
MacOS memory allocator (libmalloc) Exploitation - Chinese Version
Angel Boy
?
Storm
Storm
Phoenix Zhang
?
常用惭补肠/尝颈苍耻虫命令分享
常用惭补肠/尝颈苍耻虫命令分享
Yihua Huang
?
蚕肠辞苍2011-54肠丑别苍-互联网分步式构架分享
蚕肠辞苍2011-54肠丑别苍-互联网分步式构架分享
zhen chen
?
MongoDB for C# developer
MongoDB for C# developer
dianming.song
?
互联网分布式系统架构分享-蚕肠辞苍2011
互联网分布式系统架构分享-蚕肠辞苍2011
Yiwei Ma
?
Linux 教育訓練
Linux 教育訓練
Bo-Yi Wu
?
云计算环境中厂蝉诲在肠补蝉蝉补苍诲谤补测试的性能表现
云计算环境中厂蝉诲在肠补蝉蝉补苍诲谤补测试的性能表现
july19850903
?
大话谤别诲颈蝉设计实现
大话谤别诲颈蝉设计实现
rfyiamcool
?
可用空间的管理
可用空间的管理
倩怡 賴
?
Heap exploitation
Heap exploitation
Angel Boy
?
Advanced heap exploitaion
Advanced heap exploitaion
Angel Boy
?
Openstack swift, how does it work?
Openstack swift, how does it work?
kao kuo-tung
?
Effective linux.1.(commandline)
Effective linux.1.(commandline)
wang hongjiang
?
贵迟苍存储设计
贵迟苍存储设计
gzterrytan
?
Linux command tutorial
Linux command tutorial
朋 陈
?
尘测蝉辩濒的字符串函数
尘测蝉辩濒的字符串函数
wensheng wei
?
MacOS memory allocator (libmalloc) Exploitation - Chinese Version
MacOS memory allocator (libmalloc) Exploitation - Chinese Version
Angel Boy
?
常用惭补肠/尝颈苍耻虫命令分享
常用惭补肠/尝颈苍耻虫命令分享
Yihua Huang
?

Similar to realtime-twitter-search (20)

颁补蝉蝉补苍诲谤补介绍.辫辫迟
颁补蝉蝉补苍诲谤补介绍.辫辫迟
james tong
?
笔测迟丑辞苍速成指南
笔测迟丑辞苍速成指南
March Liu
?
搁颈补的强力后盾:谤别蝉迟+海量存储
搁颈补的强力后盾:谤别蝉迟+海量存储
zhen chen
?
狈辞蝉辩濒及其主要产物介绍
狈辞蝉辩濒及其主要产物介绍
振林 谭
?
Coreseek/Sphinx 全文检索实践指南
Coreseek/Sphinx 全文检索实践指南
HonestQiao
?
Fast flux domain detection
Fast flux domain detection
Ni Zhiqiang
?
闯惫尘内存管理基础
闯惫尘内存管理基础
wang hongjiang
?
高性能队列贵辩耻别耻别的设计和使用实践
高性能队列贵辩耻别耻别的设计和使用实践
孙立
?
Linux c++ 编程之链接与装载 -基础篇--v0.3--20120509
Linux c++ 编程之链接与装载 -基础篇--v0.3--20120509
tidesq
?
Simple tech-talk
Simple tech-talk
liltos
?
HITCON CTF 2014 BambooFox 解題心得分享
HITCON CTF 2014 BambooFox 解題心得分享
Chong-Kuan Chen
?
Postgre sql intro 0
Postgre sql intro 0
March Liu
?
R 語言教學: 探索性資料分析與文字探勘初探
R 語言教學: 探索性資料分析與文字探勘初探
Sean Yu
?
getPDF.aspx
getPDF.aspx
byron zhao
?
getPDF.aspx
getPDF.aspx
byron zhao
?
Google protocol buffers简析
Google protocol buffers简析
wavefly
?
闯补惫补线上应用问题排查方法和工具(空望)
闯补惫补线上应用问题排查方法和工具(空望)
ykdsg
?
Voldemort Intro Tangfl
Voldemort Intro Tangfl
fulin tang
?
搁别诲颈蝉分享
搁别诲颈蝉分享
yiihsia
?
颁++工程实践
颁++工程实践
Shuo Chen
?
颁补蝉蝉补苍诲谤补介绍.辫辫迟
颁补蝉蝉补苍诲谤补介绍.辫辫迟
james tong
?
笔测迟丑辞苍速成指南
笔测迟丑辞苍速成指南
March Liu
?
搁颈补的强力后盾:谤别蝉迟+海量存储
搁颈补的强力后盾:谤别蝉迟+海量存储
zhen chen
?
狈辞蝉辩濒及其主要产物介绍
狈辞蝉辩濒及其主要产物介绍
振林 谭
?
Coreseek/Sphinx 全文检索实践指南
Coreseek/Sphinx 全文检索实践指南
HonestQiao
?
Fast flux domain detection
Fast flux domain detection
Ni Zhiqiang
?
闯惫尘内存管理基础
闯惫尘内存管理基础
wang hongjiang
?
高性能队列贵辩耻别耻别的设计和使用实践
高性能队列贵辩耻别耻别的设计和使用实践
孙立
?
Linux c++ 编程之链接与装载 -基础篇--v0.3--20120509
Linux c++ 编程之链接与装载 -基础篇--v0.3--20120509
tidesq
?
Simple tech-talk
Simple tech-talk
liltos
?
HITCON CTF 2014 BambooFox 解題心得分享
HITCON CTF 2014 BambooFox 解題心得分享
Chong-Kuan Chen
?
Postgre sql intro 0
Postgre sql intro 0
March Liu
?
R 語言教學: 探索性資料分析與文字探勘初探
R 語言教學: 探索性資料分析與文字探勘初探
Sean Yu
?
Google protocol buffers简析
Google protocol buffers简析
wavefly
?
闯补惫补线上应用问题排查方法和工具(空望)
闯补惫补线上应用问题排查方法和工具(空望)
ykdsg
?
Voldemort Intro Tangfl
Voldemort Intro Tangfl
fulin tang
?
搁别诲颈蝉分享
搁别诲颈蝉分享
yiihsia
?
颁++工程实践
颁++工程实践
Shuo Chen
?
Ad

realtime-twitter-search

Editor's Notes