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
デプロイ今昔物語 〜CGIからサーバーレスまで〜 / The deployment technics
Search
mackee
March 19, 2023
Programming
10
12k
デプロイ今昔物語 〜CGIからサーバーレスまで〜 / The deployment technics
YAPC::Kyoto 2023
mackee
March 19, 2023
Tweet
Share
More Decks by mackee
See All by mackee
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
perl for shell, awk and sed programmers
mackee
2
1.5k
今更GoのWebフレームワークを作ろうとしているワケ / Why am I trying to create a Go web framework now?
mackee
1
69
マイクロサービス化を利用した Goへの移行事例
mackee
0
120
PerlでつくるフルスクラッチWebAuthn/パスキー認証 / Demonstration of full-scratch WebAuthn/Passkey Authentication written in Perl
mackee
3
3.4k
SRE定例やその辺の取り組みをアプリケーションエンジニア目線で語る / "Observe" about SRE Meeting by Application Engineer
mackee
0
1.8k
TinyGoで使えるORM sqllaの 紹介とTinyGoで使えるようにするための工夫
mackee
0
1.2k
Go向けORM sqllaの紹介と JOINやUNIONを含んだクエリの扱い方
mackee
0
4.5k
E2Eテストから負荷試験シナリオを作ってみた / Why do we make a scenario of load testing from E2E testing scenarios
mackee
3
5.5k
Other Decks in Programming
See All in Programming
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
1
350
The rollercoaster of releasing an Android, iOS, and macOS app with Kotlin Multiplatform | droidcon Italy
prof18
0
150
layerx_20241129.pdf
kyoheig3
2
290
CSC509 Lecture 14
javiergs
PRO
0
130
MCP with Cloudflare Workers
yusukebe
2
220
useSyncExternalStoreを使いまくる
ssssota
6
1k
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
130
バグを見つけた?それAppleに直してもらおう!
uetyo
0
170
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
プロダクトの品質に コミットする / Commit to Product Quality
pekepek
2
760
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
The World Runs on Bad Software
bkeepers
PRO
65
11k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
510
Producing Creativity
orderedlist
PRO
341
39k
Agile that works and the tools we love
rasmusluckow
328
21k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
440
What's in a price? How to price your products and services
michaelherold
243
12k
Side Projects
sachag
452
42k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
28
900
Transcript
σϓϩΠࠓੲޠ ʙCGI͔ΒαʔόʔϨε·Ͱʙ @mackee_w a.k.a macopy
͢༰
σϓϩΠ
@macopy • ໘ന๏ਓΧϠοΫ eεϙʔπࣄۀ෦ TonamelαʔόαΠυςοΫϦʔυ • Perlେ͖ Go͖ • GGST༻Ωϟϥ:
ϥϜϨβϧ • ISUCON11 ༏উ / ISUCON12 ग़
[AD] Tonamel
[AD] Tonamel ࠓճͷτʔΫͰհ͢Δ ʮσϓϩΠʯͰ͍͏ͱ Tonamel ʮPullܕσϓϩΠʯ͔ͭ ʮDockerʯͰ͢
͜ͷτʔΫʹ͓͚ΔʮσϓϩΠʯͷൣғ • WebΞϓϦέʔγϣϯΛ։ൃͨ͠ޙ͔ΒɺϢʔβʔ͕ϒϥβͰݟΔ ·Ͱʹඞཁͳٕज़܈ • ʮσϦόϦʔʯͱݴ͏ • ྫ: • αʔόʔͷϓϩάϥϜͷөํ๏
• αʔόʔϓϩάϥϜͷϗεςΟϯάํ๏
!DISCLAIMER! ͜ͷτʔΫͰҟͳΔϨΠϠʔͷ֓೦͕ަޓ ʹग़͖ͯͨΓࠞͬͨ͟Γͯ͠͞Ε·͢ ॱ൪֓Ͷ࣌ܥྻͰͷొॱͰ͕͢ɺհ͢ ΔτϐοΫొஃऀͷڵຯͰܾΊ͍ͯ·͢
͜ͷτʔΫͷਐΊํ • ҎԼͷΛҰͭͷσϓϩΠٕज़ʹର͍͖ͯͯ͠͠·͢ •ख๏ͷղઆ •࣌എܠ •࣮ફ
͜ͷτʔΫͷਐΊํ • ҎԼͷΛҰͭͷσϓϩΠٕज़ʹର͍͖ͯͯ͠͠·͢ •ख๏ͷղઆ => Ͳ͏͍͏Έͳͷ͔ •ొഎܠ => ੜ·ΕͨܦҢ •࣮ફ
=> ͬͯΈΑ͏ɺମݧͯ͠ΈΑ͏
!DISCLAIMER! ͦͷ2 σϞʹ࣌ΘΕ͍ͯͨιϑτΣΞ (όʔδϣϯ)͍ͬͯ·ͤΜʂʂʂ ࠓݱࡏೖखͰ͖ΔͷΛ͍ͬͯ·͢
ొ͢ΔιϑτΣΞڥ • Perl 5.32.1(system perl), Perl 5.36.0 • Apache 2.4.54
• mod_perl 2.0.11 • Debian 11 bullseye • ݕূڥͱ͜ͷϚγϯؒtailscaleͰVPNΛு͍ͬͯ·͢
Are you ready?
CGI
CGIͷख๏
CGIͷొഎܠ • 1993ʹఏҊ͞Ε༷ͨ ͜ͷ࣌ͷόʔδϣϯ1.0 • NCSA httpdʹhtbinͱ͍͏ػೳ͕͕͋ͬͨɺଞͷαʔόʔͰ͑ ΔΑ͏ʹ”Common”ͳ༷͕ߟ͑ΒΕͨ • ࣌HTMLࡦఆ్্ͰɺWebΛऔΓר͘πʔϧνΣΠϯ͕ੜ·Ε
Δᴈ໌ظͱ͍ͬͨײ͡
ʮϨϯλϧαʔόʔʯ ※ҰྫͰ͢
࣮ફ: PerlͷCGIϓϩάϥϜΛσϓϩΠ
ඪ४ετϦʔϜͱڥม͕͋ΕͳΜͰ͓k • ϓϩάϥϛϯάݴޠඇґଘͰ͋Δ • PerlͰCGI͋·Γʹ͋Γ͖ͨΓͰ • ͔ͤͬ͘ݴޠඇґଘͳͷʹ͜ͷσϞͰͭ·Μͳ͍Ͱ͢ΑͶʁ
࣮ફ: jqͰCGIϓϩάϥϜΛ ॻ͍ͯσϓϩΠ
CGIͷσϝϦοτ • ϓϩηεىಈͷίετ͕ॏ͍ • ϦΫΤετͷͨͼʹϓϩηεΛىಈ͠ऴྃ͢Δ͜ͱʹͳΔ • PerlͷΑ͏ͳLLͰϞδϡʔϧͷಡΈࠐΈ͕ൃੜ͢Δ͜ͱʹ • ੲ`use`Ͱͳ͘`require`ΛͬͨDynamic Loading͕ଟ༻͞Ε
͍ͯͨͷͦͷ͍ͤͩͱฉ͍͍ͯ·͢
੩తΤϯυϙΠϯτͷϕϯνϚʔΫ
CGIͷϕϯνϚʔΫ
mod_perl
mod_perlͷख๏
mod_perlͷొഎܠ • 1996ʹmod_perl, 2002ʹmod_perl2͕ϦϦʔε • Apacheͷػೳ֦ுΛPerlͰߦ͏Ϟδϡʔϧ • Ͱ͋Δ͕CGIϓϩάϥϜΛͦͷ··ޮΑ͘ಈ͔ͨ͢ΊʹΘΕͨ • `ModPerl::Registry`ͷHandlerΛ͑CGIͱͷޓੑΛอͬͨ··͑Δ
• άϩʔόϧมͷण໋͕ϦΫΤετ୯ҐͰͳ͘ͳͬͨ • ཪΛฦͤϦΫΤετ୯ҐͰ͋ΔલఏͷCGIϓϩάϥϜͦͷ··Ͱಈ͔ͳ͍
࣮ફ: PerͷCGIϓϩάϥϜΛ mod_perlͰಈ͔͢
ྨࣅ • mod_mruby, mod_lua etc… • Perlͷ෦Λผͷݴޠʹஔ͖͑ͨApacheͷϞδϡʔϧ • ngx_http_perl_module •
nginxʹPerlΛΈࠐΜͰϦΫΤετॲཧͤ͞ΔϞδϡʔϧ
FastCGI
FastCGIͷख๏
FastCGIͷొഎܠ • 1996ʹఏএ͞Εͨ • mod_perlͷ༻్ͱಉ͘͡ʮCGIϓϩάϥϜͷߴԽʯ • ҰํͰɺmod_perlͱҧ͍ݴޠඇґଘΛࢦͨ͠ • શͳdrop-in replacementͰ͖ͳ͍͕ɺηϚϯςΟΫεCGI͔Β
Ҿ͖ܧ͍Ͱ͍Δ • 1ͭͷίωΫγϣϯͰϦΫΤετͷଟॏԽ͞Ε͍ͯΔ
࣮ફ: PerlͷFastCGI͚ϓϩάϥϜΛ ಈ͔͢
FastCGIͷྨࣅ • SpeedyCGI/PersistentPerl • CGIϓϩηεΛӬଓԽͯ͠ར༻͢Δվ͞ΕͨperlΠϯλϓϦλΛ ༻͍Δ • #!/usr/bin/speedy ʹshebangΛஔ͖͑Δͱར༻Ͱ͖Δ •
ApacheͱSpeedyCGIؒCGIͱಉ༷ඪ४ετϦʔϜ+ڥม
PSGI
PSGIͷొഎܠ • 2009ʹspec͕CPANʹshipit͞Εͨ • WebϑϨʔϜϫʔΫͷ࣌ʹͳ͍͕ͬͯͨɺWebϑϨʔϜϫʔΫ͕ͦΕ ͧΕɺCGIFastCGIɺmod_perl͚ͷରԠΛߦͳ͍ͬͯͨ… • ͦ͜ͰWebΞϓϦͷೖग़ྗΛநԽͨ͠ΠϯλʔϑΣΠεΛ༻ҙͯ͠ (=PSGI)ͦͷΠϯλʔϑΣΠεΛѻ͍ͨ͘͢͠ϥΠϒϥϦ(=Plack)Λ༻ ҙͯ͠ɺPlack::Handlerͱͯ͠CGImod_perlͷϋϯυϥ͕࣮͞Εͨ
PSGIͷొഎܠ ͦͷ2 • ҰํͰϓϩάϥϛϯάݴޠϥϯλΠϜࣗମͰHTTPαʔόʔΛಈ͔͢Α ͏ʹͳͬͨ • ”ϦόʔεϓϩΩγ”ͱ͍͏֓೦͕ҰൠతʹͳΓ࢝Ίͨ • lighttpd, nginx
etc… • Plack::Handlerͱͯ͠StarmanStarletͱ͍ͬͨPreforkܕͷHTTPαʔ όʔ͕࣮͞Εͯ͘ΘΕΔΑ͏ʹͳͬͨ
Plack/PSGIͷख๏
࣮ફ: ੜPSGIΛॻ͍ͯΈͨ
PSGIͷྨࣅ • Java Servelet API • WSGI (Python) • Rack
(Ruby) • ͜ͷॱ൪Ͱspecʹݴٴ͕͋Δ • PSGIʹWSGIͱRackͱ”JSGI”ʹݴٴ͕͋Δ
Plackͷྨࣅ(ΠϯλʔϑΣΠεࢹ) • ઌͨͪ • CGI.pm • CGI::Application • Apache::Request •
HTTP::Engine • Catalyst::Engine
͜Ε·ͰΞʔΩςΫνϟ ϓϩάϥϛϯάΠϯλʔϑΣΠεΛ த৺ʹ͝հ
͔͜͜Βαʔόʔͷ өํ๏ʹ͍ͭͯ͝հ
FTP
CGI/mode_perl/FastCGIͰFTPΛ ͬͯσϓϩΠ͍ͯͨ͠ͷͰলུ ※2023࣌ͷҙݟͰ͢
Pushܕ σϓϩΠ
PushܕσϓϩΠͷख๏
࣮ફ: PSGIΞϓϦΛ PushܕσϓϩΠ͢Δ
PushܕσϓϩΠͷ • αʔόʔ͕େ͖͘ͳΓ࢝Ίͨ • Push͢ΔଆͷϦιʔεͷͯ͠ σϓϩΠ͕͘ͳΔ • ύϒϦοΫΫϥυͷීٴͰΦʔ τεέʔϧ͢ΔΑ͏ʹͳ͕ͬͨɺ
ͦͷ߹ͷ৯͍߹Θ͕ͤѱ͍
Pullܕ σϓϩΠ
PullܕσϓϩΠͷख๏
࣮ફ: stretcherΛ༻͍ͨ PushܕσϓϩΠ
ΞʔΩςΫνϟͷհʹΔ
Docker
DockerΛͬͨσϓϩΠͷख๏
࣮ફ: Docker SwarmΛ༻͍ͨ DockerͷσϓϩΠ
Dockerͷొഎܠ • Dockerͷൃද2013 • PullܕσϓϩΠ • ʮίϯςφʯͱ͍͏ܗͰWebΞϓϦέʔγϣϯΛϥϯλΠϜ͝ͱ packͯ͠σϓϩΠ͢Δख๏ • ʮσϓϩΠʯͷର͕ΞϓϦέʔγϣϯϓϩάϥϜʹՃ͑ͯϥϯ
λΠϜ·Ͱ͕ͬͨ
Serverless
LambdaΛ༻͍ͨαʔόʔϨεͷख๏
࣮ફ: lambrollΛ༻͍ͨ Perl WebΞϓϦέʔγϣϯͷσϓϩΠ
Serverless/FaaSͷొഎܠ • ΞϓϦέʔγϣϯ੍࡞ऀ͕ཧ͢Δର͕࣌Λ͏͝ͱʹϨΠ Ϡʔ্͕ͱ্͕͍͍ͬͯͬͯͨ • ཧαʔόʔ, Ծαʔόʔ, IaaS, ίϯςφ •
ϥϯλΠϜϓϩηεͷϥΠϑαΠΫϧ·ͰΫϥυࣄۀऀʹ͓ئ͍ ͯ͠͠·͏ͷ͕Serverless • Ϩϯλϧαʔόʔ/CGIͷճؼ, ΑΓޮԽ͞Εͨͷ
Serverless/FaaSͷྨࣅ • PaaS • Heroku, Elastic Beanstalk, AppEngine(Flexible Environment)… •
ϥϯλΠϜͷΫϥυࣄۀऀ • ͨͩ͠αʔόʔతଘࡏ࣮֬ʹײ͡Δ, εέʔϦϯάઃఆͳͲ
͍͔͕Ͱͨ͠Ͱ͠ΐ͏͔
ొஃऀͷײ • σϓϩΠٕज़લʹΘΕٕͨज़ͷ՝Λղফ͢ΔͨΊʹੜ·Ε͖ͯͨ • ࢼߦࡨޡͷ݁Ռࠓ͕͋Δɻͭ·Γ “try/catch” Ͱ͢Ͷ • ͦΕͦΕͱͯ͠ɺੲͷٕज़ͰݟͲ͜Ζ͋Δ •
CGI͕ಈ͘ϨϯλϧαʔόʔFaaSͱݴ͑Δ • ੲΑΓWebΞϓϦέʔγϣϯ͕ղ͜͏ͱ͢Δ՝͕ෳࡶʹͳ͍ͬͯΔ ͷͰɺཧํ๏ͷҰͭͰ͋ΔʮσϓϩΠʯෳࡶʹͳΔ
͋ͳͨͷ͖ͳ ʮσϓϩΠʯ ͋Γ·͔ͨ͠ʁ
࠙ձͱ͔࿓ԼͰͯ͠ཉ͍͠ • 2000ΑΓલͷJavaͱ͔Ͳ͏ͬͯσϓϩΠ͍ͯͨ͠ͷ͔ʁ • warͰݻΊͯΛFTPͰυʔϯ͍ͯͨ͠, TomcatͰͱ͍͏͕͋Γ·͢ɻ༗ࣝऀ ͷํʑͲ͏ͧ • ASPͱ͔IISͱ͔Windows Server
• mod_perl͔FastCGIͲͪΒΛ͍͔ͬͯͨ • ͓͢͢ΊͷϨϯλϧαʔόʔ • ొஃऀXREAΛ͍ͬͯ·ͨ͠
࠙ձͱ͔࿓ԼͰͯ͠ཉ͍͠ ͦͷ2 • ϩʔϦϯάϦελʔτ, ϒϧʔάϦʔϯσϓϩΠ • graceful restart • PullܕσϓϩΠ+graceful
restartσϓϩΠ͕ΊͪΌΊͪΌ͔ͬͨ • ΠϯϑϥͷઃఆσϓϩΠͱΞϓϦέʔγϣϯͷσϓϩΠͷڥ