SlideShare une entreprise Scribd logo
1  sur  29
Télécharger pour lire hors ligne
Introduction to SAE Python
        Jaime Chen
chenzheng2@staff.sina.com.cn
     PyCon China 2011
         新浪 R&D
A distributed system is one in which the
failure of a computer you didn't even
know existed can render your own
computer unusable.
                        -- Leslie Lamport
内容概览
示例应用

SAE Python介绍

沙盒实现分享
Hello, world!
import sae

def app(environ, start_response):
   status = '200 OK'
   response_headers = [('Content-type',
'text/plain')]
   start_response(status, response_headers)
   return ['Hello, world!']

application =sae.create_wsgi_app(app)

http://blackfire.sinaapp.com
http://djangoblog.sinaapp.com
http://caicaini.sinaapp.com
http://toqrcode.sinaapp.com
微博相关应用
SAE 数据

用户数: 8.5万+
应用数: 12万+
日代码部署次数: 2万+
日增用户数: 600+
日增应用数: 700+
日请求数公共平台:4700万
微博平台:1.3 亿

Q3宕机时长:45分钟
Q3宕机次数:4次
Q3整体服务SLA:99.95%
Sina AppEngine 服务
MySQL
Memcache
Storage
KVDB

Mail
Cron
TaskQueue

Rank,分词,全文搜索等扩展服务
http://sae.sina.com.cn/?m=devcenter&catId=33
SAE Python
主页 http://appstack.sinaapp.com/
文档 http://appstack.sinaapp.com/static/doc/release/testing/
Git https://github.com/SAEPython/saepythondevguide

os.getcwd: app根目录,index.wsgi

No os.fork, os.system, os.exec*, os.popen*

Say goodbye to subprocess
文件系统
只读:
$app_root, no version in path
/usr/local/sae/python/lib/python2.6
/saetmp/$hash/$appname
/dev/urandom
/etc/mime.types

可写:
/saetmp/$hash/$appname
预装第三方模块
Django-1.2.7
mitsuhiko-werkzeug-0.7.1
Flask-0.7.2
MySQL-python-1.2.3
tornado-2.1.1
bottle-0.9.6
sinatpy2.x
Uliweb-0.0.1a7
SQLAlchemy-0.7.3
web.py-0.36
使用其他模块
app_root 已在sys.path中

参考 http://weizi888.sinaapp.com/

requirements.txt TBD
Sandbox 概览
cpu,mem:  apache

进程线程

网络

文件系统
一些思考
独立沙盒:   不可逆模式,python初始化后进入沙盒,无法退出
受控沙盒:  沙盒每次动作都需要向主控者发出请求

full-sandbox:应用代码不需修改
para-sandbox:应用需要修改

whitelist-sandbox
blacklist-sandbox
A pragmatic approach
进程和线程
--with-threads=no

#undef HAVE_FORK
#undef HAVE_SPAWNV
#undef HAVE_EXECV

#undef HAVE_KILL
#undef HAVE_KILLPG
#undef HAVE_PIPE
#undef HAVE_POPEN
#undef HAVE_SYSTEM
....
网络
urllib, urllib2 -> socket.py -> Modules/socketmodule.
c

getsockaddrarg

ip, port 白名单

访问频率控制

iptable
文件操作 
r_path, r_path

Modules/posixmodule.c os.open, os.unlink, ...
Modules/_fileio.c _fileio, io.FileIO
Objects/fileobject.c PyFile_Type, builtin.open

Python/bltinmodule.c execfile
Python/traceback.c traceback.print_exc
Python/import.c __import__, import语句, imp模块
get_file, find_module
Modules/zipimport.c
其他....
禁用动态扩展
#undef HAVE_DYNAMIC_LOADING

允许加载系统目录的c扩展?

禁用模块:ctypes, _ctypes_test,
_multiprocessing, dl, fcntl, grp, nis, pwd,
resource, select, spwd, syslog
apache, mod_wsgi
embedded mode
daemon mode

wsgi_interpreters:
   application_group -> interpreter
wsgi_daemon_index:
   process_group -> daemon

wsgi_daemon_list

Py_Newinterpreter share c-exts
Other Python web hosting providers

GAE
Webfaction
Gondor
ep.io
heroku
dotcloud
Roadmap
Git support
Interactive debugger in protected debug mode
Internal pypi, requirements.txt

Background data mining process
Auth, billing, payment modules
VM instance for app
参考资料
https://gist.github.com/1400023
Thanks, Q/A?

Contenu connexe

En vedette (6)

111218 zhtechparty-zd-浅谈symbian开发
111218 zhtechparty-zd-浅谈symbian开发111218 zhtechparty-zd-浅谈symbian开发
111218 zhtechparty-zd-浅谈symbian开发
 
Virtualbox
VirtualboxVirtualbox
Virtualbox
 
Xen Cloud Platform at Build a Cloud Day at SCALE 10x
Xen Cloud Platform at Build a Cloud Day at SCALE 10x Xen Cloud Platform at Build a Cloud Day at SCALE 10x
Xen Cloud Platform at Build a Cloud Day at SCALE 10x
 
Virtual Deep-Dive: Citrix Xen Server
Virtual Deep-Dive: Citrix Xen ServerVirtual Deep-Dive: Citrix Xen Server
Virtual Deep-Dive: Citrix Xen Server
 
Virtualizimi
VirtualizimiVirtualizimi
Virtualizimi
 
Presentation bringing xen server to mission critical system
Presentation   bringing xen server to mission critical systemPresentation   bringing xen server to mission critical system
Presentation bringing xen server to mission critical system
 

Similaire à 陈正 Introduction to-sae_python

Android mobile app security offensive security workshop
Android mobile app security   offensive security workshopAndroid mobile app security   offensive security workshop
Android mobile app security offensive security workshop
Abhinav Sejpal
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
catherinewall
 
Application Services On The Web Sales Forcecom
Application Services On The Web Sales ForcecomApplication Services On The Web Sales Forcecom
Application Services On The Web Sales Forcecom
QConLondon2008
 
App engine devfest_mexico_10
App engine devfest_mexico_10App engine devfest_mexico_10
App engine devfest_mexico_10
Chris Schalk
 
Social ent. with java on heroku
Social ent. with java on herokuSocial ent. with java on heroku
Social ent. with java on heroku
Anand B Narasimhan
 
SOM_MAS
SOM_MASSOM_MAS
SOM_MAS
SOM K
 

Similaire à 陈正 Introduction to-sae_python (20)

Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...
 
Google App Engine for Java v0.0.2
Google App Engine for Java v0.0.2Google App Engine for Java v0.0.2
Google App Engine for Java v0.0.2
 
Android mobile app security offensive security workshop
Android mobile app security   offensive security workshopAndroid mobile app security   offensive security workshop
Android mobile app security offensive security workshop
 
Web application penetration testing lab setup guide
Web application penetration testing lab setup guideWeb application penetration testing lab setup guide
Web application penetration testing lab setup guide
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
 
Application Services On The Web Sales Forcecom
Application Services On The Web Sales ForcecomApplication Services On The Web Sales Forcecom
Application Services On The Web Sales Forcecom
 
App engine devfest_mexico_10
App engine devfest_mexico_10App engine devfest_mexico_10
App engine devfest_mexico_10
 
Continuous Deployment: The Dirty Details
Continuous Deployment: The Dirty DetailsContinuous Deployment: The Dirty Details
Continuous Deployment: The Dirty Details
 
Social ent. with java on heroku
Social ent. with java on herokuSocial ent. with java on heroku
Social ent. with java on heroku
 
ragi_tutorial_v1
ragi_tutorial_v1ragi_tutorial_v1
ragi_tutorial_v1
 
ragi_tutorial_v1
ragi_tutorial_v1ragi_tutorial_v1
ragi_tutorial_v1
 
Hybrid application development
Hybrid application developmentHybrid application development
Hybrid application development
 
Integrating WordPress With Web APIs
Integrating WordPress With Web APIsIntegrating WordPress With Web APIs
Integrating WordPress With Web APIs
 
Social Enterprise Java Apps on Heroku Webinar
Social Enterprise Java Apps on Heroku WebinarSocial Enterprise Java Apps on Heroku Webinar
Social Enterprise Java Apps on Heroku Webinar
 
Liferay Devcon presentation on Workflow & Dynamic Forms
Liferay Devcon presentation on Workflow & Dynamic FormsLiferay Devcon presentation on Workflow & Dynamic Forms
Liferay Devcon presentation on Workflow & Dynamic Forms
 
Liferay Devcon Presentation on Dynamic Forms with Liferay Workflow
Liferay Devcon Presentation on Dynamic Forms with Liferay WorkflowLiferay Devcon Presentation on Dynamic Forms with Liferay Workflow
Liferay Devcon Presentation on Dynamic Forms with Liferay Workflow
 
SOM_MAS
SOM_MASSOM_MAS
SOM_MAS
 
Google App Engine for Java
Google App Engine for JavaGoogle App Engine for Java
Google App Engine for Java
 
WordCamp Bucharest 2017
WordCamp Bucharest 2017WordCamp Bucharest 2017
WordCamp Bucharest 2017
 
Google App Engine overview (GAE/J)
Google App Engine overview (GAE/J)Google App Engine overview (GAE/J)
Google App Engine overview (GAE/J)
 

Plus de Zoom Quiet

111218 zhtechparty-panda讲稿
111218 zhtechparty-panda讲稿111218 zhtechparty-panda讲稿
111218 zhtechparty-panda讲稿
Zoom Quiet
 
111218 zhtechparty-移动互联网产品需求分析
111218 zhtechparty-移动互联网产品需求分析111218 zhtechparty-移动互联网产品需求分析
111218 zhtechparty-移动互联网产品需求分析
Zoom Quiet
 

Plus de Zoom Quiet (20)

42qu thrift1
42qu thrift142qu thrift1
42qu thrift1
 
产品信息收集系统Infoc的演变
产品信息收集系统Infoc的演变产品信息收集系统Infoc的演变
产品信息收集系统Infoc的演变
 
Go courseday3
Go courseday3Go courseday3
Go courseday3
 
Go courseday2
Go courseday2Go courseday2
Go courseday2
 
Go courseday1
Go courseday1Go courseday1
Go courseday1
 
01s0401 go,互联网时代的c语言 许式伟
01s0401 go,互联网时代的c语言   许式伟01s0401 go,互联网时代的c语言   许式伟
01s0401 go,互联网时代的c语言 许式伟
 
Zoz pwned-by-the-owner-表惹程序猿
Zoz pwned-by-the-owner-表惹程序猿Zoz pwned-by-the-owner-表惹程序猿
Zoz pwned-by-the-owner-表惹程序猿
 
金山云查询系统改进之路1
金山云查询系统改进之路1金山云查询系统改进之路1
金山云查询系统改进之路1
 
Zh120226techparty zd-story
Zh120226techparty zd-storyZh120226techparty zd-story
Zh120226techparty zd-story
 
Zh120226techparty velocity2011-review
Zh120226techparty velocity2011-reviewZh120226techparty velocity2011-review
Zh120226techparty velocity2011-review
 
Zh120226techparty jeff kit-ios-toolbox
Zh120226techparty jeff kit-ios-toolboxZh120226techparty jeff kit-ios-toolbox
Zh120226techparty jeff kit-ios-toolbox
 
Velocity2011分享
Velocity2011分享Velocity2011分享
Velocity2011分享
 
111218 zhtechparty-panda讲稿
111218 zhtechparty-panda讲稿111218 zhtechparty-panda讲稿
111218 zhtechparty-panda讲稿
 
111218 zhtechparty-移动互联网产品需求分析
111218 zhtechparty-移动互联网产品需求分析111218 zhtechparty-移动互联网产品需求分析
111218 zhtechparty-移动互联网产品需求分析
 
ImpoImport this, that, and the other thing: custom importersrt not for_y
ImpoImport this, that, and the other thing: custom importersrt not for_yImpoImport this, that, and the other thing: custom importersrt not for_y
ImpoImport this, that, and the other thing: custom importersrt not for_y
 
Import this, that, and the other thing: custom importers
Import this, that, and the other thing: custom importersImport this, that, and the other thing: custom importers
Import this, that, and the other thing: custom importers
 
金山卫士界面框架
金山卫士界面框架金山卫士界面框架
金山卫士界面框架
 
111030 gztechparty-小路-云时代的mysql
111030 gztechparty-小路-云时代的mysql111030 gztechparty-小路-云时代的mysql
111030 gztechparty-小路-云时代的mysql
 
111030 gztechparty-小路-sophia
111030 gztechparty-小路-sophia111030 gztechparty-小路-sophia
111030 gztechparty-小路-sophia
 
080328 linux2 bsd
080328 linux2 bsd080328 linux2 bsd
080328 linux2 bsd
 

Dernier

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 

陈正 Introduction to-sae_python