Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
2009-douban-tech-story
Search
Zoom.Quiet
April 26, 2009
Technology
99
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
190
PyCon2014China-Zhuhai-meta programming
zoomquiet
1
170
PyCon2014China-Zhuhai-bpm.py
zoomquiet
0
150
PyCon2014China-Zhuhai-luna kv db
zoomquiet
0
140
PyCon2014China-Zhuhai-seed studio
zoomquiet
0
140
PyCon2014China-Zhuhai-Docker Registry Build By Python
zoomquiet
0
160
PyCon2014China-Zhuhai-jeff
zoomquiet
0
140
PyCon2014China-Zhuhai-pythonic front-end
zoomquiet
0
170
DevFest2014-Zhuhai-Polymer
zoomquiet
0
480
Other Decks in Technology
See All in Technology
白金鉱業Meetup_Vol.24_「AIエージェントは分けるほど良い」は本当か? / Is it true that “the more you divide AI agents, the better”?
brainpadpr
1
410
ザ・データベース、MySQL ~ OSC 2026 Sendai ~
sakaik
0
130
気づかぬうちにセキュリティ負債を生むAPIキー運用
sgwrmctk
0
180
10年間のブログ発信を振り返って見えたWebアプリケーションエンジニアとしての軌跡
stefafafan
0
160
不要なレビューをAIにまかせて AIコーディングの環境改善を加速した
shoota
1
220
攻撃者視点で考えるDetection Engineering
cryptopeg
3
2k
AI-DLCを “そのまま導入しなかった”話 ~組織に合わせてアジャストした 私たちの実践共有~
hiroramos4
PRO
0
170
入門!AWS Blocks
ysuzuki
1
160
MUSUBI 田中裕一『AIと共に行う「しごとのリデザイン」- スモールバックオフィス編』AI Ops Lab #4
musubi
0
250
Claude Codeをどのように キャッチアップしているか
oikon48
13
8.5k
ロボティクスの技術 / Robotics Technology
ks91
PRO
0
100
SONiC Scale-Up Working Group から探る Scale-UpやUltraEthernet機能の実装方法
ebiken
PRO
2
410
Featured
See All Featured
Game over? The fight for quality and originality in the time of robots
wayneb77
1
200
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
350
WCS-LA-2024
lcolladotor
0
650
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
Done Done
chrislema
186
16k
Mind Mapping
helmedeiros
PRO
1
250
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
580
Raft: Consensus for Rubyists
vanstee
141
7.5k
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
30 Presentation Tips
portentint
PRO
1
330
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Ҡቔ
• ᄝӁഈቓԛཋᇅၛх૧ݖત֥Ұ࿘ • ር༥ҷٳభުᄎෘ • Ⴈၘᅧ֥ඌࢳथ໙ี
྆྆