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
930
一方、私はなぜEMでありつづけるか / TECH TRACK vol.1
_atsushisakai
0
420
子育てとEMと転職と
_atsushisakai
2
760
「家族アルバム みてね」を支える エンジニアリング組織/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
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
180
Jakarta EE meets AI
ivargrimstad
0
250
HTTP compression in PHP and Symfony apps
dunglas
2
1.7k
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
ドメインイベント増えすぎ問題
h0r15h0
2
310
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
240
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
330
良いユニットテストを書こう
mototakatsu
8
2.4k
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
4
520
Refactor your code - refactor yourself
xosofox
1
260
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
130
命名をリントする
chiroruxx
1
410
Featured
See All Featured
Side Projects
sachag
452
42k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
Music & Morning Musume
bryan
46
6.2k
Designing for humans not robots
tammielis
250
25k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
How STYLIGHT went responsive
nonsquared
95
5.2k
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
A Philosophy of Restraint
colly
203
16k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
RailsConf 2023
tenderlove
29
940
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!!