52
DAE PyCon China 2013

DAE

Embed Size (px)

DESCRIPTION

Talk on PyCon China 2013

Citation preview

Page 1: DAE

DAEPyCon China 2013

Page 2: DAE

About Me• 洪强宁 / hongqn

• 2002年开始接触Python

• 2004年开始完全使⽤用Python⼯工作

• 2006年加⼊入⾖豆瓣,现任⾸首席架构师

• www.douban.com/people/hongqn/

[email protected]

Page 3: DAE

议程• DAE是什么

• 为什么要开发DAE

• DAE的架构

• DAE的特点

• DAE的未来

Page 4: DAE

DAE是什么

Page 5: DAE

Douban Adorable Engineers

Douban App Engine

Page 6: DAE

PaaS

Page 7: DAE

Platform as a Service (PaaS)

Page 8: DAE

PaaS

PrivatePython

Page 9: DAE

Current State

Page 10: DAE

427 apps126 对外应⽤用

Page 11: DAE

bubbler.labs.douban.com

Page 12: DAE

m.douban.com

Page 13: DAE

douban.fm

Page 14: DAE

movie.douban.com

Page 15: DAE

group.douban.com

Page 16: DAE

code

Page 17: DAE

up

Page 18: DAE

花名册

Page 19: DAE

精灵宝钻

Page 20: DAE

…等等

Page 21: DAE

每天处理 2.4 亿动态请求 5K 峰值 qps on 32 nodes

Page 22: DAE

为什么要开发DAE

Page 23: DAE

代码拆分

1 big svn repo (17万提交)

4602 git repo (2881 fork)

Page 24: DAE

重⽤用基础设施Proj A Proj B Proj C Proj D

MySQL, BeansDB, Memcache, MQ …

Page 25: DAE

简化新项⺫⽬目启动

$ dae create $ dae serve $ dae deploy

Page 26: DAE

最佳实践对 每个app开箱即⽤用

持续集成

分级上线

状态收集

故障报告

Page 27: DAE

Scale SA

4

Page 28: DAE

DAE的架构

Page 29: DAE

app.yaml

Page 30: DAE

pip-req.txt

$ dae install flask

PyPI 镜像 pypi.douban.com

Page 31: DAE

Instance• web

• gunicorn

• service

• gunicorn + customized worker

• daemon

• zookeeper

Page 32: DAE

两级结构Load Balancer (nginx)

Gateway (nginx)

App (gunicorn)

App Starter

unix socket fallback

startNode 1

Gateway (nginx)

App (gunicorn)

App Starter

Node 2

Page 33: DAE

资源池API• mysql • memcache • doubandb, doubanfs • moosefs • beanstalkd • cdn • statsd + graphite • mail • elastic search • irc

waylife 监控API调⽤用

Page 34: DAE

DAE的特点

Page 35: DAE

Low Overhead

• 资源分配 — 进程

• 资源隔离 — UNIX帐号

• 资源限制 — 外部监控

Page 36: DAE

Customizable

• 每个应⽤用从模板⽣生成nginx配置

• 使⽤用 hook point 定制

• 或者只使⽤用⽣生成的 nginx 配置⽚片段

Page 37: DAE

⾃自依赖• 通过⼀一个应⽤用部署应⽤用

• 通过⼀一个应⽤用管理应⽤用

• ⼀一个应⽤用 scale 所有应⽤用

• ⼀一个应⽤用 serve 跨应⽤用的静态⽂文件

• DAE 的代码托管在⼀一个 DAE 应⽤用上

Page 38: DAE

gevent

• 默认启⽤用

• ⽀支持⻓长连接,如 websocket

• 节省内存

• 很多坑

greenify 已开源 github.com/douban/greenify

Page 39: DAE

Service 是⼀一等公民

• Thrift

• 在线客户端⽣生成

• 依赖注册

• 升级通知

thriftclient 即将开源

Page 40: DAE

收集⼤大量状态数据

Page 41: DAE

内置最佳实践

• 错误收集 - sentry

• 在线 profile ⼯工具

• 预发布环境

• 持续集成

• Code集成

• 打包发布

• 服务地址实时推送

• 分级上线

cfgpusher 即将开源

Page 42: DAE

不受限的Python环境

• 可⽤用C扩展

• 可⽤用 fork, subprocess, multiprocessing…

曹娥已开源 github.com/douban/CaoE

Page 43: DAE

DAE的未来

Page 44: DAE

⾖豆瓣所有应⽤用的平台

Page 45: DAE

cgroups

Page 46: DAE

离线⼤大数据计算

Page 47: DAE

更好的 service 体系

Page 48: DAE

跨 IDC

Page 49: DAE

QoS

Page 50: DAE

公有云服务?

Page 51: DAE

开源?开源!

Page 52: DAE

谢谢!