搜狐pv insight(py)技术交流

49
搜搜 搜搜 PVInsight PVInsight 搜搜搜搜搜搜搜搜搜 ; 搜搜

Upload: bj

Post on 19-May-2015

1.086 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: 搜狐Pv insight(py)技术交流

搜狐搜狐 PVInsightPVInsight 运算系统运算系统刘凯毅 ; 尤春

Page 2: 搜狐Pv insight(py)技术交流

PVInsight 系统简介

• 公司向用户提供的价值

• 获取的商业价值

Page 3: 搜狐Pv insight(py)技术交流

PVInsight 运系统简介

什么样的用户认可提供的价值?

这些用户有商业价值吗?有多认可?

开始认识用户吧 !

Page 4: 搜狐Pv insight(py)技术交流

系统简介 / 用户

关键字 : 响应用户 / 新用户 / 活跃用户 / 流失用户

Page 5: 搜狐Pv insight(py)技术交流

系统简介 / 用户

关键字 : 连续访问

Page 6: 搜狐Pv insight(py)技术交流

系统简介 / sohu 企邮

一个企邮用户的连续访问 > 登入 > [ 管理此域 ] > 员工列表 > 广播邮件 *

>>> ..... 一通点击

> 群组列表 > 新建群组 > 广播邮件 * > 发送

想发广播邮件的用户 想做了些什么?

Page 7: 搜狐Pv insight(py)技术交流

系统简介 / sohu 企邮

如何发现 此类连续访问问题 ?

1. 产品经理提出: 希望看到发“广播邮件”的用户都怎么时候 ?2. 从数据仓库中找出连续访问中 > 广播邮件 > 发送 ;之前的 操作 3. 并清洗数据为 离发送广播邮件最后 10 步 :

> a_url 访问人数 ;

> b_url 访问人数 离发送广播邮件最后 9 步 : > c_url 访问人数 > d_url 访问人数 …… .

Page 8: 搜狐Pv insight(py)技术交流

这样做对商业价值有利吗?

系统简介 / 商业价值

各个职位上对商业价值的帮助

广告给我们带来效果怎么样 ?

Page 9: 搜狐Pv insight(py)技术交流

系统简介 / 商业价值角度

公司高层

搜狐pvinsight系统

搜狐全站访问和用户情况如何?

广告投放效果如何?

我应该重点支持哪些系统?

部门老大

我们部门的访问情况如何?

这篇文章或专题效果如何?文章SEO效果如何

从全站到文章

从长久站到短暂

从整体到细节

市场部

开发人员优化人员编辑

Page 10: 搜狐Pv insight(py)技术交流

名词解释

Pv : page view 浏览次数Uv : unique visitor 独立访客Ip : 独立 Ip 数 新老访客 / 回头用户 / 会话次数 / 访问间隔 / 停留时长 / 访问深度 / 回访率 / 跳出率 / 入口率 计费方式 : cpc : 每次点击计费 cpm : 千次效果展现 计费 cpa : 用户行为计费 cps : 销售成本计费

Page 11: 搜狐Pv insight(py)技术交流

名词解释

现实是很残酷的 : 其实 UV 就很难算 ~

我们的 UID 是一个 16 位的字符串 一般一个小小的统计就上亿条的记录 ( 16*8* (10**8) ) / ((2**10)**3) = 12 G

Page 12: 搜狐Pv insight(py)技术交流

PVInsight 运系统简介

系统架构• 收 集 • 存 储 • 结构化 • 可视化

Page 13: 搜狐Pv insight(py)技术交流

系统架构 / 图

Page 14: 搜狐Pv insight(py)技术交流

系统架构 / 使用语言

1. Python

• ETL: 数据清洗 / 数据完整性 • 中间数据:结构维护(分时 / 治) / 统计• 胶水 : c / r /mysql/ infob / bdb

2. Java

• Hdfs / mapreduce / hbase

3. Shell

• 调度 / 维护运行环境配置

Page 15: 搜狐Pv insight(py)技术交流

Py 细节 / 预处理

Page 16: 搜狐Pv insight(py)技术交流

Py 细节 / 预处理 / 数据完整性 url

url => 栏目 ID ,频道 ID

搜狐全站

auto频道 club频道 . . .

栏目 栏目 栏目 . . .

URLURL . . .URL URL

Page 17: 搜狐Pv insight(py)技术交流

Py 细节 / 预处理 / 数据完整性 url

域名 +url

auto.sohu.com//20090914/n266706777.shtml

域名

auto.sohu.com/

泛域名

i.auto.sohu.com/20090913/n237706498.shtml

特例

http://cs.focus.cn/news/2005-09-14/128510.html

Page 18: 搜狐Pv insight(py)技术交流

Py 细节 / 预处理 / 数据完整性 url

1. 存储 btree 需要匹配 url

• Key = domain 倒序 |url

def pointerDrift_domain(self,domain,url,loop=10) :

if loop < 0 : return ('0','0')

dk2,dv2 = btree_url.previous() # next()

dtype,ddmain,durl = dk2.split('|')[:3]

if ddmain != domain : return ('0','0')

if url.startswith( durl ) :

return dv2.split('\t')

else :

return self.pointerDrift_domain(domain,url,loop-1)

Page 19: 搜狐Pv insight(py)技术交流

Py 细节 / 预处理 / 数据完整性 url

Btree key url

moc.uhos.otua | /20090913/n237706498.shtml

moc.uhos.otua |

moc.uhos.otua.i | /20090914/n266706777.shtml

| = 174

特例

cs.focus.cn/news/2005-09-14/128510.html

Page 20: 搜狐Pv insight(py)技术交流

Py 细节 / 预处理 / 数据清洗流水线——预处理0908251329265655 [26/Aug/2009:13:25:01 +0800] 123.15.49.138 "GET /pv.gif?t?=1251264295765164_1024_768?r?=http://www.sohu.com/ HTTP/1.1" "http://news.sohu.com/20090826/n266231388.shtml" pv.sohu.com CN4107 - - "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; QQDownload 570; .NET CLR 1.1.4322; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)" [email protected]

news.sohu.com 0908251329265655 20090826/n266231388.shtml 26/Aug/2009:13:25:01 0|2|1|1|[email protected] www.sohu.com CN2301

908251329265655 1252922376 900 /20090707/n265035120.shtml 11 / 0|2|1|1|[email protected] CN2301

news.sohu.com 0908251329265655 20090826/n266231388.shtml 26/Aug/2009:13:25:01 0|2|1|1|[email protected] www.sohu.com CN2301

908251329265655 1252922376 900 /20090707/n265035120.shtml 11 / 0|2|1|1|[email protected] CN2301

news.sohu.com 0908251329265655 20090826/n266231388.shtml 26/Aug/2009:13:25:01 0|2|1|1|[email protected] www.sohu.com CN2301

908251329265655 1252922376 900 /20090707/n265035120.shtml 11 / 0|2|1|1|[email protected] CN2301

news.sohu.com 0908251329265655 20090826/n266231388.shtml 26/Aug/2009:13:25:01 0|2|1|1|[email protected] www.sohu.com CN2301

908251329265655 1252922376 900 /20090707/n265035120.shtml 11 / 0|2|1|1|[email protected] CN2301

news.sohu.com 0908251329265655 20090826/n266231388.shtml 26/Aug/2009:13:25:01 0|2|1|1|[email protected] www.sohu.com CN2301

908251329265655 1252922376 900 /20090707/n265035120.shtml 11 / 0|2|1|1|[email protected] CN2301

Page 21: 搜狐Pv insight(py)技术交流

Py 细节 / 预处理 / 数据清洗

Py 的一些特性正则>>> re.findall( r’\b(?:ab)+\b’ , ’ababab abbabb aabaab’)输出 : ['ababab']

>>> re.findall( ’/\*.*?\*/’ , ‘/* part 1 */ code /* part 2 */ ‘)输出 : ['/* part 1 */', '/* part 2 */']    

‘(?<=…)’ 前向界定 , ‘(?=…)’  后向界定>>> s=r’/* comment 1 */  code  /* comment 2 */’>>> re.findall( r’(?<=/\*).+?(?=\*/)’ , s )[' comment 1 ', ' comment 2 ']

# py 条件正则 大家请注意 。。。

Page 22: 搜狐Pv insight(py)技术交流

Py 细节 / 预处理 / 数据清洗

合理使用正则

Page 23: 搜狐Pv insight(py)技术交流

Py 细节 / 预处理 / 中间结果 / 分时分治

Page 24: 搜狐Pv insight(py)技术交流

PVInsight 运算系统实现

流水线——分时处理

5分钟处理log 1 12处理过去 小时 个5分钟的dump

1 24处理过去 天 个小时的dump

根据需要处理过去若干天的dump

Page 25: 搜狐Pv insight(py)技术交流

Py 细节 / 分时

流水线——分时处理

Page 26: 搜狐Pv insight(py)技术交流

Py 细节

分治

Page 27: 搜狐Pv insight(py)技术交流

计算 UV

好吧已经知道 UV 就很难算 ~

我们先来看看 ,目前非常火的 Mapreduce 解决方案!

Page 28: 搜狐Pv insight(py)技术交流

UV 计算, mapreduce 解决方案

目前我这里使用的, mapreduce 很粗暴!

Page 29: 搜狐Pv insight(py)技术交流

UV 计算, mapreduce 解决方案

频道 1,SUV1频道 2,SUV2频道 1,SUV3频道 1,SUV1频道 1,SUV2

频道 1 SUV1频道 1 SUV1频道 1 SUV2频道 1 SUV3

频道 2 SUV1

频道 1 SUV1频道 1 SUV1频道 1 SUV2频道 1 SUV3频道 2 SUV1

频道 1,SUV1频道 2,SUV2频道 1,SUV3频道 1,SUV1频道 1,SUV2

频道 1 SUV1频道 1 SUV3频道 1 SUV1频道 1 SUV2

频道 2 SUV1

频道 1 SUV1频道 1 SUV3频道 1 SUV2

频道 2 SUV1

Page 30: 搜狐Pv insight(py)技术交流

UV 计算, mapreduce 解决方案

频道 1,IP1,SUV1频道 2, IP1,SUV2频道 1, IP2,SUV3

频道 1 ‘SUV’ SUV1频道 1 ‘IP’ IP1频道 2 ‘SUV’ SUV2频道 2 ‘IP’ IP1频道 1 ‘SUV’ SUV3频道 1 ‘IP’ IP2

… …

Page 31: 搜狐Pv insight(py)技术交流

Py 细节 / 预处理 / 中间结果 / 分时分治

Python :marshal

Page 32: 搜狐Pv insight(py)技术交流

UV 计算, python 解决方案

频道 1,SUV1频道 2,SUV2频道 1,SUV1

频道 1,SUV3频道 1,SUV1

频道 1,SUV2

频道 1 001001…频道 2 100111 …

频道 1 110011…

频道 1 00100…

频道 1 0001010…

频道 2 1001000…

Page 33: 搜狐Pv insight(py)技术交流

UV 计算, python 解决方案

频道 1,SUV1频道 2,SUV2频道 1,SUV1

频道 1,SUV3频道 1,SUV1

频道 1,SUV2

频道 1 001001…频道 2 100111 …

频道 1 110011…

频道 1 00100…

频道 1 0001010…

频道 2 1001000…

Page 34: 搜狐Pv insight(py)技术交流

UV 计算, python 解决方案

现实又一次的残酷了!我们的 UID 是一个 16 位的字符串 ~

Page 35: 搜狐Pv insight(py)技术交流

UV 计算, python 解决方案

bc=bitarray()for n in xrange( 1000 ) :    bc.extend(bitarray(10**6))

#120Mf1=open('/tmp/bc1.ba','wa')bc.tofile(f1)

# 我测试在 160k 左右sio = StringIO()f2=open('/tmp/bc2.ba','wb')w = GzipFile('/tmp/bc3.ba','wb',9,sio)w.write(bc.tostring())w.close()

Page 36: 搜狐Pv insight(py)技术交流

UV 计算, python 解决方案

Page 37: 搜狐Pv insight(py)技术交流

UV 计算, python 调度

这么多任务 , 我们需要以个 ..

调度

Page 38: 搜狐Pv insight(py)技术交流

Py 细节 / 调度 - gearman

Page 39: 搜狐Pv insight(py)技术交流

Py 细节 / 调度 – 想象远没现实美好

Page 40: 搜狐Pv insight(py)技术交流

Py 细节 / 胶水 R / rpy2

import rpy2.robjects as robjectsr = robjects.r

robjects.globalenv["x"] = robjects.FloatVector([1,2, 3, 4, 5, 6, 7, 8, 9, 10])robjects.globalenv["y"] = robjects.FloatVector([0,30,44,57,65,78,68,97,99,120])lm_d9 = r.lm("y ~ 1+x")

r.predict( lm_d9, robjects.r(" data.frame(x=11) "), interval="prediction",level=0.95)[0]

输出 : 128.26666666666668

Page 41: 搜狐Pv insight(py)技术交流

数据的重要性 - 数据可视化

Twitter 上我们的关系

Page 42: 搜狐Pv insight(py)技术交流

数据的重要性 - 数据可视化

facebook 人物关系链图

Page 43: 搜狐Pv insight(py)技术交流

数据的重要性 - 数据可视化

Yahoo Research针对地震发生后一小时 twitter相关微博数据研究

Page 44: 搜狐Pv insight(py)技术交流

数据的重要性 - 数据可视化

高转帖子的传播环: 二环为粉丝转发 5% , 三环为粉丝们的粉丝转发 55% , 四环是粉丝们的粉丝加泛粉丝 25% , 五环是随机粉丝 15% 。

Page 45: 搜狐Pv insight(py)技术交流

数据的重要性 - 数据可视化

Page 46: 搜狐Pv insight(py)技术交流

数据的重要性 - 数据可视化

twitter 上的 love 有关的关键词

Page 47: 搜狐Pv insight(py)技术交流

数据的重要性 - 数据可视化

twitter 上的 hate 有关的关键词

Page 48: 搜狐Pv insight(py)技术交流

数据的重要性 - 数据可视化

Yahoo Research针对地震发生后一小时 twitter相关微博数据研究

Page 49: 搜狐Pv insight(py)技术交流