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
Webアプリケーションのキャッシュ戦略とそのパターン / Pattern and Strate...
Search
moznion
March 04, 2017
Technology
71
350k
Webアプリケーションのキャッシュ戦略とそのパターン / Pattern and Strategy of Web Application Caching
YAPC::Kansai OSAKA 2017の資料です
moznion
March 04, 2017
Tweet
Share
More Decks by moznion
See All by moznion
Perl 5 OOP機構30年史 - Perl 5's OOP Mechanism over the past 30 years
moznion
1
770
RuboCopのカスタムCopを書いてContributionしてみる - Contributing a Custom Cop to RuboCop: A Hands-on Experience
moznion
0
48
AWS上に構築する メンテ容易なElasticsearch System / Maintainable Elasticsearch system on AWS
moznion
2
3.9k
PROXY Protocol aware Proxy Server on Node.js
moznion
2
2.4k
Perl meets AWS Lambda
moznion
0
4.6k
ソフトウェア開発における 「設計」と「パフォーマンス」の相互作用 / Interaction Between Design and Performance on Software Development
moznion
11
6.8k
Javaカードの世界 / The world of Java Card
moznion
8
13k
無限にスケールする上に自律的なJenkinsに見る夢~AWS篇~ / Dream of autonomous and infinite scalable Jenkins with AWS
moznion
21
6.9k
The World of Inline Module
moznion
0
5.3k
Other Decks in Technology
See All in Technology
10Xでのデータ基盤の変遷とこれから: データマネジメントのリアル 〜BtoB企業3社の歩みとこれから〜
10xinc
6
1.2k
【shownet.conf_】持続可能な次世代Wi-Fi運用に向けて
shownet
PRO
0
240
k6を活用した再現性・拡張性の高い負荷試験基盤の構築
biwashi
11
2.8k
成果のためのコミュニケーション - 語彙を育てよう -/communication-for-good-outcome-developing-vocabulary
hassaku63
3
130
AWS Lambdaで実現するスケーラブルで低コストなWebサービス構築/YAPC::Hakodate2024
fujiwara3
3
530
スモールスタート、不都合な真実 〜 耳当たりの良い言葉に現場が振り回されないために/20240930-ssmjp-small-start
opelab
12
1.7k
【インフラエンジニアbooks】30分でわかる「AWS継続的セキュリティ実践ガイド」
hssh2_bin
1
460
映像・音声伝送システム
jtes
0
190
Authenticator のエミュレーションによる パスキーのログインテスト/nikkei-tech-talk-25
nikkei_engineer_recruiting
0
140
【shownet.conf_】ShowNet x 宇宙ネットワーク
shownet
PRO
0
290
Consoles, printk, Nested-NMIs_ Oh my!
ennael
PRO
0
150
第45回 MLOps 勉強会 - ML Test Score を用いた機械学習システムの定量的なアセスメント
masatakashiwagi
2
130
Featured
See All Featured
It's Worth the Effort
3n
183
27k
Designing for Performance
lara
604
68k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
30
2.6k
Bootstrapping a Software Product
garrettdimon
PRO
304
110k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
225
22k
Embracing the Ebb and Flow
colly
83
4.4k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
663
120k
Bash Introduction
62gerente
608
210k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
91
16k
The Cost Of JavaScript in 2023
addyosmani
43
5.8k
Web development in the modern age
philhawksworth
205
10k
Transcript
WebΞϓϦέʔγϣϯͷ Ωϟογϡઓུͱ ͦͷύλʔϯ @moznion
None
໔ ੈͷத৭ʑͳέʔε͕͋Γ·͔͢Β શͯΛΧόʔ͢Δ༰ແཧͰͨ͠ ͜ͷ༰҃ΔҰྫͩͱࢥͬͯ ϦϥοΫεͯ͠ோΊ͍ͯͩ͘͞
@moznion Web application server side engineer Twitter: @moznion GitHub: moznion
Ωϟογϡ
ࠓճ͢͜ͱ - WebΞϓϦέʔγϣϯʹ͓͚ΔΩϟογϡʹ͍ͭͯ - HTTPϨΠϠͰͷΩϟογϡ - ΞϓϦέʔγϣϯϨΠϠͰͷΩϟογϡ - ΩϟογϡΛΊΑ͏
લఏ: ߴͳ (Web) ΞϓϦέʔγϣϯΛ ߏஙɾӡ༻͍ͯ͘͠ඞཁ͕͋Δ
Ωϟογϡͱͳʹ͔ʁ
Ωϟογϡʁ ʮΩϟογϡ: ΛӅͨ͠Γ֨ೲͨ͠Γ͓ͯ͘͠ͷʹ҆શͳॴʯ ― Webster ৽ੈքถޠࣙయɼΧϨοδ൛ ୈ3൛ ʮΩϟογϡͱௐΔඞཁͷ͋ΔͷΛஔ͍͓ͯ҆͘શͳॴͷ ͜ͱͰ͋ΔɽΩϟογϡͱ͍͏༻ޠɼ࠷ॳͷ༻ίϯϐϡʔλʹ ͓͍ͯɼϓϩηοαͱओهԱͱͷؒʹૠೖ͞ΕͨهԱ֊ϨϕϧΛ
දͨ͢Ίʹ༻͞Εͨɽ(தུ) ͜ͷ༻ޠࠓͰࢀরͷہॴੑΛ ར༻͢ΔΑ͏ʹཧ͞ΕͨҙͷهԱΛࢦͯ͠༻͞ΕΔʯ ― σΠϏου A ύλʔιϯ, δϣϯ ̡ ϔωγʔ ஶ, ా ޫজ ༁ ίϯϐϡʔλͷߏͱઃܭɼୈ5൛ [Լ] ❞ ❞
ͳΔ΄Ͳ…
લఏ: ߴͳ (Web) ΞϓϦέʔγϣϯΛ ߏஙɾӡ༻͍ͯ͘͠ඞཁ͕͋Δ
લఏ: ߴͳ (Web) ΞϓϦέʔγϣϯΛ ߏஙɾӡ༻͍ͯ͘͠ඞཁ͕͋Δ
Ωϟογϡʁ ʮΩϟογϡ: ΛӅͨ͠Γ֨ೲͨ͠Γ͓ͯ͘͠ͷʹ҆શͳॴʯ ― Webster ৽ੈքถޠࣙయɼΧϨοδ൛ ୈ3൛ ʮΩϟογϡͱௐΔඞཁͷ͋ΔͷΛஔ͍͓ͯ҆͘શͳॴͷ ͜ͱͰ͋ΔɽΩϟογϡͱ͍͏༻ޠɼ࠷ॳͷ༻ίϯϐϡʔλʹ ͓͍ͯɼϓϩηοαͱओهԱͱͷؒʹૠೖ͞ΕͨهԱ֊ϨϕϧΛ
දͨ͢Ίʹ༻͞Εͨɽ(தུ) ͜ͷ༻ޠࠓͰࢀরͷہॴੑΛ ར༻͢ΔΑ͏ʹཧ͞ΕͨҙͷهԱΛࢦͯ͠༻͞ΕΔʯ ― σΠϏου A ύλʔιϯ, δϣϯ ̡ ϔωγʔ ஶ, ా ޫজ ༁ ίϯϐϡʔλͷߏͱઃܭɼୈ5൛ [Լ] ❞ ❞
Ωϟογϡʁ ʮΩϟογϡ: ΛӅͨ͠Γ֨ೲͨ͠Γ͓ͯ͘͠ͷʹ҆શͳॴʯ ― Webster ৽ੈքถޠࣙయɼΧϨοδ൛ ୈ3൛ ʮΩϟογϡͱௐΔඞཁͷ͋ΔͷΛஔ͍͓ͯ҆͘શͳॴͷ ͜ͱͰ͋ΔɽΩϟογϡͱ͍͏༻ޠɼ࠷ॳͷ༻ίϯϐϡʔλʹ ͓͍ͯɼϓϩηοαͱओهԱͱͷؒʹૠೖ͞ΕͨهԱ֊ϨϕϧΛ
දͨ͢Ίʹ༻͞Εͨɽ(தུ) ͜ͷ༻ޠࠓͰࢀরͷہॴੑΛ ར༻͢ΔΑ͏ʹཧ͞ΕͨҙͷهԱΛࢦͯ͠༻͞ΕΔʯ ― σΠϏου A ύλʔιϯ, δϣϯ ̡ ϔωγʔ ஶ, ా ޫজ ༁ ίϯϐϡʔλͷߏͱઃܭɼୈ5൛ [Լ] ❞ ❞ جຊతͳ֓೦ͱͯͦ͠ͷ௨Γ Ͱ͜Εϓϩηοαͷͩʂ
ࠓճ͞ͳ͍͜ͱ - WebΞϓϦέʔγϣϯҎ֎ͷΩϟογϡʹ͍ͭͯ - e.g - ϓϩηοαͷΩϟογϡ - DNSΩϟογϡʹ͍ͭͯࠓճ͠·ͤΜ -
ଞʹ৭ʑͳΛ͠·ͤΜ
WebΞϓϦέʔγϣϯʹ͓͚Δ Ωϟογϡͱͳʹ͔ʁ
WebΞϓϦέʔγϣϯʹ͓͚ΔΩϟογϡʁ αʔό͕ฦ͖͢ίϯςϯπʹ͍ͭͯ…… - 1࣍ετϨʔδΑΓߴͳετϨʔδʹ ஔ͓͍͔ͯͯͦ͜͠Βฦ͢ - ͘͠ฦ͞ͳ͍
WebΞϓϦέʔγϣϯʹ͓͚ΔΩϟογϡʁ ΞϓϦέʔγϣϯϨΠϠͰͷΩϟογϡ ߴͳετϨʔδܦ༝Ͱฦ͢ํ HTTPϨΠϠͰͷΩϟογϡ ϨεϙϯεΛฦ͞ͳ͍ํ
WebΞϓϦέʔγϣϯʹ͓͚ΔΩϟογϡʁ ΞϓϦέʔγϣϯϨΠϠͰͷΩϟογϡ ߴͳετϨʔδܦ༝Ͱฦ͢ํ HTTPϨΠϠͰͷΩϟογϡ ϨεϙϯεΛฦ͞ͳ͍ํ
ΞϓϦέʔγϣϯϨΠϠͰͷΩϟογϡ Server Client Primary Storage Heavy Component OR
ΞϓϦέʔγϣϯϨΠϠͰͷΩϟογϡ Server Client Primary Storage i ii iii iv i.
ϦΫΤετ ii. Ұ࣍ετϨʔδ͍߹Θͤ iii. ݁ՌΛฦ͢ iv. Ϩεϙϯε
ΞϓϦέʔγϣϯϨΠϠͰͷΩϟογϡ Server Client Primary Storage i ii iii iv i.
ϦΫΤετ ii. Ұ࣍ετϨʔδ͍߹Θͤ iii. ݁ՌΛฦ͢ iv. Ϩεϙϯε ͕͜͜ωοΫ ͷ߹
ΞϓϦέʔγϣϯϨΠϠͰͷΩϟογϡ Server Client Primary Storage ii iii Cache Storage
ΞϓϦέʔγϣϯϨΠϠͰͷΩϟογϡ Server Client Primary Storage i ii iii iv i.
ϦΫΤετ ii. Ωϟογϡ͍߹Θͤ iii. ݁ՌΛฦ͢ iv. Ϩεϙϯε Cache Storage ii iii
ΞϓϦέʔγϣϯϨΠϠͰͷΩϟογϡ Server Client Primary Storage i ii iii iv i.
ϦΫΤετ ii. Ωϟογϡ͍߹Θͤ iii. ݁ՌΛฦ͢ iv. Ϩεϙϯε Cache Storage ii iii Ұ࣍ετϨʔδΑΓ Ωϟγϡ͕ߴͳΒ ૣ͘ฦͤΔ
ΞϓϦέʔγϣϯϨΠϠͰͷΩϟογϡ Server Client Primary Storage ii iii Ұ࣍ετϨʔδͱ ΩϟογϡετϨʔδ ͳΜΒ͔༰ͷ߹Λ
औΔඞཁ͕͋Δ Cache Storage
WebΞϓϦέʔγϣϯʹ͓͚ΔΩϟογϡʁ ΞϓϦέʔγϣϯϨΠϠͰͷΩϟογϡ ߴͳετϨʔδܦ༝Ͱฦ͢ํ HTTPϨΠϠͰͷΩϟογϡ ϨεϙϯεΛฦ͞ͳ͍ํ
HTTPϨΠϠͰͷΩϟογϡ ΩϟογϡͱɺϦιʔεͷʹج͍ͮͯɺҰऔಘͨ͠Ϧιʔ εΛΫϥΠΞϯτଆͰ͍·Θ͢ํࣜͰ͢ɻ ΩϟογϡͷརɺαʔόͱΫϥΠΞϯτؒͷ௨৴ΛݮΒ͢͜ͱ ͰωοτϫʔΫଳҬͷར༻ॲཧ࣌ؒΛॖখ͠ɺΑΓޮతʹॲཧ Ͱ͖Δ͜ͱͰ͢ɻ ― ࢁຊ ཅฏ ஶ
WebΛࢧ͑Δٕज़ - HTTPɺURIɺHTMLɺͦͯ͠REST (WEB+DB PRESS plus) ❞
HTTPϨΠϠͰͷΩϟογϡ Server Client contents
HTTPϨΠϠͰͷΩϟογϡ Server Client i ii i. ίϯςϯπ͘Εʙ ii. ͍Αʙ contents
HTTPϨΠϠͰͷΩϟογϡ Server Client i ii i. ίϯςϯπ͘Εʙ ii. ͍Αʙ contents
ίϯςϯπ͕ωοτϫʔΫʹΔ (serverͷཪଆͰߋʹॏ͍ॲཧ͕͍ͬͯΔ͔) contents
HTTPϨΠϠͰͷΩϟογϡ Server Client contents contents ΫϥΠΞϯτଆͰίϯςϯπΛอ࣋
HTTPϨΠϠͰͷΩϟογϡ Server Client contents contents i ii i. ίϯςϯπ͘Εʙ ii.
͏࣋ͬͯ·͢Α
HTTPϨΠϠͰͷΩϟογϡ Server Client contents contents i ii i. ίϯςϯπ͘Εʙ ii.
͏࣋ͬͯ·͢Α ίϯςϯπωοτϫʔΫʹΒͳ͍ ʮ͏࣋ͬͯ·͢Αʯͱ͍͏ใ͕Δ
HTTPϨΠϠͰͷΩϟογϡ ͨͩ͠ɺݹ͍ΩϟογϡΛར༻ͯ͠͠·͍ɺใͷ৴པੑ͕Լ͕Δ Մೳੑ͋Γ·͢ɻ ― ࢁຊ ཅฏ ஶ WebΛࢧ͑Δٕज़ - HTTPɺURIɺHTMLɺͦͯ͠REST
(WEB+DB PRESS plus) ❞
ࠓճओʹΞϓϦέʔγϣϯϨΠϠͷ Ωϟογϡͷ͕ଟ͍Ͱ͢ (HTTPϨΠϠͷͰڞ௨͢Δ͋Γ·͢)
ͳͥΩϟογϡΛ͏ͷ͔ʁ
ͳͥΩϟογϡΛ͏ͷ͔ʁ ϦΫΤετΛߴʹฦ٫͢ΔͨΊ Ϣʔβମݧͷ্ ୯Ґ࣌ؒ͋ͨΓͷॲཧΛ૿Ճͤ͞ΔͨΊ ܭࢉػϦιʔεͷར༻ޮ্ঢ ɹɹRequest per secondͷ૿Ճ ಛఆίϯϙʔωϯτ (e.g.
RDBMS) ͷෛՙݮͷͨΊ γεςϜͷ҆ఆӡ༻ (͔͠͠߹ʹґΔ)
ͳͥΩϟογϡΛ͏ͷ͔ʁ ϦΫΤετΛߴʹฦ٫͢ΔͨΊ Ϣʔβମݧͷ্ ୯Ґ࣌ؒ͋ͨΓͷॲཧΛ૿Ճͤ͞ΔͨΊ ܭࢉػϦιʔεͷར༻ޮ্ঢ ɹɹRequest per secondͷ૿Ճ ಛఆίϯϙʔωϯτ (e.g.
RDBMS) ͷෛՙݮͷͨΊ γεςϜͷ҆ఆӡ༻ (͔͠͠߹ʹґΔ)
ϦΫΤετΛߴʹฦ٫͢Δ Server Client Cache Storage ߴʹฦ٫͢Δ͜ͱͰ ετϨε͕গͳ͘ͳΓ ϢʔβʔମݧΞοϓʂ ⚡⚡⚡
ͳͥΩϟογϡΛ͏ͷ͔ʁ ϦΫΤετΛߴʹฦ٫͢ΔͨΊ Ϣʔβମݧͷ্ ୯Ґ࣌ؒ͋ͨΓͷॲཧΛ૿Ճͤ͞ΔͨΊ ܭࢉػϦιʔεͷར༻ޮ্ঢ ɹɹRequest per secondͷ૿Ճ ಛఆίϯϙʔωϯτ (e.g.
RDBMS) ͷෛՙݮͷͨΊ γεςϜͷ҆ఆӡ༻ (͔͠͠߹ʹґΔ)
୯Ґ࣌ؒ͋ͨΓͷॲཧͷ૿Ճ Server Client Cache Storage ୯Ґ࣌ؒ͋ͨΓͷॲཧ ૿ՃʹΑΓҰʹ ͨ͘͞ΜͷϦΫΤετΛ ͚͞Δ Client
Client . . .
ͳͥΩϟογϡΛ͏ͷ͔ʁ ϦΫΤετΛߴʹฦ٫͢ΔͨΊ Ϣʔβମݧͷ্ ୯Ґ࣌ؒ͋ͨΓͷॲཧΛ૿Ճͤ͞ΔͨΊ ܭࢉػϦιʔεͷར༻ޮ্ঢ ɹɹRequest per secondͷ૿Ճ ಛఆίϯϙʔωϯτ (e.g.
RDBMS) ͷෛՙݮͷͨΊ γεςϜͷ҆ఆӡ༻ (͔͠͠߹ʹґΔ)
ಛఆίϯϙʔωϯτͷෛՙܰݮ Server Client Client . . . Storage (৭ʑͳࣄ͕͋Γ) ετϨʔδʹෛՙ͕ूத͍ͯ͠Δʂ
ಛఆίϯϙʔωϯτͷෛՙܰݮ Server Client Client . . . Storage Cache Storage
ಛఆίϯϙʔωϯτͷෛՙܰݮ Server Client Client . . . Storage Cache Storage
Ωϟογϡʹಀ͕ͯ͠ Δ͜ͱͰ աෛՙίϯϙʔωϯτͷ ෛՙΛܰݮ͢Δ
ಛఆίϯϙʔωϯτͷෛՙܰݮ Server Client Client . . . Storage Cache Storage
͔͠͠Ωϟογϡίϯϙʔωϯτ͕ ૿͑Δ͜ͱͰγεςϜͱͯ͠ͷ ނোՄೳੑ૿Ճ͢Δʂ
ͳͥΩϟογϡΛ͏ͷ͔ʁ ϦΫΤετΛߴʹฦ٫͢ΔͨΊ Ϣʔβମݧͷ্ ୯Ґ࣌ؒ͋ͨΓͷॲཧΛ૿Ճͤ͞ΔͨΊ ܭࢉػϦιʔεͷར༻ޮ্ঢ ɹɹRequest per secondͷ૿Ճ ಛఆίϯϙʔωϯτ (e.g.
RDBMS) ͷෛՙݮͷͨΊ γεςϜͷ҆ఆӡ༻ (͔͠͠߹ʹґΔ)
ͳͥΩϟογϡΛ͏ͷ͔ʁ ϦΫΤετΛߴʹฦ٫͢ΔͨΊ Ϣʔβମݧͷ্ ୯Ґ࣌ؒ͋ͨΓͷॲཧΛ૿Ճͤ͞ΔͨΊ ܭࢉػϦιʔεͷར༻ޮ্ঢ ɹɹRequest per secondͷ૿Ճ ಛఆίϯϙʔωϯτ (e.g.
RDBMS) ͷෛՙݮͷͨΊ γεςϜͷ҆ఆӡ༻ (͔͠͠߹ʹґΔ) ͭ·ΓΧωʂʂʂ
ͳͥΩϟογϡΛ͏ͷ͔ʁ ϦΫΤετΛߴʹฦ٫͢ΔͨΊ Ϣʔβମݧͷ্ ୯Ґ࣌ؒ͋ͨΓͷॲཧΛ૿Ճͤ͞ΔͨΊ ܭࢉػϦιʔεͷར༻ޮ্ঢ ɹɹRequest per secondͷ૿Ճ ಛఆίϯϙʔωϯτ (e.g.
RDBMS) ͷෛՙݮͷͨΊ γεςϜͷ҆ఆӡ༻ (͔͠͠߹ʹґΔ) ͭ·ΓΧωʂʂʂ
ͳͥΩϟογϡΛ͏ͷ͔ʁ ϦΫΤετΛߴʹฦ٫͢ΔͨΊ Ϣʔβମݧͷ্ ୯Ґ࣌ؒ͋ͨΓͷॲཧΛ૿Ճͤ͞ΔͨΊ ܭࢉػϦιʔεͷར༻ޮ্ঢ ɹɹRequest per secondͷ૿Ճ ಛఆίϯϙʔωϯτ (e.g.
RDBMS) ͷෛՙݮͷͨΊ γεςϜͷ҆ఆӡ༻ (͔͠͠߹ʹґΔ) ͭ·ΓΧωʂʂʂ Ωϟογϡ͔ʂʁ
͍
ΩϟογϡΛͲͷΑ͏ͳ࣌ʹ͏͔
ΩϟογϡΛͲͷΑ͏ͳ࣌ʹ͏͔ - Ͳ͏ͬͯΫΤϦ͕͍ (৭ʑͳ͜ͱ͕͋Δ) - ৭ʑͳཧ༝ͰৗيΛҳͨ͠ྔͷΞΫηε͕͋Δ - ৭ʑ͋ͬͯ֎෦αʔϏεʹґଘ͍ͯ͠Δ - ͳͲͳͲ
ΩϟογϡΛͲͷΑ͏ͳ࣌ʹ͏͔ - Ͳ͏ͬͯΫΤϦ͕͍ (৭ʑͳ͜ͱ͕͋Δ) - ৭ʑͳཧ༝ͰৗيΛҳͨ͠ྔͷΞΫηε͕͋Δ - ৭ʑ͋ͬͯ֎෦αʔϏεʹґଘ͍ͯ͠Δ - ͳͲͳͲ
Ͳ͏ͬͯΫΤϦ͕͍ Server Client Client . . . RDBMS Slow Query
Ͳ͏ͬͯΫΤϦ͕͍ Server Client Client . . . RDBMS Slow Query.
Ͳ͏ͬͯΫΤϦ͕͍ Server Client Client . . . RDBMS Slow Query..
Ͳ͏ͬͯΫΤϦ͕͍ Server Client Client . . . RDBMS Slow Query…
Ͳ͏ͬͯΫΤϦ͕͍ Server Client Client . . . RDBMS Slow Query…
͜͜ͰαʔϏε͕٧·Δ (աෛՙͰDB͕μϯ͢Δ͔ʁ)
Ͳ͏ͬͯΫΤϦ͕͍ Server Client Client . . . RDBMS Cache
Ͳ͏ͬͯΫΤϦ͕͍ Server Client Client . . . RDBMS Cache Ωϟογϡʹಀ͕͢͜ͱͰ
ݱ࣮తͳ࣌ؒͰฦ͢ (ෛՙࢄͤ͞Δ)
ΩϟογϡΛͲͷΑ͏ͳ࣌ʹ͏͔ - Ͳ͏ͬͯΫΤϦ͕͍ (৭ʑͳ͜ͱ͕͋Δ) - ৭ʑͳཧ༝ͰৗيΛҳͨ͠ྔͷΞΫηε͕͋Δ - ৭ʑ͋ͬͯ֎෦αʔϏεʹґଘ͍ͯ͠Δ - ͳͲͳͲ
ৗيΛҳͨ͠ྔͷΞΫηε͕͋Δ Server . . . Storage Not slow request
ৗيΛҳͨ͠ྔͷΞΫηε͕͋Δ Server . . . Storage Not slow request!!!!!!
ৗيΛҳͨ͠ྔͷΞΫηε͕͋Δ Server . . . Storage Not slow request!!!!!! ܾ͍ͯ͠ϦΫΤετͰͳ͍͕
ϦΫΤετ͕ଟ͗ͯ͢ࡹ͖͖Εͳ͍
ৗيΛҳͨ͠ྔͷΞΫηε͕͋Δ Server . . . Storage Cache
ৗيΛҳͨ͠ྔͷΞΫηε͕͋Δ Server . . . Storage Cache ͬͱߴͳετϨʔδͰ ରԠͯ͠ͳΜͱ͔͢Δ (ྗ)
ৗيΛҳͨ͠ྔͷΞΫηε͕͋Δ Server . . . Storage Cache
ৗيΛҳͨ͠ྔͷΞΫηε͕͋Δ Server . . . Storage Cache ͦͦωοτϫʔΫͰ ٧·ΔՄೳੑ͕͋Δ
ৗيΛҳͨ͠ྔͷΞΫηε͕͋Δ Server . . . Storage Cache HTTPϨΠϠͷΩϟογϡΛͬͯ ʮฦ͞ͳ͍ʯඞཁ͕͋Δ͔
ΩϟογϡΛͲͷΑ͏ͳ࣌ʹ͏͔ - Ͳ͏ͬͯΫΤϦ͕͍ (৭ʑͳ͜ͱ͕͋Δ) - ৭ʑͳཧ༝ͰৗيΛҳͨ͠ྔͷΞΫηε͕͋Δ - ৭ʑ͋ͬͯ֎෦αʔϏεʹґଘ͍ͯ͠Δ - ͳͲͳͲ
֎෦αʔϏεʹґଘ͍ͯ͠Δ Server Client Client . . . Outer Service Request
(via HTTP)
֎෦αʔϏεʹґଘ͍ͯ͠Δ Server Client Client . . . Outer Service Request
(via HTTP) ֎෦αʔϏεʹϦΫΤετΛ ඈ͍͍ͯͯ͠
֎෦αʔϏεʹґଘ͍ͯ͠Δ Server Client Client . . . Outer Service Cache
֎෦αʔϏεʹґଘ͍ͯ͠Δ Server Client Client . . . Outer Service Cache
ΩϟογϡΛհ͢Δ͜ͱͰ ߴʹ݁ՌΛಘΔͱͱʹ ෆཁͳϦΫΤετΛݮ͢Δ
ΩϟογϡΛͲͷΑ͏ͳ࣌ʹ͏͔ - Ͳ͏ͬͯΫΤϦ͕͍ (৭ʑͳ͜ͱ͕͋Δ) - ৭ʑͳཧ༝ͰৗيΛҳͨ͠ྔͷΞΫηε͕͋Δ - ৭ʑ͋ͬͯ֎෦αʔϏεʹґଘ͍ͯ͠Δ - ͳͲͳͲ
ΩϟογϡΛͲͷΑ͏ͳ࣌ʹ͏͔ - Ͳ͏ͬͯΫΤϦ͕͍ (৭ʑͳ͜ͱ͕͋Δ) - ৭ʑͳཧ༝ͰৗيΛҳͨ͠ྔͷΞΫηε͕͋Δ - ৭ʑ͋ͬͯ֎෦αʔϏεʹґଘ͍ͯ͠Δ - ͳͲͳͲ
৭ʑͳ͜ͱ͕͋Δɼ৭ʑͳ͜ͱ͕……
ΩϟογϡΛͲͷΑ͏ͳ࣌ʹ͏͔ - Ͳ͏ͬͯΫΤϦ͕͍ (৭ʑͳ͜ͱ͕͋Δ) - ৭ʑͳཧ༝ͰৗيΛҳͨ͠ྔͷΞΫηε͕͋Δ - ৭ʑ͋ͬͯ֎෦αʔϏεʹґଘ͍ͯ͠Δ - ͳͲͳͲ
৭ʑͳ͜ͱ͕͋Δɼ৭ʑͳ͜ͱ͕…… ͔͠͠ຊʹΩϟογϡ͕ඞཁͳͷ͔ख़ߟ͖͢ɽޙड़
ΩϟογϡετϨʔδ
ΩϟογϡετϨʔδ֓؍ - memcached - memcachedϓϩτίϧΛΔؒ - Redis - BerkeleyDB -
mmap (!) - ΞϓϦͷϓϩηεʹ࣋ͭ - ͳͲͳͲ
ͦͷଞͷΩϟογϡϛυϧΣΞ
ΩϟογϡϛυϧΣΞ֓؍ - Squid - Varnish - ͳͲͳͲ
ΩϟογϡϛυϧΣΞ֓؍ - Squid - Varnish - ͳͲͳͲ HTTPϨΠϠͰͷΩϟογϡΛओʹߦ͏ܥ
ϛυϧΣΞબఆͷ ࣌ؒ༨ͬͨΒΓ·͢
Ωϟογϡઓུ
Ωϟογϡઓུ
Ωϟογϡઓུ ͱʹ͔͘ߴʹฦ͢
Ωϟογϡઓུ ͱʹ͔͘ߴʹฦ͢ ߴʹฦ[ͤ͞]ͳ͍Ωϟογϡແҙຯ
Ωϟογϡઓུ ΞϓϦΛյ͞ͳ͍
Ωϟογϡઓུ ΞϓϦΛյ͞ͳ͍ ΞϓϦΛͿͬյ͢Ωϟογϡແҙຯ
Ωϟογϡઓུ - ߴʹฦ͢ - ΞϓϦΛͿͬյ͞ͳ͍ - ґଘίϯϙʔωϯτΛগͳ͘อͭ - লϝϞϦ -
Ωϟογϡ͕ͿͬյΕͯٽ͔ͳ͍ - (ͳΔۚ͘Λ͔͚ͳ͍)
Ωϟογϡઓུ - ߴʹฦ͢ - ΞϓϦΛͿͬյ͞ͳ͍ - ґଘίϯϙʔωϯτΛগͳ͘อͭ - লϝϞϦ -
Ωϟογϡ͕ͿͬյΕͯٽ͔ͳ͍ - (ͳΔۚ͘Λ͔͚ͳ͍)
ґଘίϯϙʔωϯτΛগͳ͘อͭ - ґଘίϯϙʔωϯτ͕૿͑Δ = ো͕૿͑Δ - োগͳ͍ํ͕ྑ͍ - ҆қʹϛυϧΣΞΛ૿͞ͳ͍ -
ʮͬͯΈ͔͔ͨͬͨΒʯΛؾܰʹΔͱ ͲΜͲΜट͕క·Δ
Ωϟογϡઓུ - ߴʹฦ͢ - ΞϓϦΛͿͬյ͞ͳ͍ - ґଘίϯϙʔωϯτΛগͳ͘อͭ - লϝϞϦ -
Ωϟογϡ͕ͿͬյΕͯٽ͔ͳ͍ - (ͳΔۚ͘Λ͔͚ͳ͍)
লϝϞϦ - ϝϞϦΛϞϦϞϦ৯͏ઃܭΛආ͚Δ - ࠷ॳྑ͍͔͠Εͳ͍͕͋Δಥવ ো͕ى͖ͨΓ͢Δ - (ࢹ͠Ζͱ͍͏Ͱ͋Δ͕……) - جຊతʹΩϟογϡ͢ΔΞΠςϜʹ
ExpireΛ͚Δ (= ӬଓతʹσʔλΛ࣋ͨͳ͍)
Ωϟογϡઓུ - ߴʹฦ͢ - ΞϓϦΛͿͬյ͞ͳ͍ - ґଘίϯϙʔωϯτΛগͳ͘อͭ - লϝϞϦ -
Ωϟογϡ͕ͿͬյΕͯٽ͔ͳ͍ - (ͳΔۚ͘Λ͔͚ͳ͍)
Ωϟογϡ͕ͿͬյΕͯٽ͔ͳ͍ - ΩϟογϡյΕΔͷͱͯ͠ӡ༻ͨ͠΄͏͕ͤ - Ωϟογϡ͕ͿͬյΕͨΒ·ͨ࡞Εྑ͍ - Let it crash -
ͨͩɼͿͬյΕͨλΠϛϯάͰٸܹʹෛՙ্͕͕Δ Α͏ͳঢ়گʹ͚ͩͳΒͳ͍Α͏͖͢
Ωϟογϡઓུ - ߴʹฦ͢ - ΞϓϦΛͿͬյ͞ͳ͍ - ґଘίϯϙʔωϯτΛগͳ͘อͭ - লϝϞϦ -
Ωϟογϡ͕ͿͬյΕͯٽ͔ͳ͍ - (ͳΔۚ͘Λ͔͚ͳ͍)
ͳΔۚ͘Λ͔͚ͳ͍ - ͍
Ωϟογϡύλʔϯ
ύλʔϯʁ ʮͦΕͧΕͷύλʔϯզʑͷͷ·ΘΓͰԿճى͖Δɺ͓ ΑͼɺͦΕͧΕͷʹର͢Δղ๏ͷϙΠϯτΛهड़͍ͯ͠Δɻͦ ͜Ͱզʑɺ͜ΕΒͷղ๏ΛԿສճͰ͏͜ͱ͕Ͱ͖Δɻಉ͡ ʹର͢Δಉ͡ղ๏ΛԿԿ࠷ॳ͔Βߟ͑ͣ͞ʹࡁΉͱ͍ ͏Θ͚ͩʯ ― Erich Gamma, Richard
Helm, Ralph Johnson, John Vlissides ஶ, ຊҐా ਅҰ, ٢ాथ ༁ σβΠϯύλʔϯɼվగ൛ ❞
ύλʔϯԽ͢Δརͱ ʮύλʔϯʹ໊લΛ͚Δ͜ͱͰɺઃܭͷ͓͚Δ༻ޠͷޠኮΛ૿ ͢͜ͱʹͳΔɻͦΕʹΑͬͯߴ͍நϨϕϧͰઃܭ͢Δ͜ͱ͕Մೳ ͱͳΔɻύλʔϯʹؔ͢Δޠኮ͕૿͑Εɺಉ྅ͱٞͨ͠Γɺจ ॻʹهͨ͠ΓɺࣗࣗͰߟ͑Λཧ͢Δͷʹཱͭɻઃܭʹ ؔͯ͠ݕ౼ͨ͠Γɺઃܭ্ͷτϨʔυΦϑΛਓʹ͑Δ͜ͱ༰қ ʹͳΔʯ ― Erich Gamma,
Richard Helm, Ralph Johnson, John Vlissides ஶ, ຊҐా ਅҰ, ٢ాथ ༁ σβΠϯύλʔϯɼվగ൛ ❞
ύλʔϯԽ͢Δརͱ ʮҰ໊લΛݺͿ͜ͱ͕Ͱ͖Εɺ͋ͳͨͦΕΛҙࣝ͠ɺͦΕΛ ࢧ͠ɺͦΕΛॴ༗͠ɺͦΕΛίϯτϩʔϧͰ͖ΔΑ͏ʹͳΔͷͰ ͢ʯ ― Robin Williams ஶ, ٢యल ༁ɹ
ϊϯσβΠφʔζɾσβΠϯϒοΫ ❞
Ωϟογϡͷύλʔϯ - Ωϟογϡʹ͍ͭͯͷύλʔϯɼΈ͍ͨͳΛ͋·Γ ฉ͔ͳ͍ - ݁Ռͱͯ͠ʮ✕✕✕͕˓˓˓Ͱ˚˚˚ʹͳΔͭͰ͢ʯ Έ͍ͨͳৄࡉͳจষͰίϛϡχέʔγϣϯ͢Δ͜ͱ ʹͳΔ => ͨΔ͍
Ωϟογϡͷύλʔϯ - ͱ͍͏Θ͚ͰύλʔϯͰ͢ʂʂ - উखʹ໊͚ͨલͳΜͰ͏طʹผͷ໊લ͕͋Δ͔
(ݸਓతʹ) Α͘͏ ύλʔϯΛ͝հʂ
Brokerύλʔϯ - Ωϟογϡʹ͋ͬͨΒΩϟογϡ͔Βฦ͢ - Ωϟογϡʹແ͔ͬͨΒҰ࣍ετϨʔδʹ͍߹Θ ͤͯͦͷ݁ՌΛฦͭͭ͠ΩϟογϡʹೖΕΔ ϦΫΤετͯ͠…… ϦϙδτϦύλʔϯͷѥछͱݴ͑ͦ͏
Server Client Primary Storage ii iii Cache Storage Brokerύλʔϯ i
ii iii iv i. ϦΫΤετ ii. Ωϟογϡ͍߹Θͤ iii. ώοτͨ͠ͷͰ݁ՌΛฦ͢ iv. Ϩεϙϯε
Server Client Primary Storage ii iii Cache Storage Brokerύλʔϯ i
ii iii iv v vi i. ϦΫΤετ ii. Ωϟογϡ͍߹Θͤ iii. Ωϟογϡʹແ͍ͷͰ Ұ࣍ετϨʔδ͍߹Θͤ iv. ݁ՌΛΩϟογϡʹೖΕΔ v. ݁ՌΛฦ͢ vi. Ϩεϙϯε
Brokerύλʔϯ Pros - ΞΫηεසͷߴ͍ίϯςϯπΩϟογϡʹΓ ͍ίϯςϯπΩϟογϡʹΒͳ͍ লϝϞϦ - σʔλͷ߹ੑΛอ͍ͪ͢ (Ωϟογϡ͕৽) Cons
- ࠷ॳʹίϯςϯπʹདྷͨਓ͕ॏ͘ͳΔ - Ωϟογϡʹ͍ͬͯͳ͍࣌ʹେྔʹΞΫηε͕དྷΔͱ ෳͷϦΫΤετ͕Ұ࣍ετϨʔδʹૹΒΕΔ Cache Thundering Herd (ޙड़)
Inventoryύλʔϯ - Ωϟογϡʹ͋ͬͨΒΩϟογϡ͔Βฦ͢ - Ωϟογϡʹແ͔ͬͨΒσϑΥϧτΛฦͭͭ͠ɼ ඇಉظͰҰ࣍ετϨʔδ͔ΒΛऔ͖ͬͯͯ Ωϟογϡ͢ΔΑ͏ʹ͢Δ ϦΫΤετͯ͠……
Inventoryύλʔϯ Server Client Primary Storage ii iii Cache Storage i
ii iii iv i. ϦΫΤετ ii. Ωϟογϡ͍߹Θͤ iii. ώοτͨ͠ͷͰ݁ՌΛฦ͢ iv. Ϩεϙϯε
Inventoryύλʔϯ Server Client Primary Storage ii iii Cache Storage i
ii iii iv i. ϦΫΤετ ii. Ωϟογϡ͍߹Θͤ iii. Ωϟογϡʹແ͍ iv. σϑΥϧτΛฦ͢ (ඇಉظͰ) iv’. Ұ࣍ετϨʔδ͍߹Θͤ v’. ݁ՌΛΩϟογϡ iv’ v’
Inventoryύλʔϯ Pros - Brokerύλʔϯͱ΄΅ಉ͡Pros͕͋Δ - ࠷ॳʹίϯςϯπʹདྷͨਓʹରͯ͠ϨεϙϯελΠϜ͕ѱԽ ͠ͳ͍ Cons - ࠷ॳʹίϯςϯπʹདྷͨਓ͕ਖ਼͍͠ίϯςϯπΛऔΕͳ͍
- σϑΥϧτͷϋϯυϦϯάΛͲ͏͢Δ͔ - Cache Thundering Herd ʹ͍ͭͯղܾ͍ͯ͠ͳ͍
Warmerύλʔϯ - ͦͷίϯςϯπΛΩϟογϡʹͤΔ - ΫϥΠΞϯτͦͷΩϟογϡΛࢀর͢Δ ίϯςϯπੜ࣌ʹ…… ϥϯΩϯάͱ͔ʹ͑Δ
Warmerύλʔϯ Server Client Cache Storage i ii iii iv contents
contents v i. ίϯςϯπੜ࣌ʹ ίϯςϯπΛΩϟογϡ ii. ϦΫΤετ iii. Ωϟογϡ͍߹Θͤ iv. ίϯςϯπฦ͢ v. Ϩεϙϯε
Warmerύλʔϯ Pros - ࠷ॳ͔ΒΩϟογϡܦ༝ͰίϯςϯπΛฦͤΔ - Cache Thundering Herd ͷҰղܾ Cons
- ίϯςϯπ͕ੜ͞ΕΔܥ͡Όͳ͍ͱ͑ͳ͍ - ϥΠϑαΠΫϧͷཧ͕ࡶʹͳΔ (ಉظͱ͔) - ϝϞϦΊͬͪΌ৯͏߹͕͋Δ - Ωϟογϡ͕شൃͨ࣌͠ʹͲ͏͢Δͷ͔ʁ
Pool & Flushύλʔϯ POSTϦΫΤετܥʹ͏ɽ ϦΫΤετ͕དྷͨ࣌ʹΩϟογϡʹͦͷ༰ΛཷΊɼ ͋ΔλΠϛϯάͰӬଓετϨʔδʹॻ͖ग़͢
Pool & Flushύλʔϯ Server Client Primary Storage ii iii Cache
Storage i ii iii i. ϦΫΤετ ii. ΩϟογϡʹཷΊΔ iii. Ϩεϙϯε (͋ΔλΠϛϯάͰ) x. ӬଓετϨʔδʹॻ͖ग़͠ x
Pool & Flushύλʔϯ Pros - ߴʹߋ৽ܥΛॲཧͰ͖Δ Cons - ϓʔϧ͕ͿͬյΕͨ࣌ʹσʔλ͕ফ໓͢Δ -
σʔλͷҰ؏ੑΛอͭ࿑ྗ͕͔͔Δ
ΫϥΠΞϯταΠυΩϟογϡ
HTTP HeaderΛ༻͍ͨΩϟογϡ Server Client i ii i. ϦΫΤετ ii. ϔομ͚ͯฦ͢
- Expires - Cache-Control - Last-Modified - ETag contents
HTTP HeaderΛ༻͍ͨΩϟογϡ Server Client i ii i. ݅ͷϔομ͚ͯ ϦΫΤετ -
If-Modified-Since - If-None-Match ii. ݅ʹैͬͯฦ͢ contents contents
HTTP HeaderΛ༻͍ͨΩϟογϡ Server Client i ii i. ݅ͷϔομ͚ͯ ϦΫΤετ -
If-Modified-Since - If-None-Match ii. ݅ʹैͬͯฦ͢ contents contents ແବʹίϯςϯπΛฦ͢ඞཁ͕ແ͘ͳΔ
ϩʔΧϧͷڥͰ݁ͤ͞Δ - ΩϟογϡͲ͜ΖͰͳ͍ - ྫ: - ӾཡཤྺΛΫϥΠΞϯτͰ࣋ͬͯΒ͏ - λΠϜϥΠϯ࣮ΛΫϥΠΞϯτͷετϨʔδʹ ࣋ͬͯΒ͏
αʔό͔Βฦ͞ͳ͍ͷ͕ ݁ہ͍ͪΜʂʂʂ
Ωϟογϡʹ·ͭΘΔॾ
Cache Thundering Herd ௨ৗɺΩϟογϡʹ֨ೲ͞ΕΔσʔλɺͦΕͧΕ୯Ұͷੜଘ࣌ؒ Λ͍ͬͯ·͢ɻɺසൟʹΞΫηε͞ΕΔΩϟογϡσʔλ ͕ΤΫεύΠΞͨ͠ࡍʹൃੜ͠·͢ɻσʔλ͕ΤΫεύΠϠͨ͠ॠؒ ͔ΒɺฒߦʹΔෳͷΞϓϦέʔγϣϯϩδοΫ͕ϛεώοτΛ ݕ͠ɺ͍ͣΕ͔ͷϓϩηε͕ΩϟογϡσʔλΛ֨ೲ͢Δ·Ͱͷ ؒɺಉҰͷϦΫΤετ͕ଟɺόοΫΤϯυʹඈΜͰ͠·͏ͷͰ͢ɻ ―ΩϟογϡγεςϜͷ
Thundering Herd (Kazuho@Cybozu Labs) http://labs.cybozu.co.jp/blog/kazuho/archives/2007/09/cache_and_thundering_herd.php ❞
Cache Thundering Herd - ΤϯτϦ͝ͱʹExpireͷपظΛόϥ͢ͱ͔ - ಉҰ༰ͷΤϯτϦΛ2ॏʹ༻ҙ͓͍ͯͯ͠ɼ ͲͪΒ͔ҰํΛૣ͘ (͘͘͠) Expireͤ͞Δͱ͔
ͦ͏͍͏ରࡦɾ͕ඞཁͱͳΔ
ಉظ Ωϟογϡͷ༰ͱӬଓετϨʔδͷ༰ͷ ಉظͲ͏͢ΔΜ͡Ό
ಉظ - ΞϓϦέʔγϣϯجຊతʹӬଓετϨʔδʹର ͯ͠ߋ৽ΛՃ͍͑ͯ͘ Ωϟογϡ࣮ݹ͍ίϯςϯπ͔ - ͪΌΜͱ༰Λಉظͤ͞Α͏ͱ͢Δͱେม - Ωϟογϡ͕ਧ͖ඈͿͱӬଓԽ͞Εͳ͍ɼ ͳΜ͍ͯ͏͋Γ͑Δ
ಉظ ORMΛͬͯDBͱΩϟογϡΛಁաతʹѻ͏ͱ͍͏ ख๏͕͋Δʹ͋Δ͕ࠈײ
ಉظ ࣃΛ৯͍ͬͯ͠Δ͔͠ͳ͍ͷ͔……
ෆ۩߹ى͖ͨͱ͖ͷσόοά͕͠ʹ͍͘ ʮ͋Εɼ͜ΕΩϟογϡͨͬͯΔΜͰ͔͢ʯ ʮ͍ɼDB͔Βऔ͖ͬͯͯΔΜ͡Όͳ͍ʯ ʮͳΜ͔͕ͣΕͯΔΜͰ͢ΑͶʯ ʮΤοɼ͜ΕͲ͏ͳͬͯΜͩʁʯ
ෆ۩߹ى͖ͨͱ͖ͷσόοά͕͠ʹ͍͘ ʮ͋Εɼ͜ΕΩϟογϡͨͬͯΔΜͰ͔͢ʯ ʮ͍ɼDB͔Βऔ͖ͬͯͯΔΜ͡Όͳ͍ʯ ʮͳΜ͔͕ͣΕͯΔΜͰ͢ΑͶʯ ʮΤοɼ͜ΕͲ͏ͳͬͯΜͩʁʯ ͋Γ͕ͪʂʂʂʂʂʂ
ෆ۩߹ى͖ͨͱ͖ͷσόοά͕͠ʹ͍͘ ͜Ε͔ͬΓΔ͔͠ͳ͍……
ෆ۩߹ى͖ͨͱ͖ͷσόοά͕͠ʹ͍͘ օ͞ΜͦΕͧΕͷmemcachedͷҝͷπʔϧ RedisͷҝͷπʔϧΛ͍࣋ͬͯΔ͜ͱͰ͠ΐ͏ (͋Δ͍ϓϩτίϧΛΕΔΑ͏ʹਐԽ͢Δ)
ෆ۩߹ى͖ͨͱ͖ͷσόοά͕͠ʹ͍͘ ͋ͱϩάΛϞϦϞϦࠐΉΈ͍ͨͳ ݹࣜΏ͔͍͠ख๏ (ຯ͕ͩޮ͘)
ΩϟογϡϛυϧΣΞ૿͑Δ ΩϟογϡͷҝʹϛυϧΣΞ͕૿͑Δ ୯७ʹোཁҼ͕૿͑Δʂʂʂʂʂ
ΩϟογϡϛυϧΣΞ૿͑Δ γεςϜΛ҆ఆͤ͞ΔͨΊʹಋೖͨ͠ ΩϟογϡϛυϧΣΞ͕ෆ҆ఆͳ͔Γʹ ҎલΑΓՔಇ͕Լ͕ͬͯ͠·͏ͱ͍͏ࠈ
ΩϟογϡϛυϧΣΞ૿͑Δ - ΈͩΓʹϛυϧΣΞΛ૿͞ͳ͍ํͰؤுΔ - طଘͷίϯϙʔωϯτͰ༻͕Ͱ͖Δ͔ʁ
Ͳ͏͍͏࣌ʹΩϟογϡΛΘͳ͍͖͔
σʔλ͕ফ͑Δͱக໋తͳ߹ - σʔλ͕ڏۭʹফ͑ΔͱഛঈʂʂɹΈ͍ͨͳ ͱ͜Ζʹ͏͖Ͱͳ͍ - Ωϟογϡͷσʔλফ͑Δͷͱߟ͑Δ
σʔλ͕ফ͑Δͱக໋తͳ߹ - σʔλ͕ڏۭʹফ͑ΔͱഛঈʂʂɹΈ͍ͨͳ ͱ͜Ζʹ͏͖Ͱͳ͍ - Ωϟογϡͷσʔλফ͑Δͷͱߟ͑Δ ͔͠͠αʔϏεӡ༻্ফ͑ͯྑ͍σʔλ ͳΜͯ΄ͱΜͲͳ͍ͧʂʂʂ
ΩϟογϡΛ࠶ߏஙग़དྷͳ͍߹ - ΩϟογϡͷσʔλͿͬյΕͯ࠶ߏங Ͱ͖Εͳ͍ - όονͰDB͔ΒΩϟογϡ࠶ੜͱ͔Ͱ - ٯʹݴ͏ͱΩϟογϡΛ࠶ߏஙͰ͖ͳ͍߹ ͏͖Ͱͳ͍
ଞʹ৭ʑ͋Δ…… ݁ߏΩϟογϡΛ͏͖Ͱͳ͍Օॴ ۙʹᷓΕ͍ͯΔ
Ωϟογϡຑༀ
Ωϟογϡʹ·ͭΘΔॾΛ͏͚ͯ ΩϟογϡϚδَ
ҰΩϟογϡΛ͏ͱΕͳ͘ͳΔ - ҆қͳؾ࣋ͪͰΩϟογϡΛ͏ͱ ͦͷ෦͕͏͔ͬΓ͘ͳͬͯ͠·͏ - ଞͷ෦Ͱͦͷߴ͞ΛٻΊΒΕΔ ͠ΐ͏͕ͳ͍ͷͰΩϟογϡ͍·͔͢…… - Α͏ͦ͜Ωϟογϡপ
ҰΩϟογϡΛ͏ͱΕͳ͘ͳΔ - Ωϟογϡجຊతʹෳࡶͳػߏ - ೖΕΔͷ؆୯ɼൈ͘ͷ͕͍͠ - ΩϟογϡͱҰੜ͖߹͍֮ͬͯ͘ޛ͕͋Δ͔
Ωϟογϡͷڪාʂʂʂ ʮͳΜ͔͜ͷ෦͍ͬ͢Ͷ͑ʯ ʮDB٧·ͬͯΜ͡ΌΜʁɹΩϟογϡ͠Α͏ͥʯ ʮOKOKʯ
Ωϟογϡͷڪාʂʂʂ ʮͳΜ͔͜ͷ෦͍ͬ͢Ͷ͑ʯ ʮDB٧·ͬͯΜ͡ΌΜʁɹΩϟογϡ͠Α͏ͥʯ ʮOKOKʯ OKͰͳ͍ʂʂʂʂʂ
Ωϟογϡͷڪාʂʂʂ ͍ʂ ෲཱͭʂʂ Ωϟογϡ͢Δʂʂʂ
҆қͳΩϟογϡΛ ΊΖʂʂʂʂ
ͪΌΜͱઃܭΛ͢Δ
ͪΌΜͱઃܭΛ͢Δ - ͪΌΜͱDB (σʔλϞσϧ) ͷઃܭΛ͢Δ - ΠϯσοΫεͱؚ͔Ίͯ - มͳΞʔΩςΫνϟΛΊΔ -
ϘτϧωοΫʹͳΓ͕ͪ - ʮͨΓલͷ͜ͱΛͨΓલʹΔʯ
Ͳ͏ͬͯΫΤϦ͕͍ Server Client Client . . . RDBMS Slow Query
Ͳ͏ͬͯΫΤϦ͕͍ Server Client Client . . . RDBMS Slow Query
ΫΤϦ (͋Δ͍ςʔϒϧ)Λͤʂʂʂ దʹνϡʔχϯά͞ΕͨΫΤϦʹ ΩϟογϡͳͲෆཁ
Ͳ͏ͬͯΫΤϦ͕͍ Server Client Client . . . RDBMS Slow Query
Slave Slave ΩϟογϡʹཔΒͣ SlaveΛฒΔΑ͠
֎෦αʔϏεʹґଘ͍ͯ͠Δ Server Client Client . . . Outer Service Request
(via HTTP)
֎෦αʔϏεʹґଘ͍ͯ͠Δ Server Client Client . . . Outer Service Request
(via HTTP) ֎෦αʔϏεʹґଘ͠ͳ͍ ํ๏Λߟ͑Δ
ͪΌΜͱଌఆΛ͢Δ
ͪΌΜͱଌఆΛ͢Δ - ΩϟογϡΛ༻͍Δ͜ͱͰຊʹޮ͍͍ͯΔͷ͔ - ෛՙ͕Լ͕͍ͬͯΔʁ - ϨεϙϯελΠϜ͕վળ͍ͯ͠Δʁ - αʔϏεͷՄ༻ੑ্͕ঢ͍ͯ͠Δʁ
ͪΌΜͱଌఆΛ͢Δ - ΩϟογϡΛ༻͍Δ͜ͱͰຊʹޮ͍͍ͯΔͷ͔ - ෛՙ͕Լ͕͍ͬͯΔʁ - ϨεϙϯελΠϜ͕վળ͍ͯ͠Δʁ - αʔϏεͷՄ༻ੑ্͕ঢ͍ͯ͠Δʁ ΩϟογϡΛೖΕ͚ͨͩͰ
تΜͰ͍ͯବ
ͪΌΜͱଌఆΛ͢Δ - ΩϟογϡΛ༻͍Δ͜ͱͰຊʹޮ͍͍ͯΔͷ͔ - େͯ͠ޮ͔͵ΩϟογϡͳΒೖΕΔ͚ͩෛ࠴
Ωϟογϡຑༀ Ωϟογϡ࠷ऴฌث
ຊʹඞཁͳ࣌ʹ͚ͩ ΩϟογϡΛ͍·͠ΐ͏
Θͳͯ͘ࡁΉͷͳΒ ΩϟογϡΛΊΑ͏ʂʂ
Q?
͕࣌ؒ͋Εͷίʔφʔ
VarnishͷΛ͍ͯ͠·ͤΜͶʁ
VarnishͷΛ͍ͯ͠·ͤΜͶʁ - ͢Έ·ͤΜαʔϏεͰͬͨ͜ͱͳ͍ͷͰ ҰΕ·ͤΜ - ༗ӹͳΠϯλʔωοτ্ʹͨ͘͞Μ ࢿྉ͕͋Γ·͢ (YAPC 2011ͷmala͞ΜͷࢿྉͳͲ) -
ΠϯλʔωοτʹͳΜͰ͋Δ
ΩϟογϡετϨʔδબఆ
ΩϟογϡετϨʔδબఆ - ༻్ - ࢄ͢Δඞཁ͕͋Δ͔ - Խ͢Δඞཁ͕͋Δ͔ - ͬͯΔΫϥυϓϥοτϑΥʔϜͰαϙʔτ ͍ͯ͠Δ͔Ͳ͏͔
- ετϨʔδʹৄ͍͠ਓ͕͍Εྑ͍
ΩϟογϡετϨʔδબఆ
ΩϟογϡετϨʔδͷ Խߏʹ͍ͭͯ
Խ - Redisͩͱsentinelͱ͔clusterͱ͔ - memdͷ߹ܥΛෳ༻ҙ͢Δͱ͔ - ࣗͰϧʔςΟϯάΛॻ͘ඞཁ͕͋Δ - ͍҃mcrouterͳͲ…… -
ຊʹԽ͕ඞཁͳͷ͔Ͳ͏͔Λߟ͑Δ ඞཁ͋Δ