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
非同期処理を使った応答性能改善 AWS Lambda
Search
Hyuga-Tsukui
August 03, 2022
Programming
1
330
非同期処理を使った応答性能改善 AWS Lambda
AWS Lambda,SQS,Dynamodb を利用し、応答性能をお手軽に改善する一つの案の提示ができればと思っています。
Hyuga-Tsukui
August 03, 2022
Tweet
Share
More Decks by Hyuga-Tsukui
See All by Hyuga-Tsukui
Form実装基本を学び直してみた
hyugatsukui
1
450
エンジニアリングの本質を見極めて、何気ない行動の質を上げよう
hyugatsukui
0
160
Other Decks in Programming
See All in Programming
fs2-io を試してたらバグを見つけて直した話
chencmd
0
230
Effective Signals in Angular 19+: Rules and Helpers @ngbe2024
manfredsteyer
PRO
0
140
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
3
270
Beyond ORM
77web
7
840
Spatial Rendering for Apple Vision Pro
warrenm
0
110
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
4
560
Kaigi on Railsに初参加したら、その日にLT登壇が決定した件について
tama50505
0
100
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
200
php-conference-japan-2024
tasuku43
0
300
From Translations to Multi Dimension Entities
alexanderschranz
2
130
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
선언형 UI에서의 상태관리
l2hyunwoo
0
160
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
How to Ace a Technical Interview
jacobian
276
23k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
A better future with KSS
kneath
238
17k
Embracing the Ebb and Flow
colly
84
4.5k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Transcript
ඇಉظॲཧΛͬͨԠੑೳ վળ ServerlessLTॳ৺ऀ͚ LTେձ #24
ࣗݾհ • Hyuga Tsukuiʢ@hy_twenʣ • γΣϧϑΟʔʢגʣͰݐઃۀք͚SaaSΛ։ൃ͍ͯ͠·͢ • ࣾ֎LTॳઓͰ͢👋
ࠓ͍͑ͨ͜ͱ • ৗ͔Βݟ͑Δඇಉظॲཧͱʁ • ඇಉظॲཧͷ͍ॴ • ߴίετͳॲཧͷऔΓѻ͍ͱγϯϓϧͳղܾࡦͷհ
ඇಉظॲཧͱ • ޙͰ݁ՌΛฦ͢͜ͱΛଋ͠ɺҰॲཧΛྃͤ͞Δɻ݁Ռ͕༻ҙͰ ͖ͨΒݺͼग़͠ݩʹ͋ΒͨΊͯ݁ՌΛ௨͢ΔΈͷ͜ͱʢࢀߟ https://www.htmlhi fi ve.com ඇಉظॲཧͱPromiseΛഎܠ͔Βཧղ͠Α͏ʣ
͋Δͷ͓ങ͍Λߟ͑ͯΈ·͢ • εʔύʔซઃͷༀہͰɺॲํᝦ͔ΒༀΛ࡞ͬͯΒ͏ʢλεΫAʣ • ͖ΐ͏ͷ൩͝Μͷ৯ࡐΛങ͏ʢλεΫBʣ
ಉظॲཧVer. ॲํᝦड ௐࡎʢNJOʣ ػʢNJOʣ ௐࡎྃ ങ͍ NJO
ඇಉظॲཧVer. ॲํᝦड ௐࡎʢNJOʣ ങ͍ NJO ௐࡎྃ ड൪߸ൃߦ
྆ऀͷҧ͍ • ಉظVer.ௐࡎ͕ऴΘͬͨΒങ͍Λ։࢝͢Δ • ඇಉظVer.ௐࡎதʹങ͍Λ։࢝͢Δ
ಉظॲཧVer. ॲํᝦड ௐࡎʢNJOʣ ػʢNJOʣ ௐࡎྃ ങ͍ NJO Ұ࿈ͷॲཧ͕ྃ͢Δ·ͰNJO͔͔Δ
ඇಉظॲཧVer. ॲํᝦड ௐࡎʢNJOʣ ങ͍ NJO ௐࡎྃ ड൪߸ൃߦ Ұ࿈ͷॲཧ͕ྃ͢Δ·ͰNJO͔͔Δ
ௐࡎΛຊʹͭඞཁ͕͋Δ͔ʁ
ड൪߸(PromiseʣͳͲͰඇಉظతʹ ॲཧͰ͖Δ
ඇಉظॲཧΛݕ౼͢ΔMotivation • λεΫͷྃΛͭඞཁ͕ແ͍ͱ͖ • Ұ࿈ͷλεΫͷྲྀΕʢ͋Δͷ͓ങ͍ʣͷதͰɺϘτϧωοΫͱͳ ΔΑ͏ͳλεΫ͕͋Δ࣌
γεςϜͷ
ϦΞϧͳͷߟ͑·ͨ͠ʂ
͋ΔIOTػثͷར༻։࢝αʔϏεΛߟ͑Δ • ػثࡏݿཧDBͰͲͷސ٬͕ར༻͢Δ͔ཧ͍ͯ͠Δ • ػث͕ωοτϫʔΫΛར༻͢ΔʹɺػثఏڙϕϯμͷAPIϓϩϏ δϣχϯάਃΛ͢Δඞཁ͕͋Δ • ϓϩϏδϣχϯάਃྃʹΛཁ͢Δ • ࣦഊ͢ΔՄೳੑ͋Δ
ུਤ
λεΫΛ͚ͯΈΔͱ • ػثࡏݿʹؔ͢ΔॲཧͱɺϓϩϏδϣχϯάΛ͢Δॲཧ͚Εͦ͏ • ϓϩϏδϣχϯάॲཧ͕͔͔࣌ؒΔͷͰɺλεΫΛ͚ͳ͍ͱɺԠ ੑ͕͜͜ʹӨڹΛड͚ͯѱ͘ͳΔ • ࣦഊͨ͠ͱ͖ʹϓϩϏδϣχϯά͔Β͚ͩΓͤͦ͏
ඇಉظॲཧΛݕ౼͢ΔMotivation • λεΫͷྃΛͭඞཁ͕ແ͍ͱ͖ • Ұ࿈ͷλεΫͷྲྀΕʢ͋Δͷ͓ങ͍ʣͷதͰɺϘτϧωοΫͱͳ ΔΑ͏ͳλεΫ͕͋Δ࣌
ࠓճखܰʹඇಉظԽ͢Δͷ͜͜ʂ
͍͟ɺServerlessʂ
࠷ऴߏਤ
࠷ऴߏਤ ͜͜
AWS SimpleQueueService(SQS) • AWS͕ఏڙ͢ΔServerlessͳϝοηʔδΩϡʔΠϯάαʔϏεͰ༷ʑ ͳServerlessͰߏ͞ΕͨΞϓϦΛ౷߹Ͱ͖Δ • Lambdaͱͷ࿈ܞ͕༰қ • ϦτϥΠɺࣦഊͨ͠ϝοηʔδͷอଘ͕Մೳ •
ඇৗʹߴʢඪ४ΩϡʔͳΒࣄ্࣮ແ੍ݶ
AWS SimpleQueueService(SQS) ͜Μͳײ͡ʹɺൺֱతॊೈͳϝοηʔδΛऔΓѻ͑·͢ɻ(256kb·ͰͷςΩετ) ྫͱͯ͠ɺࠓճͷϓϩϏδϣχϯάAPIʹඞཁͦ͏ͳΛઃఆͯ͠Έ·͠ΐ͏ɻ { “eventId”: “7885ca34-f3ff-4575-b062-da50e9ae746a”, “macAddress”: “00-00-5E-10-00-00-00-00“ //
document༻ʹ͋Δར༻ՄೳͳͰ͢ }
AWS SimpleQueueService(SQS) ·ͨࠓճཁ݅ͱͯ͠ɺ֎෦APIͷࣦഊՄೳੑ͕͋ΔͷͰɺDeadLetterQueueͷઃఆΦεεϝͰ͢ɻ Πϝʔδͱͯ͠ɺࣦഊͨ͠ϝοηʔδΛࣗಈͰҰ࣌తʹผͷQueue֨ೲ͠ɺܾΊΒΕͨϧʔϧͰ࠶PushʢReDriveʣ͠·͢ɻ ·ͨࢦఆͷճ࣮ߦͯ͠ফԽͰ͖ͳ͔ͬͨ߹ɺDeadLetterQueueอଘ͞Εɺࢦఆظؒܦաޙআ͞Ε·͢ɻ
࠷ऴߏਤ ͜͜
AWS Lambda • AWS͕ఏڙ͢ΔServerlessͷίϯϐϡʔςΟϯάϦιʔε • ๛ͳରԠݴޠɺϥϯλΠϜΛ࣋ͭͷͰϏδωεϩδοΫͷ࣮ίε τ͕ • ࣮ߦ࣌ؒͰͷ՝ۚͷͨΊɺॲཧʹΑͬͯίετ •
ߴεέʔϥϏϦςΟ • ࠓճͰ͍͏ͱSQSͱͷ૬ੑ͕ൈ܈ͰɺࣗલͰϙʔϦϯάج൫Λ࣋ͭ
AWS Lambda Lambdaଟ͘ͷىಈτϦΨʔΠϕϯτΛ͍࣋ͬͯΔͷͰɺSQSʹϝοηʔδ͕PUT͞ΕͨͷΛܖػʹɺىಈ͢ΔͳͲ͕ઃఆҰͭͰߦ͑ ·͢ɻ
ࠓճߏͷҙ ɾSQSʹඪ४ΩϡʔΛࢦఆͨ͠߹ɺat least once ͷ༷ʹΑΓɺಉ͡ϝοηʔδ͕ෳPULL͞ΕΔՄೳੑ͕͋Γ·͢ɻ { “eventId”: “7885ca34-f3ff-4575-b062-da50e9ae746a”, “macAddress”: “00-00-5E-10-00-00-00-00“
// document༻ʹ͋Δར༻ՄೳͳͰ͢ } 👆͜ͷϝοηʔδ͕ೋճPULL͞ΕΔͷͰɺಉ͡macAddressΛॲཧ͢ΔLambda͕ෳճ࣮ߦ͞ΕΔՄೳੑ͕͋Δɻ
ࠓճߏͷҙ ɾͦͷͨΊɺႈੑ֬อ·ͨɺϩοΫػߏΛඞ࣮ͣ͢Δඞཁ͕͋Γ·͢ɻ EX. DynamoDBΛར༻ָͨ͠؍Lockʢٙࣅίʔυʣ status = dynamoDB.GetItem(eventId=1) if (status ===
0) { api.call(macAddress); }else { return }
͋Δ͔͠Εͳ͍ٙ
͋Δ͔͠Εͳ͍ٙ Q1. LambdaࣗಈϦτϥΠ͋Δ͡ΌΜɺͳΜͰSQS? A1. ͦͷͱ͓ΓͰ͕͢ɺ࠷ऴతʹ࣮ߦͰ͖ͳ͔ͬͨevent͕SQSͷ΄͏͕͍͍ͨ͢ΊͰ͢ɻLambdaͰࣦഊͨ͠eventΛ DeadLetterQueueʹஷΊ͓ͯ͘ߏ͋ΔΑ͏Ͱ͢ɻ Q2. ͳΜͰDynamoDBʁRDSͰବͳͷ͔ A1. LambdaͱRDSͷ૬ੑྑ͘ͳ͍ͱ͢Δͷ͕ҰൠతͰ͢ɻཧ༝ɺRDSࣄ্࣮εέʔϧΞοϓͰͷରԠ͔͠Ͱ͖ͳ͍ͨΊݶք͕ۙ
͍Ͱ͕͢ɺLambdaແ੍ݶͷεέʔϧΞτͳͷͰɺ͜͜ͰRDS͕ϘτϧωοΫʹͳΔͨΊͰ͢ɻ ίωΫγϣϯϓʔϧͷAmazon RDS ProxyͳͲΛར༻͢Δ͜ͱͰଧ։Ͱ͖Δ͔͠Ε·ͤΜʢͬͨ͜ͱͳ͍Ͱ͢ɻ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ