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
海外展開を目指すアプリで実装したセキュアで高速な画像配信の話 / Image distribu...
Search
atsushisakai
August 30, 2018
Programming
8
6.8k
海外展開を目指すアプリで実装したセキュアで高速な画像配信の話 / Image distribution for overseas
iOSDC Japan 2018発表資料です。
atsushisakai
August 30, 2018
Tweet
Share
More Decks by atsushisakai
See All by atsushisakai
大規模 SaaS の技術的意思決定を支える三要素 / Three elements that support technical decision-making for large-scale SaaS
_atsushisakai
0
890
一方、私はなぜEMでありつづけるか / TECH TRACK vol.1
_atsushisakai
0
410
子育てとEMと転職と
_atsushisakai
2
750
「家族アルバム みてね」を支える エンジニアリング組織/introduce-familyalbum-engineering-team
_atsushisakai
2
210
ミクシィのマネージャーは悩んでいる / mixi's manager is in trouble
_atsushisakai
16
14k
実践 Engineering Manager / practice engineering manager
_atsushisakai
19
8k
Scalable Microservice for Media Transcoding / Transcoder
_atsushisakai
4
1.5k
New Relic {FUTURE} STACK 3/14, 2019 / newrelic_future_stack
_atsushisakai
1
1.5k
実践 WorkManager / WorkManager
_atsushisakai
3
7.3k
Other Decks in Programming
See All in Programming
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
100
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
330
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
330
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
2
670
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.5k
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
910
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
Featured
See All Featured
A better future with KSS
kneath
238
17k
Side Projects
sachag
452
42k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
120
Thoughts on Productivity
jonyablonski
67
4.3k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Making the Leap to Tech Lead
cromwellryan
133
8.9k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Transcript
ւ֎ల։Λࢦ͢ΞϓϦͰ࣮ͨ͠ ηΩϡΞͰߴͳը૾৴ͷ ञҪ ಞ @_atsushisakai mixi, Inc. iOSDC Japan 2018
- 8/31 14:20~ Track D
ञҪ ಞ @_atsushisakai 2011 ϛΫγΟೖࣾ ։ൃ։࢝ॳΑΓʮՈΞϧόϜ ΈͯͶʯͷiOS։ൃΛ୲ 2018Ҏ߱ɺΈͯͶࣄۀ෦։ൃάϧʔϓϚωʔδϟʔ ݉ SRE
1 ʮՈΞϧόϜ ΈͯͶʯʹ͍ͭͯ
ʮՈΞϧόϜ ΈͯͶʯʹ͍ͭͯ ಛ ࢠڙͷࣸਅಈըΛڞ༗ɺཧ Ո͚ͩͰ҆৺ͯ͑͠ΔΞϧόϜΞϓϦ 1
ʮՈΞϧόϜ ΈͯͶʯʹ͍ͭͯ ͜Ε·Ͱ 20154݄ αʔϏε։࢝ 20188݄ Ϣʔβʔ300ສਓ 1
ʮՈΞϧόϜ ΈͯͶʯʹ͍ͭͯ 20176݄ ӳޠ൛ͷఏڙ։࢝ 1
7݄ʹNYग़ு༷ͨ͠ࢠͳͲ https://medium.com/mixi-developers/4526e24093ca ʮՈΞϧόϜ ΈͯͶʯʹ͍ͭͯ 1
ʮՈΞϧόϜ ΈͯͶʯʹ͍ͭͯ ࠓӳޠ൛ͷΞϓϦʹ͓͚Δ՝ղܾͷࣄྫΛ͓͠͠·͢ɻ 1
՝ͱʁ 2
՝ͱʁ Ϣʔβʔ͔Βͷใࠂ ʮը૾͕දࣔ͞ΕΔͷ͕ͱ͍ͯʯ 2 NYͰݟͨվળલͷΈͯͶ
՝ͱʁ ւ֎ͰαʔϏεΛӡ༻͢Δ࠷ॳͷ՝ ΞϧόϜΞϓϦͱͯ͠ࠃಉ༷ɺߴͳը૾ӾཡΛߦ͑Δ͜ͱ 2
՝ͷੳ 3
ΈͯͶͷը૾৴ϑϩʔʢվળલʣ ՝ͷੳ 3
ը૾৴ϑϩʔ 1. ϦΫΤετ 2. ೝূɾೝՄΛߦ͍CloudFrontϦμΠϨΫτ 3. ॺ໊͖ɾ੍࣌ؒݶ͖URLը૾ΛϦΫΤετ 4. S3ͷΦϦδϯαʔόʔը૾ΛϦΫΤετ 5.
ը૾ΛCloudFrontฦ٫ɺCloudFrontͰΩϟογϡ 6. ը૾ΛσόΠεϨεϙϯεʢΩϟογϡʣ Amazon EC2 Amazon CloudFront Amazon S3 1 2 3 4 5 6 ՝ͷੳ 3
ຊࠃ֎͔ΒͲ͏ݟ͑Δ͔ʁ Amazon EC2 Amazon CloudFront Amazon S3 1 3 4
5 6 2 ՝ͷੳ 3
ຊࠃ֎͔ΒͲ͏ݟ͑Δ͔ʁ Amazon CloudFront 1 3 4 5 6 ຊࠃ Amazon
S3 Amazon EC2 2 ՝ͷੳ 3
3 ࠃ֎͔ΒͲ͏ݟ͑Δ͔ʁ Amazon EC2 Amazon CloudFront Amazon S3 1 3
4 5 6 2 ຊࠃ ຊࠃ֎͔Βͷը૾ද͕͍ࣔݪҼ • ຊࠃʹଘࡏ͍ͯ͠ΔAPIαʔόʔͷڑ͕ԕ͗͢Δ • ຊࠃʹଘࡏ͍ͯ͠ΔS3ͷڑ͕ԕ͗͢Δ ՝ͷੳ
Ͳͷ͙Β͍͍ͷʁ ՝ͷੳ 3
NewRelic Synthetics • APIΤϯυϙΠϯτͷ֎ܗࢹαʔϏε • ϦΫΤετ։࢝ॴ͕ੈքதʹଘࡏ͍ͯ͠ΔͷͰࠃ֎͔ΒͷϦΫΤετΛγϛϡϨʔτՄೳ • ςετ༰JavaScriptͰهड़ • ֤छnode.js
modulesΛར༻Մೳ (https://docs.newrelic.com/docs/synthetics/new-relic- synthetics/scripting-monitors/import-nodejs-modules) ՝ͷੳ 3
None
36.2KBͷసૹ " Washington, DC, ͔ΒͷΞΫηε
ೝূΛ࣮ߦ
302 Redirect
CloudFrontʢ࣮ࡍͷը૾ϦιʔεʣͷΞΫηε
ൃߦͨ͠ϦΫΤετ͕ྃ͢Δ·Ͱͷ࣌ؒ ͨͬͨ36.2KBΛసૹ͢ΔͨΊʹ1.35sec͔͔͍ͬͯΔ
՝Λղܾ͢ΔγεςϜઃܭ 4
՝Λղܾ͢ΔγεςϜઃܭ 4 վળ͖͢ϙΠϯτ 1. ຊࠃͷAPIϦΫΤετͷൃੜ࠷খݶʹɻ 2. CDNͷΩϟογϡΛࣄલʹߦ͏Α͏ʹɻ 1 Amazon CloudFront
1 3 4 5 6 ຊࠃ Amazon S3 Amazon EC2 2
վળ͖͢ϙΠϯτ 1. ຊࠃͷAPIϦΫΤετͷൃੜ࠷খݶʹɻ 2. CDNͷΩϟογϡΛࣄલʹߦ͏Α͏ʹɻ Amazon CloudFront 1 3 4
5 6 ຊࠃ Amazon S3 Amazon EC2 2 ՝Λղܾ͢ΔγεςϜઃܭ 4
վળ͖͢ϙΠϯτ 1. ຊࠃͷAPIϦΫΤετͷൃੜ࠷খݶʹɻ 2. CDNͷΩϟογϡΛࣄલʹߦ͏Α͏ʹɻ AWSʹPre-Warmingػೳແ͍ Amazon CloudFront 1 3
4 5 6 ຊࠃ Amazon S3 Amazon EC2 2 ՝Λղܾ͢ΔγεςϜઃܭ 4
ຊࠃͷAPIϦΫΤετͷൃੜΛ࠷খݶʹ͢Δɻ ՝Λղܾ͢ΔγεςϜઃܭ 4
ͲͷΑ͏ʹ࣮ݱ͔ͨ͠ • ॺ໊͖URLΛUI͔ΒͷϦΫΤετ͕ΔલʹࣄલʹҰཡͰ͍ग़͢Α͏ʹมߋ • ༗ޮظݶΕͷͱ͖͚ͩɺຊʹ͍߹Θͤͯ࠶औಘ • ॺ໊͖URLࣗମΛΩϟογϡ͢Δ • දࣔϦΫΤετ࣌ʹɺ͙͢ʹCloudFrontͷΞΫηεΛߦͳ͑ΔΑ͏ʹͨ͠ ՝Λղܾ͢ΔγεςϜઃܭ
4
γʔέϯε 1. ҰཡऔಘͷϦΫΤετൃՐϝλσʔλߋ৽࣌ͷΈ 2. ॺ໊͖URLࣗମΛΩϟογϡ͢Δ 3. ॺ໊͖URL͑͋͞Ε͙͢ʹը૾ʹΞΫηεՄೳ ՝Λղܾ͢ΔγεςϜઃܭ 4
ղઆ ߴͳίϯςϯπΞΫηε • ओʹCDNͷػೳͰ࣮ݱ • S3ͷίϯςϯπΛΩϟογϡ͠ϨΠςϯγʔͰ৴͢Δ • CDNʹΩϟογϡ͞Ε͍ͯΕS3ͷϦΫΤετ͕লུͰ͖Δ ηΩϡϦςΟ •
RailsͰೝূɾೝՄࡁΈͷϢʔβʔʹͷΈॺ໊͖URLΛൃߦ͍ͯ͠Δ • ৴པ͞Εͨॺ໊ऀʢαʔόʔʣͷΈ͕ॺ໊͖URLΛੜՄೳ • CloudFrontͰURLʹ༩͞Εͨॺ໊Λݕূ͞ΕͯॳΊͯϦιʔεͷΞΫηε͕Մೳ • ༗ޮظݶ͖ͰURLͷ࿙Ӯ͔ΒकΔ • S3ʹΞΫηεग़དྷͳ͍Α͏ʹઃఆ͍ͯ͠Δ ՝Λղܾ͢ΔγεςϜઃܭ 4
TIPS: ϫΠϧυΧʔυΛ༻ͨ͠CloudFrontॺ໊͖URLੜ • ϫΠϧυΧʔυࢦఆͰෳίϯςϯπΛରʹͯ͠ॺ໊͖URLΛൃߦͰ͖Δ • ྫ͑ɺෳͷαΠζͷαϜωΠϧΛS3্ʹอ͍࣋ͯ͠Δ߹ͳͲ • https://cdn-hoge.cloudfront.net/images/*/id-001.jpeg Λॺ໊͢ΔͱҎԼ྆ํͱΞΫηε͕Մೳ •
https://cdn-hoge.cloudfront.net/images/small/id-001.jpeg • https://cdn-hoge.cloudfront.net/images/large/id-001.jpeg • SDKΛͬͨURLੜ͕ศར • AWS SDK for Ruby version 3 • https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/CloudFront/UrlSigner.html ՝Λղܾ͢ΔγεςϜઃܭ 4
ΞϓϦ࣮ 5
্࣮ͷϙΠϯτ • ॺ໊͖URLΛRealmʹΩϟογϡ͢Δ • ༗ޮͳॺ໊͖URL͕ඞͣऔಘͰ͖ΔΑ͏ʹRxSwiftΛۦͯ͠RepositoryΛ࣮͢Δ • ͷը૾ͷDownload/CacheSDWebImageΛར༻͢Δ ΞϓϦ࣮ 5
Realm ΞϓϦ࣮ 5
ΞϓϦ࣮ 5
5 ॺ໊͖URLͷϑΥʔϚοτͱ༗ޮظݶΛอ࣋͢ΔϑΟʔϧυΛ༻ҙ ΞϓϦ࣮
Repository ΞϓϦ࣮ 5
ΞϓϦ࣮ 5
ΞϓϦ࣮ 5
ΞϓϦ࣮ 5 Realm/Remote APIͷΠϯλʔϑΣʔεΛநԽ ➡ RemoteCacheStore (API͚) ➡ LocalCacheStore (Realm͚)
ΞϓϦ࣮ 5 Realm͘͠API͔Βॺ໊͖URLΛऔಘ͢Δ
ΞϓϦ࣮ 5 Realmʹॺ໊͖URLΛอଘ͢Δ
ΞϓϦ࣮ 5
ΞϓϦ࣮ 5 RemoteStore ➡ SignedUrlDataStoreͷAPI࣮ CacheStore ➡ SignedUrlDataStoreͷRealm࣮
ΞϓϦ࣮ 5 RealmʹϨίʔυ͕ଘࡏ͠ͳ͍ͱ͖ʹAPI͔Βॺ໊͖URLΛऔಘ
ΞϓϦ࣮ 5 ΩϟογϡࡁΈͷॺ໊͖URL͕༗ޮظݶΕͷ߹ ࠶APIܦ༝ͰԆͨ͠ॺ໊͖URLΛऔಘ͢Δ
ΞϓϦ࣮ 5 ࠶औಘͨ͠߹ॺ໊͖URLΛΩϟογϡʹอଘͭͭ͠ฦ͢
ը૾ͷDownload/Cache ΞϓϦ࣮ 5
SDWebImage • ͗͢Δॺ໊͖URL͕ΩϟογϡΩʔͱͯ͠ѻ͑ͳ͔ͬͨ • ࣸਅɾಈըϝλσʔλͷ֤छใ͔ΒੜͰ͖ΔΩϟογϡΩʔΛࣗͰੜ͢Δ͜ͱʹͨ͠ • SDImageDownloader/SDImageCache Λݸผʹૢ࡞͢ΔίʔυΛॻ͍ͨ ΞϓϦ࣮ 5
Ռ 6
Ռ 6 Before After
※ͨͩ͠ɺॺ໊͖URL͕Expireͨ͠ͱ͖ʹ࠶औಘͷͨΊͷϦΫΤετ͕ඞཁ ඞཁͳͷCloudFrontΞΫηε͢Δ͚࣌ؒͩ
58.4ms͕ը૾දࣔϦΫΤετ࣌ؒ 1.35sec͔͔͍ͬͯͨࠒ͔ΒൺΔͱ࣮ʹ 22 ഒߴԽ
͞ΒͳΔ՝ 7
վળ͖͢ϙΠϯτ 1. ຊࠃͷAPIϦΫΤετͷൃੜ࠷খݶʹɻ 2. CDNͷΩϟογϡΛࣄલʹߦ͏Α͏ʹɻ Amazon CloudFront 1 3 4
5 6 ຊࠃ Amazon S3 Amazon EC2 2 ͞ΒͳΔ՝ 7
ࠃࡍ݁ࠗͳͲͷՈʹඇޮͰ͋Δ • CDNͷΩϟογϡΛ׆͔͖͠Εͳ͍ύλʔϯ • ྫʣຊͷ්ͱΞϝϦΧͷɻΤοδͷΩϟογϡΛෳճߦ͏ඞཁ͕͋Δɻ • Τοδαʔόʔ⁶S3ΦϦδϯͷ௨৴ʹڑʹىҼ͢ΔϨΠςϯγΛഉআ͖͠Εͳ͍ɻ • ٯʹɺಉ͡ࠃɾҬʹ͓͍ͯΤοδΩϟογϡ͕ޮ͘ͷͰ࠷ॳͷ1ճҎ֎ߴɻ ͞ΒͳΔ՝
7
CDNͷࣄલΩϟογϡػೳ͕ແ͍ • ݁ہɺUIʹىҼ͢ΔϦΫΤετΑΓɺόοΫάϥϯυεϨουʗϓϩηεͰͷࣄલΩϟο γϡ͕Ұ൪༗ޮ • ͪ͜Βݱࡏ։ൃதͰۙதʹϦϦʔε͢Δ༧ఆ ͞ΒͳΔ՝ 7
·ͱΊ 8
·ͱΊ • ը૾Λऔಘɾදࣔ͢Δ͚ͩͰւ֎͚ΞϓϦͰେ͖ͳ՝ʹͳΔͷͰҙʂ • NewRelic SyntheticsͰ؆୯ʹࠃ֎͔ΒͷAPI࣮ߦΛγϛϡϨʔτͰ͖ΔͷͰΦεεϝ • ηΩϡϦςΟΛ୲อͭͭ͠ߴʹදࣔ͢Δઃܭͱ࣮ࣄྫ ·ͱΊ 8
ւ֎ͰࣗࣾͷαʔϏεΛޭ͍ͤͨ͞։ൃऀͷօ͞Μ ઈରʹޭͤ͞ΔͨΊͷใަΛ͠·͠ΐ͏
THANK YOU!!