Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
2009-douban-tech-story
Search
Zoom.Quiet
April 26, 2009
Technology
110
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
2009-douban-tech-story
2009年 洪教授回顾豆瓣架构经验
Zoom.Quiet
April 26, 2009
More Decks by Zoom.Quiet
See All by Zoom.Quiet
PyCon2014China-Zhuhai-high performance
zoomquiet
0
210
PyCon2014China-Zhuhai-meta programming
zoomquiet
1
180
PyCon2014China-Zhuhai-bpm.py
zoomquiet
0
160
PyCon2014China-Zhuhai-luna kv db
zoomquiet
0
150
PyCon2014China-Zhuhai-seed studio
zoomquiet
0
150
PyCon2014China-Zhuhai-Docker Registry Build By Python
zoomquiet
0
170
PyCon2014China-Zhuhai-jeff
zoomquiet
0
160
PyCon2014China-Zhuhai-pythonic front-end
zoomquiet
0
200
DevFest2014-Zhuhai-Polymer
zoomquiet
0
490
Other Decks in Technology
See All in Technology
顧客の成果創出とプロダクトの成長を 両立するためのFDE
sansantech
PRO
0
520
Claude Designがめちゃくちゃ便利なので使ってほしい
diggymo
0
170
OpenClawでAzure DevOpsのWiki更新を自動化する - クラウドAIだけでは届かない場所へ
yutakaosada
0
130
ログラスのマルチプロダクトを 支える認証基盤 〜テナントごとに異なる統制とどう向き合うか〜
dada4386
3
250
Making AI Agents Safe and Fast- Jev, Obsidian, and the Meta-Harness
x5gtrn
PRO
0
170
認知負荷を吸収し、プロダクトをまたぐPR Preview基盤の設計事例
taiki45
2
550
Confitura 2026
logico_jp
0
110
ボードゲームの遊び相手をFoundation Modelsで作る / iOSDC Japan 2026
genda
0
240
人にやさしく、AIにやさしく、書き手を選ばないIaCのガードレール再考 / Rethinking IaC Guardrails for Humans and AI Alike
kohbis
5
1.8k
「今盗んで、後で解く」に備える ― AWSのポスト量子暗号入門
yama3133
2
280
20260930_Gemma4_Hands-on
tsho
0
170
地方移住と都心キャリアの両立は「金・時間・人」のリソースをフル活用すれば実現できる!〜Snowflake女子会 vol.8
snowwmn0824
0
140
Featured
See All Featured
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8k
WCS-LA-2024
lcolladotor
0
840
What's in a price? How to price your products and services
michaelherold
247
13k
How to make the Groovebox
asonas
2
2.5k
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
400
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Scaling GitHub
holman
464
140k
Documentation Writing (for coders)
carmenintech
77
5.5k
Thoughts on Productivity
jonyablonski
76
5.4k
How to build a perfect <img>
jonoalderson
1
6k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.5k
Making Projects Easy
brettharned
120
6.8k
Transcript
ϵຩඌࡏܒ֥ ؿᅚӱ 2009.4 ޠ఼ୡ
[email protected]
ϵຩࡥࢺ • 2005୍3ᄅഈཌ • ၛٳཚބؿགྷູ ނྏ֥ഠ • a႕aၻ ুaཬቆa Ӭaࣴׄ
• ֥ϵaႶਣ
၂ུඔऌ • 2.9MᇿҨႨđჿ1/4ࠃᄁႨ • తຣࠩ٤ᇿҨႨ • 23M౨/฿đڂᆴ500~600/sec • 23௴๙PCڛༀఖ(1U*15/2U*8) •
12ิ܂ཌഈڛༀ • 38G memcached
ֆڛༀఖ • ֆ1Uڛༀఖ (frodo) • ֆނAMD Athlon 64 1.8GHz •
1Gଽթđ160G SATA*2 • Gentoo Linux • MySQL 5 • Quixote (a Python web framework) • Lighttpd + SCGI (shire) • Memcached (!)
Gentoo Linux • ಸၞົ • emerge mysql • ebuild ьႿܵ
patch • ᆺνልླေ֥ת༆ • νಆྟ • GLSA(Gentoo Linux Security Advisories)
MySQL • The world’s most popular open source database •
ཿഒ؟/ཿ؟ഒ ==> MyISAM • ཿѩؿۚ ==> InnoDB • Replicate for backup
Python • षؿ • Battery Included • ֻٚ९Ӯඃ • ഠӮӉᇏ
• CPUG: http://python.cn/
Quixote • ࡥֆđਈđၞႿൌགྷRESTڄ֥۬URL • ֒ൈߎીႵDjango, TurboGears, Pylonsᆃུ࿊ᄴđᆺႵ၂ ۱Шᇗ֥ZOPE • http://www.douban.com/subject/1000001
# luz/subject/__init__.py def _q_lookup(request, name): subject = get_subject(name) return lambda req: subject_ui(req, subject) # luz/subject/subject_ui.ptl def subject_ui [html] (request, subject): site_header(request) “<h1>%s</h1>” % subject.title site_footer(request)
Lighttpd • ޓݺ֥ބ࣡ྟି • ჰളSCGIᆦӻ • SCGI: ၂۱ࡥ߄ϱЧ֥FastCGIđႮ Quixoteषؿᆀषؿ •
෮Ⴕ֥౨๙ݖ80؊१֥lighttpdࣉӱ ٳؿđଽಸሼSCGI֞localhostഈ֥ Quixoteࣉӱb
Memcache • ՖഈཌఏࣼᄝႨđႵིࡨMySQLڵք • ؓlibmemcacheቓਔpythonٿልčႨPyrexĎđྟି൞ Ղpythonϱ֥3x+ def get_subject(subject_id): subject =
mc.get(‘s:’+subject_id) if subject is None: store.farm.execute(“select xxx, xxx from subject where id=%s”, subject_id) subject = Subject(*store.farm.fetchone()) mc.set(‘s:’+subject_id, subject) return subject
Internet MySQL Lighttpd App SCGI Memcache Static Files FS
໙ีԛགྷ • 1.2M౨/฿ • ՈIOӮູ࣠ • ླေ࿙ᅳྍࠏٜ
ࢳथٚσ • ܓઙਆ1Uڛༀఖ • pippin ބ meriadoc (ުڿmerry) • චނ,
4Gଽթđ250G SATA*3 • ၂ቔູႋႨڛༀఖđ၂ቔູඔऌ९ڛༀఖ • థ၍֞චཌචIPࠏٜđႨDNSࢳ༅҂ຩ؍ IP -_-b • ष؟ದླྀቔषؿđfrodoቓູषؿႨࠏ (subversion, trac, etc...)
Internet DNS Lighttpd (!") Lighttpd (#$) App MySQL HTTP Proxy
Memcache Static Files FS SCGI
ࠫׄؿགྷ • ඔऌ९֥ଽթٳؓྟି႕ཙᇗն • innodb_buffer_pool_size • Ոෛࠏ࿙֡؇бਈ۷ᇗေ • ຩഈᅳট֥IP؍ٳ҃ޓ҂ौ௶
໙ีԛགྷ • 1.5M౨/฿đഉໃ֞ྟି࣠ • ࠏٜ҂ौ௶đَܣᅰ • IP؍ٳ҃ඔऌ҂ौ௶đႨّ႘٠໙ߏત
ࢳथٚσ • ߐ֞ौ௶֥ࠏٜđ؟ཌֆIP(BGP) • ܓઙਔ၂ྍڛༀఖ (arwen) • 74G 1wሇ SATA
* 3 • ቓູඔऌ९ڛༀఖ • षႨህ֥ڛༀఖቔު࠹ෘ
Internet Lighttpd App Memcache Data Mining MySQL Master MySQL Slave
Replicate Static Files SCGI read write
໙ีԛགྷ • 2M౨/฿ • ࣡໓ࡱڛༀՈIOӮູ࣠ • ഈϤຣ֥ཬோčႨཞaٿ૫ ோ, etc...Ď •
ඔऌ९ڛༀఖࢤ࣍࣠
ࢳथٚσ • ܓઙڛༀఖđචނđ4Gđ250G SATA*3 • ࡼோՖ၂۱նଢ్ٳӮ10000۱໓ࡱ၂۱ଢ • mod_rewriteЌӻURL҂э • ৫֥ோlighttpdࣉӱđఓႨmod_memcacheଆॶđ
ߏթཬோ • ࡨཬՈIO်ؓ૫٠໙֥႕ཙ • ࡼႋႨڛༀՖwebڛༀఖ৫ԛಀ • Ϝ۷؟֥ଽթٳ۳࣡໓ࡱڛༀ • ᄹࡆ၂۱ᆺඔऌ९
Web Service Internet Lighttpd App Memcache MySQL Master MySQL Slave
Replicate Static Files Lighttpd WebDAV WebDAV SCGI !"#$% Memcache Spiders Data Mining MySQL Slave Replicate Lighttpd (w/ mod_memcache) HTTP Proxy store.farm store.farmr write read
ᆺඔऌ९ • storeᄹࡆfarmrඋྟđູ၂۱ॖႨ֥ᆺඔऌ९Ⴓѓ • ฮ֥replicate delay໙ี • ڣ९گᇅླေൈࡗ • ۷ྍᇶ९ުđ༯၂۱౨ສສࣼ൞ေඔऌč۷ྍඔऌު
ྍ်૫Ď • Ֆڣ९߶֝ᇁcacheթ٢֥൞ࣸඔऌ • ਲၳ൙ࡱĆ • ࢳथٚمğ۷ྍඔऌ९ުđᄝყ௹ॖି߶ઔഈႨ֥֞౦ঃ༯đᇶ ྍߏթ • ......҂ປૅđbut it works
х૧replicate delayႄ ఏ֥ਲၳ൙ࡱ def get_subject(sid): sbj = mc.get(‘s:’+sid) if sbj
is None: sbj = flush_subject(sid, store.farmr) return sbj def flush_subject(sid, cursor=None): cursor = cursor or store.farm cursor.execute(“select ... from subject”) subject = Subject(*cursor.fetchone()) mc.set(‘s:’+sid, subject) return subject def update_subject(subject, props): store.farm.execute(“update subject ...”) store.farm.connection.commit() flush_subject(subject.id, store.farm)
໙ีԛགྷ • 2.5M౨/฿ • ඔऌ९Ոॢࡗ҂ܔਔ • ഈ/ࣴׄඔऌਈஔն • SATAܣᅰੱۚ •
ඔऌ९৯ᄹն
ࢳथٚσ • Scale Upđܓઙඹ1Uڛༀఖ • 16Gଽթđ147G SCSI *2 + 500G
SATA • SCSI ቓ RAID-0 • ႨMySQL SlaveটЌᆣჅ • ᄹࡆmemcachedࢫׄඔଢ • ෮Ⴕ֥MyISAMіڿູInnoDBі • ิۚଽթ০Ⴈིੱ • ࡼಆ໓ෆ෬၍ᇀSphinx
Internet Lighttpd App Memcache MySQL Master MySQL Slave Replicate Static
Files Lighttpd WebDAV WebDAV SCGI Memcache Spiders Lighttpd (w/ mod_memcache) HTTP Proxy store.farm store.farmr Sphinx Web Service Memcache Memcache Web Service
໙ีԛགྷ • 5.2M౨/฿ • ோੀਈٮႨӮູቋնӮЧ • Webڛༀఖ֥ՈIOߎ൞߶႕ཙ် ૫ྟି • ႋႨڛༀఖࣉӱඔ҂ܔਔ
• ࠏ݊ॢࡗ҂ܔਔ
ࢳथٚσ • ฿ࣃ֥ࠏٜьၒ၂ུ :) • ӵքோੀਈ • ުඔऌड࠹ෘ • ಸᄙСٺ
• ܓઙ31Uڛༀఖğ4ނđ32Gଽթđ1T SATA * 3 • Ⴊ߄భ؊đఓႨ otho.douban.com ބ lotho.douban.com თ • lighttpd 1.5 with aio support • ҆ඇLVS • Scale Up: ႋႨڛༀఖଽթശࠩ 4G -> 8G
Internet Lighttpd Static Files Lighttpd WebDAV Lighttpd HTTP Proxy Lighttpd
1.5 (w/ mod_cache) Lighttpd 1.5 (w/ mod_cache) LVS LB (Master) LVS LB (backup) Keepalived www.douban.com otho.douban.com
MySQL Master MySQL Slave Replicate !"#$% Data Mining !"#$% Data
Mining MySQL Slave replicate read read write write
໙ีԛགྷ • 6.4M౨/฿ (5M PV) • ႋႨڛༀఖӮູ࣠ • ଽթğᅝႨሹ൞ᄹӉđරެႵଽթ྄
• CPUğmemcacheؓའਙ߄/ّਙ߄
ࢳथٚσ • ֻؽႋႨڛༀఖഈཌ • lighttpd֥mod_scgiᆺିround-robin • lighttpd 1.5҂໗ק • mod_proxy
• proxy.balance = fair (load based, passive balancing) • ֒ࣉӱᅝႨଽթӑݖᚐᆴđ֒భ౨ປӮުሱ೪ • Ⴈspreadऊކರᆽ
Lighttpd Static Files Lighttpd WebDAV Lighttpd HTTP Proxy App Memcache
Lighttpd App Memcache Lighttpd Internet SCGI SCGI HTTP Proxy HTTP Proxy Log Aggregator spread spread
໙ีԛགྷ • 11M౨/฿č3ႋႨڛༀఖĎ • ॴࠏٜཿೆӮູު࠹ෘ֥࣠ • Sphinx֥קᇅྟ҂ܔ • ཌྷҨӁषؿᇏđླေࢳथோթԥ໙ ี
• ਲၳགྷའğ ຩᅟэતđࠒᄟਔնਈ৵ࢤ ֤҂֞ԩđloadಏ҂ۚ
ࢳथٚσ • ඔऌ९ٳ९ • ࣴׄཌྷܱі৫ԛট • ඔऌडཌྷܱі৫ԛটđᇶ९٢ᄝ ฿ࣃđКࣘᆺ • Sphinx
-> Xapian • ႨMogileFS
!" Master #$ Master %&'() Data Mining %&'() Data Mining
#$ Slave !" Slave *+,- Slave !" Slave #$ Slave *+,- Master replicate write write replicate replicate read read replicate replicate
؟ඔऌ९৵ࢤ • іಆअື၂đົ၂۱іᇀඔऌ९֥႘ഝ • store.farm[r] -> store.get_cursor(table=‘xxx’, ro=True/False) def flush_subject(sid,
ro=False): cursor = store.get_cursor(table=‘subject’, ro=ro) cursor.execute(“select ... from subject”) subject = Subject(*cursor.fetchone()) mc.set(‘s:’+sid, subject) return subject • ᄝඔऌ९ࡗ୳іэ֤ಸၞđᄝᇶڣ९ࡗޙڵ ᄛ္э֤ಸၞ
MogileFS Master Uploader MogileFS Node MogileFS Node nginx (w/ proxy_store)
MogileFS Tracker FileStorage Gateway Internet upload.douban.com otho.douban.com App signed POST form HTTP redirect
ࢳथٚσč࿃Ď • libmemcache -> libmemcachedđႨconsistent hashࢆ֮memcacheטᆜսࡎ • ྩᆞlibmemcached֥consistent hashཌྷܱbug •
ႋႨڛༀఖശࠩᇀඹނCPU • ྩᆞlibmemcached֥failoverཌྷܱbug • Ⴈnginxูսlighttpdቓload balance • ቋުؿགྷቌঊࠋ൮൞spreadđ⯝ • ڿӮႨnginx࠺ರᆽ
Consistent Hash ோϱಃඋႿcharlee http:// tech.idv2.com/2008/07/24/ memcached-004/
Lighttpd Static Files Lighttpd WebDAV Lighttpd HTTP Proxy App Lighttpd
Internet SCGI HTTP Proxy Nginx HTTP Proxy App Lighttpd SCGI HTTP Proxy App Lighttpd SCGI HTTP Proxy
໙ีԛགྷ • 13M౨/฿ • ࠹߃ࡼ෮Ⴕ࣡ோ֝ೆMogileFS • ໓ࡱཬđඔਈնđTracker DBॖିӮູ ࣠ •
ཌྷҨӁޓ൳ߋ႒đթԥॢࡗषࣅᅦ
ࢳथٚσ • ܓઙ8ྍڛༀఖ • 32GଽթđඹނCPU • (300G SCSI×2 + 1T
SATA) × 3 • (1T SATA × 3) × 5 • 6Кࣘđ2฿ࣃ • षؿDoubanFS
DoubanFS • ીႵᇏྏඔऌ९đᆰࢤοᅶ໓ࡱhashҰᅳ෮ᄝࢫ ׄđॖഥ෪ྟ۷ݺ • οᅶhashᆴթӮଢඎđૄ۱ࢫׄڵᄳ၂ቆhashᆴ თ • קൈ҄đࠎႿ໓ࡱྩڿൈࡗ֥Merkle Tree
• ০Ⴈconsistent hashࡨഒᄹࢫׄջট֥ඔऌ၍ਈ • WebDAVቔູཿࢤ१ • ྟିູMogileFS֥3Пđཿྟିູ50П
Merkle Tree
Uploader DoubanFS Node DoubanFS Node nginx (w/ proxy_store) FileStorage Gateway
Internet upload.douban.com otho.douban.com App signed POST form HTTP redirect
໙ีԛགྷ • 16M౨/฿ • ඔऌ९ն໓Чሳ؍ᇗ႕ཙਔඔऌ९ྟ ି • DoubanFSᇏཬோ֝ᇁIOᄹۚ • ඔऌ९ॖႨྟေิۚ
ࢳथٚσ • षؿDoubanDB • ۷ݺ֥ഥ෪ྟ • ն໓Чሳ؍၍ԛުđMySQL֥ྟି֤֞ ᄹ఼ • MySQLචMasterٚσ
• failover۷ࡥֆ • ࢳथreplicate delay໙ี
DoubanDB • ٳ҃ൔKey-Valueඔऌ९ • ՖAmazon Dynamoࠆ֤ਲۋđቓਔ၂ུࡥ߄ • ۱ࢤ१ğset(key, value), get(key),
delete(key) • memcacheླྀၰቔູཿࢤ१ • ᆇᆞ֥Merkle TreeđࠎႿଽթđުڿູࠎႿՈ໓ࡱ • Consistent Hash • ႨTokyoCabinetቓָູҪթԥ • ඔऌ९ᇏ֥ն໓Чሳ؍ࣉೆDoubanDB • DoubanFS 2.0 ࠎႿ DoubanDB ൌགྷ
ோϱಃඋႿcharlee http:// tech.idv2.com/2008/07/24/ memcached-004/
!" Master1 #$ Master1 %&'() Data Mining %&'() Data Mining
#$ Master2 !" Master2 *+,- Slave !" Slave #$ Slave *+,- Master replicate write write replicate replicate read read replicate replicate
ቋྍ֥၂ུڿ • ࡼDoubanFSބඔऌडӱ၍߭Кࣘࠏٜ • ࡥ߄໓ࡱഈԮੀӱބս • ۷ݺ֥০Ⴈ႗ࡱሧჷ • Ⴈngnixቔູቋభ؊ •
www.douban.com္҆ඇLVS • ႨRabbitMQսูspread
၂ུࣜဒ • Ϝఫᄝଽթഈ൞ᆴ֤֥ • ࡹ৫ਅݺ֥profile۽ऎđѩ০Ⴈᆭ • memcacheѩ҂৷ࡎđር༥॥ᇅcache֥ؓའնཬ ބ٠໙ٚൔ • х૧ඔऌ९֥joinҠቔ
• ᄝӁഈቓԛཋᇅၛх૧ݖત֥Ұ࿘ • ር༥ҷٳభުᄎෘ • Ⴈၘᅧ֥ඌࢳथ໙ี
྆྆