SlideShare a Scribd company logo
1 of 38
微博实时搜索
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

More Related Content

What's hot

Qcon2011-54chen-互联网分步式构架分享
Qcon2011-54chen-互联网分步式构架分享Qcon2011-54chen-互联网分步式构架分享
Qcon2011-54chen-互联网分步式构架分享zhen chen
 
MongoDB for C# developer
MongoDB for C# developerMongoDB for C# developer
MongoDB for C# developerdianming.song
 
互联网分布式系统架构分享-Qcon2011
互联网分布式系统架构分享-Qcon2011互联网分布式系统架构分享-Qcon2011
互联网分布式系统架构分享-Qcon2011Yiwei Ma
 
Linux 教育訓練
Linux 教育訓練Linux 教育訓練
Linux 教育訓練Bo-Yi Wu
 
云计算环境中Ssd在cassandra测试的性能表现
云计算环境中Ssd在cassandra测试的性能表现 云计算环境中Ssd在cassandra测试的性能表现
云计算环境中Ssd在cassandra测试的性能表现 july19850903
 
大话redis设计实现
大话redis设计实现大话redis设计实现
大话redis设计实现rfyiamcool
 
可用空間的管理
可用空間的管理可用空間的管理
可用空間的管理倩怡 賴
 
Heap exploitation
Heap exploitationHeap exploitation
Heap exploitationAngel Boy
 
Advanced heap exploitaion
Advanced heap exploitaionAdvanced heap exploitaion
Advanced heap exploitaionAngel Boy
 
Openstack swift, how does it work?
Openstack swift, how does it work?Openstack swift, how does it work?
Openstack swift, how does it work?kao kuo-tung
 
Effective linux.1.(commandline)
Effective linux.1.(commandline)Effective linux.1.(commandline)
Effective linux.1.(commandline)wang hongjiang
 
Ftn存储设计
Ftn存储设计Ftn存储设计
Ftn存储设计gzterrytan
 
Linux command tutorial
Linux command tutorialLinux command tutorial
Linux command tutorial朋 陈
 
mysql的字符串函数
mysql的字符串函数mysql的字符串函数
mysql的字符串函数wensheng wei
 
MacOS memory allocator (libmalloc) Exploitation - Chinese Version
MacOS memory allocator (libmalloc) Exploitation - Chinese VersionMacOS memory allocator (libmalloc) Exploitation - Chinese Version
MacOS memory allocator (libmalloc) Exploitation - Chinese VersionAngel Boy
 
常用Mac/Linux命令分享
常用Mac/Linux命令分享常用Mac/Linux命令分享
常用Mac/Linux命令分享Yihua Huang
 

What's hot (18)

Optimzing mysql
Optimzing mysqlOptimzing mysql
Optimzing mysql
 
Qcon2011-54chen-互联网分步式构架分享
Qcon2011-54chen-互联网分步式构架分享Qcon2011-54chen-互联网分步式构架分享
Qcon2011-54chen-互联网分步式构架分享
 
MongoDB for C# developer
MongoDB for C# developerMongoDB for C# developer
MongoDB for C# developer
 
互联网分布式系统架构分享-Qcon2011
互联网分布式系统架构分享-Qcon2011互联网分布式系统架构分享-Qcon2011
互联网分布式系统架构分享-Qcon2011
 
Linux 教育訓練
Linux 教育訓練Linux 教育訓練
Linux 教育訓練
 
云计算环境中Ssd在cassandra测试的性能表现
云计算环境中Ssd在cassandra测试的性能表现 云计算环境中Ssd在cassandra测试的性能表现
云计算环境中Ssd在cassandra测试的性能表现
 
大话redis设计实现
大话redis设计实现大话redis设计实现
大话redis设计实现
 
可用空間的管理
可用空間的管理可用空間的管理
可用空間的管理
 
Heap exploitation
Heap exploitationHeap exploitation
Heap exploitation
 
Advanced heap exploitaion
Advanced heap exploitaionAdvanced heap exploitaion
Advanced heap exploitaion
 
Openstack swift, how does it work?
Openstack swift, how does it work?Openstack swift, how does it work?
Openstack swift, how does it work?
 
Effective linux.1.(commandline)
Effective linux.1.(commandline)Effective linux.1.(commandline)
Effective linux.1.(commandline)
 
Ftn存储设计
Ftn存储设计Ftn存储设计
Ftn存储设计
 
Linux command tutorial
Linux command tutorialLinux command tutorial
Linux command tutorial
 
mysql的字符串函数
mysql的字符串函数mysql的字符串函数
mysql的字符串函数
 
MacOS memory allocator (libmalloc) Exploitation - Chinese Version
MacOS memory allocator (libmalloc) Exploitation - Chinese VersionMacOS memory allocator (libmalloc) Exploitation - Chinese Version
MacOS memory allocator (libmalloc) Exploitation - Chinese Version
 
Storm
StormStorm
Storm
 
常用Mac/Linux命令分享
常用Mac/Linux命令分享常用Mac/Linux命令分享
常用Mac/Linux命令分享
 

Similar to realtime-twitter-search

Cassandra简介.ppt
Cassandra简介.pptCassandra简介.ppt
Cassandra简介.pptjames tong
 
Python速成指南
Python速成指南Python速成指南
Python速成指南March Liu
 
Ria的强力后盾:rest+海量存储
Ria的强力后盾:rest+海量存储 Ria的强力后盾:rest+海量存储
Ria的强力后盾:rest+海量存储 zhen chen
 
Nosql及其主要产品简介
Nosql及其主要产品简介Nosql及其主要产品简介
Nosql及其主要产品简介振林 谭
 
Coreseek/Sphinx 全文检索实践指南
Coreseek/Sphinx 全文检索实践指南Coreseek/Sphinx 全文检索实践指南
Coreseek/Sphinx 全文检索实践指南HonestQiao
 
Fast flux domain detection
Fast flux domain detectionFast flux domain detection
Fast flux domain detectionNi Zhiqiang
 
高性能队列Fqueue的设计和使用实践
高性能队列Fqueue的设计和使用实践高性能队列Fqueue的设计和使用实践
高性能队列Fqueue的设计和使用实践孙立
 
Linux c++ 编程之链接与装载 -基础篇--v0.3--20120509
Linux c++ 编程之链接与装载 -基础篇--v0.3--20120509Linux c++ 编程之链接与装载 -基础篇--v0.3--20120509
Linux c++ 编程之链接与装载 -基础篇--v0.3--20120509tidesq
 
Simple tech-talk
Simple tech-talkSimple tech-talk
Simple tech-talkliltos
 
HITCON CTF 2014 BambooFox 解題心得分享
HITCON CTF 2014 BambooFox 解題心得分享HITCON CTF 2014 BambooFox 解題心得分享
HITCON CTF 2014 BambooFox 解題心得分享Chong-Kuan Chen
 
Postgre sql intro 0
Postgre sql intro 0Postgre sql intro 0
Postgre sql intro 0March Liu
 
R 語言教學: 探索性資料分析與文字探勘初探
R 語言教學: 探索性資料分析與文字探勘初探R 語言教學: 探索性資料分析與文字探勘初探
R 語言教學: 探索性資料分析與文字探勘初探Sean Yu
 
Google protocol buffers简析
Google protocol buffers简析Google protocol buffers简析
Google protocol buffers简析wavefly
 
Java线上应用问题排查方法和工具(空望)
Java线上应用问题排查方法和工具(空望)Java线上应用问题排查方法和工具(空望)
Java线上应用问题排查方法和工具(空望)ykdsg
 
Voldemort Intro Tangfl
Voldemort Intro TangflVoldemort Intro Tangfl
Voldemort Intro Tangflfulin tang
 
Redis分享
Redis分享Redis分享
Redis分享yiihsia
 
C++工程实践
C++工程实践C++工程实践
C++工程实践Shuo Chen
 

Similar to realtime-twitter-search (20)

Cassandra简介.ppt
Cassandra简介.pptCassandra简介.ppt
Cassandra简介.ppt
 
Python速成指南
Python速成指南Python速成指南
Python速成指南
 
Ria的强力后盾:rest+海量存储
Ria的强力后盾:rest+海量存储 Ria的强力后盾:rest+海量存储
Ria的强力后盾:rest+海量存储
 
Nosql及其主要产品简介
Nosql及其主要产品简介Nosql及其主要产品简介
Nosql及其主要产品简介
 
Coreseek/Sphinx 全文检索实践指南
Coreseek/Sphinx 全文检索实践指南Coreseek/Sphinx 全文检索实践指南
Coreseek/Sphinx 全文检索实践指南
 
Fast flux domain detection
Fast flux domain detectionFast flux domain detection
Fast flux domain detection
 
Jvm内存管理基础
Jvm内存管理基础Jvm内存管理基础
Jvm内存管理基础
 
高性能队列Fqueue的设计和使用实践
高性能队列Fqueue的设计和使用实践高性能队列Fqueue的设计和使用实践
高性能队列Fqueue的设计和使用实践
 
Linux c++ 编程之链接与装载 -基础篇--v0.3--20120509
Linux c++ 编程之链接与装载 -基础篇--v0.3--20120509Linux c++ 编程之链接与装载 -基础篇--v0.3--20120509
Linux c++ 编程之链接与装载 -基础篇--v0.3--20120509
 
Simple tech-talk
Simple tech-talkSimple tech-talk
Simple tech-talk
 
HITCON CTF 2014 BambooFox 解題心得分享
HITCON CTF 2014 BambooFox 解題心得分享HITCON CTF 2014 BambooFox 解題心得分享
HITCON CTF 2014 BambooFox 解題心得分享
 
Postgre sql intro 0
Postgre sql intro 0Postgre sql intro 0
Postgre sql intro 0
 
R 語言教學: 探索性資料分析與文字探勘初探
R 語言教學: 探索性資料分析與文字探勘初探R 語言教學: 探索性資料分析與文字探勘初探
R 語言教學: 探索性資料分析與文字探勘初探
 
getPDF.aspx
getPDF.aspxgetPDF.aspx
getPDF.aspx
 
getPDF.aspx
getPDF.aspxgetPDF.aspx
getPDF.aspx
 
Google protocol buffers简析
Google protocol buffers简析Google protocol buffers简析
Google protocol buffers简析
 
Java线上应用问题排查方法和工具(空望)
Java线上应用问题排查方法和工具(空望)Java线上应用问题排查方法和工具(空望)
Java线上应用问题排查方法和工具(空望)
 
Voldemort Intro Tangfl
Voldemort Intro TangflVoldemort Intro Tangfl
Voldemort Intro Tangfl
 
Redis分享
Redis分享Redis分享
Redis分享
 
C++工程实践
C++工程实践C++工程实践
C++工程实践
 

realtime-twitter-search

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n