# Base on WSGIdefjust_web_app(environ,start_response):data="this is FarBox Realtime API Page, you should request by WebSocket\n"start_response("200 OK",[("Content-Type","text/plain"),("Content-Length",str(len(data)))])returniter([data])
Why Flask
1, 源码量不多,容易追源;可控性高,定制的痛苦度低。 2, 文档够用,再不济看下源码即可。 3, from flask import request, g; then anywhere 4, debugger 5, 恰到好处,比如没有冲突的交叉import from website import app(views.py); from views import * (website.py) 6, Pocoo品牌: Flask/Jinja2/Pygments/Shpinx/Werkzeug
Why Jinja2/Jade
模板引擎是什么? 编译(html为py)、缓存(避免重复编译)、执行(渲染)
Jinja2 VS Django: 在模板里处理逻辑,适合吗?
Jade VS Jinja2
if var == 'a'
div.css_class this is a
elif var == 'b'
div.css_class_2 this is b
elsediv.css_class.css_class_3 this is not a or b
1, 支持Gevent 2, pre-fork worker model (比如:一个master控制10个workers,其中5个会被分派任务;当一个worker处理了1w请求或者其它原因被要求终止,master会分派一个新的worker,无缝交接)
Fail2Ban
Supervisor
Fabric
Bakthat(自动备份到S3)
rotation:
days: 7 # Number of days to keep
first_week_day: 5 # First week day, to calculate wich weekly backup keep
months: 6 # Number of months to keep
weeks: 6 # Number of weeks to keep
importsh,loggingfrombakthat.helperimportBakHelper# BakHelper automatically create a temp directorywithBakHelper("mongodb",destination="s3",password="xxxxx",tags=["mongodb"])asbh:logging.info(sh.mongodump(host='localhost:xxxx'))bh.backup()bh.rotate()
持续迭代与监控
Sentry NewRelic 用户抱怨...
数据库
Mongodb
1, FarBox的数据对象之间关系很弱,是通过路径名关联起来的 2,NoSQL 3,JSON
现在的结构: 三个节点的副本集,两个节点跟Web服务器一起,另外一个节点主要作为备份
Why need Patches
# for exmapledb.collection.find_one()db.collection.find_one(object_id)db.collection.find_one(None)# btw, Replica的选择机制