デプロイ今昔物語 〜CGIからサーバーレスまで〜 / The deployment technics
by
mackee
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
σϓϩΠࠓੲޠ ʙCGI͔ΒαʔόʔϨε·Ͱʙ @mackee_w a.k.a macopy
Slide 2
Slide 2 text
͢༰
Slide 3
Slide 3 text
σϓϩΠ
Slide 4
Slide 4 text
@macopy • ໘ന๏ਓΧϠοΫ eεϙʔπࣄۀ෦ TonamelαʔόαΠυςοΫϦʔυ • Perlେ͖ Go͖ • GGST༻Ωϟϥ: ϥϜϨβϧ • ISUCON11 ༏উ / ISUCON12 ग़
Slide 5
Slide 5 text
[AD] Tonamel
Slide 6
Slide 6 text
[AD] Tonamel ࠓճͷτʔΫͰհ͢Δ ʮσϓϩΠʯͰ͍͏ͱ Tonamel ʮPullܕσϓϩΠʯ͔ͭ ʮDockerʯͰ͢
Slide 7
Slide 7 text
͜ͷτʔΫʹ͓͚ΔʮσϓϩΠʯͷൣғ • WebΞϓϦέʔγϣϯΛ։ൃͨ͠ޙ͔ΒɺϢʔβʔ͕ϒϥβͰݟΔ ·Ͱʹඞཁͳٕज़܈ • ʮσϦόϦʔʯͱݴ͏ • ྫ: • αʔόʔͷϓϩάϥϜͷөํ๏ • αʔόʔϓϩάϥϜͷϗεςΟϯάํ๏
Slide 8
Slide 8 text
!DISCLAIMER! ͜ͷτʔΫͰҟͳΔϨΠϠʔͷ֓೦͕ަޓ ʹग़͖ͯͨΓࠞͬͨ͟Γͯ͠͞Ε·͢ ॱ൪֓Ͷ࣌ܥྻͰͷొॱͰ͕͢ɺհ͢ ΔτϐοΫొஃऀͷڵຯͰܾΊ͍ͯ·͢
Slide 9
Slide 9 text
͜ͷτʔΫͷਐΊํ • ҎԼͷΛҰͭͷσϓϩΠٕज़ʹର͍͖ͯͯ͠͠·͢ •ख๏ͷղઆ •࣌എܠ •࣮ફ
Slide 10
Slide 10 text
͜ͷτʔΫͷਐΊํ • ҎԼͷΛҰͭͷσϓϩΠٕज़ʹର͍͖ͯͯ͠͠·͢ •ख๏ͷղઆ => Ͳ͏͍͏Έͳͷ͔ •ొഎܠ => ੜ·ΕͨܦҢ •࣮ફ => ͬͯΈΑ͏ɺମݧͯ͠ΈΑ͏
Slide 11
Slide 11 text
!DISCLAIMER! ͦͷ2 σϞʹ࣌ΘΕ͍ͯͨιϑτΣΞ (όʔδϣϯ)͍ͬͯ·ͤΜʂʂʂ ࠓݱࡏೖखͰ͖ΔͷΛ͍ͬͯ·͢
Slide 12
Slide 12 text
ొ͢ΔιϑτΣΞڥ • Perl 5.32.1(system perl), Perl 5.36.0 • Apache 2.4.54 • mod_perl 2.0.11 • Debian 11 bullseye • ݕূڥͱ͜ͷϚγϯؒtailscaleͰVPNΛு͍ͬͯ·͢
Slide 13
Slide 13 text
Are you ready?
Slide 14
Slide 14 text
CGI
Slide 15
Slide 15 text
CGIͷख๏
Slide 16
Slide 16 text
CGIͷొഎܠ • 1993ʹఏҊ͞Ε༷ͨ ͜ͷ࣌ͷόʔδϣϯ1.0 • NCSA httpdʹhtbinͱ͍͏ػೳ͕͕͋ͬͨɺଞͷαʔόʔͰ͑ ΔΑ͏ʹ”Common”ͳ༷͕ߟ͑ΒΕͨ • ࣌HTMLࡦఆ్্ͰɺWebΛऔΓר͘πʔϧνΣΠϯ͕ੜ·Ε Δᴈ໌ظͱ͍ͬͨײ͡
Slide 17
Slide 17 text
ʮϨϯλϧαʔόʔʯ ※ҰྫͰ͢
Slide 18
Slide 18 text
࣮ફ: PerlͷCGIϓϩάϥϜΛσϓϩΠ
Slide 19
Slide 19 text
ඪ४ετϦʔϜͱڥม͕͋ΕͳΜͰ͓k • ϓϩάϥϛϯάݴޠඇґଘͰ͋Δ • PerlͰCGI͋·Γʹ͋Γ͖ͨΓͰ • ͔ͤͬ͘ݴޠඇґଘͳͷʹ͜ͷσϞͰͭ·Μͳ͍Ͱ͢ΑͶʁ
Slide 20
Slide 20 text
࣮ફ: jqͰCGIϓϩάϥϜΛ ॻ͍ͯσϓϩΠ
Slide 21
Slide 21 text
CGIͷσϝϦοτ • ϓϩηεىಈͷίετ͕ॏ͍ • ϦΫΤετͷͨͼʹϓϩηεΛىಈ͠ऴྃ͢Δ͜ͱʹͳΔ • PerlͷΑ͏ͳLLͰϞδϡʔϧͷಡΈࠐΈ͕ൃੜ͢Δ͜ͱʹ • ੲ`use`Ͱͳ͘`require`ΛͬͨDynamic Loading͕ଟ༻͞Ε ͍ͯͨͷͦͷ͍ͤͩͱฉ͍͍ͯ·͢
Slide 22
Slide 22 text
੩తΤϯυϙΠϯτͷϕϯνϚʔΫ
Slide 23
Slide 23 text
CGIͷϕϯνϚʔΫ
Slide 24
Slide 24 text
mod_perl
Slide 25
Slide 25 text
mod_perlͷख๏
Slide 26
Slide 26 text
mod_perlͷొഎܠ • 1996ʹmod_perl, 2002ʹmod_perl2͕ϦϦʔε • Apacheͷػೳ֦ுΛPerlͰߦ͏Ϟδϡʔϧ • Ͱ͋Δ͕CGIϓϩάϥϜΛͦͷ··ޮΑ͘ಈ͔ͨ͢ΊʹΘΕͨ • `ModPerl::Registry`ͷHandlerΛ͑CGIͱͷޓੑΛอͬͨ··͑Δ • άϩʔόϧมͷण໋͕ϦΫΤετ୯ҐͰͳ͘ͳͬͨ • ཪΛฦͤϦΫΤετ୯ҐͰ͋ΔલఏͷCGIϓϩάϥϜͦͷ··Ͱಈ͔ͳ͍
Slide 27
Slide 27 text
࣮ફ: PerͷCGIϓϩάϥϜΛ mod_perlͰಈ͔͢
Slide 28
Slide 28 text
ྨࣅ • mod_mruby, mod_lua etc… • Perlͷ෦Λผͷݴޠʹஔ͖͑ͨApacheͷϞδϡʔϧ • ngx_http_perl_module • nginxʹPerlΛΈࠐΜͰϦΫΤετॲཧͤ͞ΔϞδϡʔϧ
Slide 29
Slide 29 text
FastCGI
Slide 30
Slide 30 text
FastCGIͷख๏
Slide 31
Slide 31 text
FastCGIͷొഎܠ • 1996ʹఏএ͞Εͨ • mod_perlͷ༻్ͱಉ͘͡ʮCGIϓϩάϥϜͷߴԽʯ • ҰํͰɺmod_perlͱҧ͍ݴޠඇґଘΛࢦͨ͠ • શͳdrop-in replacementͰ͖ͳ͍͕ɺηϚϯςΟΫεCGI͔Β Ҿ͖ܧ͍Ͱ͍Δ • 1ͭͷίωΫγϣϯͰϦΫΤετͷଟॏԽ͞Ε͍ͯΔ
Slide 32
Slide 32 text
࣮ફ: PerlͷFastCGI͚ϓϩάϥϜΛ ಈ͔͢
Slide 33
Slide 33 text
FastCGIͷྨࣅ • SpeedyCGI/PersistentPerl • CGIϓϩηεΛӬଓԽͯ͠ར༻͢Δվ͞ΕͨperlΠϯλϓϦλΛ ༻͍Δ • #!/usr/bin/speedy ʹshebangΛஔ͖͑Δͱར༻Ͱ͖Δ • ApacheͱSpeedyCGIؒCGIͱಉ༷ඪ४ετϦʔϜ+ڥม
Slide 34
Slide 34 text
PSGI
Slide 35
Slide 35 text
PSGIͷొഎܠ • 2009ʹspec͕CPANʹshipit͞Εͨ • WebϑϨʔϜϫʔΫͷ࣌ʹͳ͍͕ͬͯͨɺWebϑϨʔϜϫʔΫ͕ͦΕ ͧΕɺCGIFastCGIɺmod_perl͚ͷରԠΛߦͳ͍ͬͯͨ… • ͦ͜ͰWebΞϓϦͷೖग़ྗΛநԽͨ͠ΠϯλʔϑΣΠεΛ༻ҙͯ͠ (=PSGI)ͦͷΠϯλʔϑΣΠεΛѻ͍ͨ͘͢͠ϥΠϒϥϦ(=Plack)Λ༻ ҙͯ͠ɺPlack::Handlerͱͯ͠CGImod_perlͷϋϯυϥ͕࣮͞Εͨ
Slide 36
Slide 36 text
PSGIͷొഎܠ ͦͷ2 • ҰํͰϓϩάϥϛϯάݴޠϥϯλΠϜࣗମͰHTTPαʔόʔΛಈ͔͢Α ͏ʹͳͬͨ • ”ϦόʔεϓϩΩγ”ͱ͍͏֓೦͕ҰൠతʹͳΓ࢝Ίͨ • lighttpd, nginx etc… • Plack::Handlerͱͯ͠StarmanStarletͱ͍ͬͨPreforkܕͷHTTPαʔ όʔ͕࣮͞Εͯ͘ΘΕΔΑ͏ʹͳͬͨ
Slide 37
Slide 37 text
Plack/PSGIͷख๏
Slide 38
Slide 38 text
࣮ફ: ੜPSGIΛॻ͍ͯΈͨ
Slide 39
Slide 39 text
PSGIͷྨࣅ • Java Servelet API • WSGI (Python) • Rack (Ruby) • ͜ͷॱ൪Ͱspecʹݴٴ͕͋Δ • PSGIʹWSGIͱRackͱ”JSGI”ʹݴٴ͕͋Δ
Slide 40
Slide 40 text
Plackͷྨࣅ(ΠϯλʔϑΣΠεࢹ) • ઌͨͪ • CGI.pm • CGI::Application • Apache::Request • HTTP::Engine • Catalyst::Engine
Slide 41
Slide 41 text
͜Ε·ͰΞʔΩςΫνϟ ϓϩάϥϛϯάΠϯλʔϑΣΠεΛ த৺ʹ͝հ
Slide 42
Slide 42 text
͔͜͜Βαʔόʔͷ өํ๏ʹ͍ͭͯ͝հ
Slide 43
Slide 43 text
FTP
Slide 44
Slide 44 text
CGI/mode_perl/FastCGIͰFTPΛ ͬͯσϓϩΠ͍ͯͨ͠ͷͰলུ ※2023࣌ͷҙݟͰ͢
Slide 45
Slide 45 text
Pushܕ σϓϩΠ
Slide 46
Slide 46 text
PushܕσϓϩΠͷख๏
Slide 47
Slide 47 text
࣮ફ: PSGIΞϓϦΛ PushܕσϓϩΠ͢Δ
Slide 48
Slide 48 text
PushܕσϓϩΠͷ • αʔόʔ͕େ͖͘ͳΓ࢝Ίͨ • Push͢ΔଆͷϦιʔεͷͯ͠ σϓϩΠ͕͘ͳΔ • ύϒϦοΫΫϥυͷීٴͰΦʔ τεέʔϧ͢ΔΑ͏ʹͳ͕ͬͨɺ ͦͷ߹ͷ৯͍߹Θ͕ͤѱ͍
Slide 49
Slide 49 text
Pullܕ σϓϩΠ
Slide 50
Slide 50 text
PullܕσϓϩΠͷख๏
Slide 51
Slide 51 text
࣮ફ: stretcherΛ༻͍ͨ PushܕσϓϩΠ
Slide 52
Slide 52 text
ΞʔΩςΫνϟͷհʹΔ
Slide 53
Slide 53 text
Docker
Slide 54
Slide 54 text
DockerΛͬͨσϓϩΠͷख๏
Slide 55
Slide 55 text
࣮ફ: Docker SwarmΛ༻͍ͨ DockerͷσϓϩΠ
Slide 56
Slide 56 text
Dockerͷొഎܠ • Dockerͷൃද2013 • PullܕσϓϩΠ • ʮίϯςφʯͱ͍͏ܗͰWebΞϓϦέʔγϣϯΛϥϯλΠϜ͝ͱ packͯ͠σϓϩΠ͢Δख๏ • ʮσϓϩΠʯͷର͕ΞϓϦέʔγϣϯϓϩάϥϜʹՃ͑ͯϥϯ λΠϜ·Ͱ͕ͬͨ
Slide 57
Slide 57 text
Serverless
Slide 58
Slide 58 text
LambdaΛ༻͍ͨαʔόʔϨεͷख๏
Slide 59
Slide 59 text
࣮ફ: lambrollΛ༻͍ͨ Perl WebΞϓϦέʔγϣϯͷσϓϩΠ
Slide 60
Slide 60 text
Serverless/FaaSͷొഎܠ • ΞϓϦέʔγϣϯ੍࡞ऀ͕ཧ͢Δର͕࣌Λ͏͝ͱʹϨΠ Ϡʔ্͕ͱ্͕͍͍ͬͯͬͯͨ • ཧαʔόʔ, Ծαʔόʔ, IaaS, ίϯςφ • ϥϯλΠϜϓϩηεͷϥΠϑαΠΫϧ·ͰΫϥυࣄۀऀʹ͓ئ͍ ͯ͠͠·͏ͷ͕Serverless • Ϩϯλϧαʔόʔ/CGIͷճؼ, ΑΓޮԽ͞Εͨͷ
Slide 61
Slide 61 text
Serverless/FaaSͷྨࣅ • PaaS • Heroku, Elastic Beanstalk, AppEngine(Flexible Environment)… • ϥϯλΠϜͷΫϥυࣄۀऀ • ͨͩ͠αʔόʔతଘࡏ࣮֬ʹײ͡Δ, εέʔϦϯάઃఆͳͲ
Slide 62
Slide 62 text
͍͔͕Ͱͨ͠Ͱ͠ΐ͏͔
Slide 63
Slide 63 text
ొஃऀͷײ • σϓϩΠٕज़લʹΘΕٕͨज़ͷ՝Λղফ͢ΔͨΊʹੜ·Ε͖ͯͨ • ࢼߦࡨޡͷ݁Ռࠓ͕͋Δɻͭ·Γ “try/catch” Ͱ͢Ͷ • ͦΕͦΕͱͯ͠ɺੲͷٕज़ͰݟͲ͜Ζ͋Δ • CGI͕ಈ͘ϨϯλϧαʔόʔFaaSͱݴ͑Δ • ੲΑΓWebΞϓϦέʔγϣϯ͕ղ͜͏ͱ͢Δ՝͕ෳࡶʹͳ͍ͬͯΔ ͷͰɺཧํ๏ͷҰͭͰ͋ΔʮσϓϩΠʯෳࡶʹͳΔ
Slide 64
Slide 64 text
͋ͳͨͷ͖ͳ ʮσϓϩΠʯ ͋Γ·͔ͨ͠ʁ
Slide 65
Slide 65 text
࠙ձͱ͔࿓ԼͰͯ͠ཉ͍͠ • 2000ΑΓલͷJavaͱ͔Ͳ͏ͬͯσϓϩΠ͍ͯͨ͠ͷ͔ʁ • warͰݻΊͯΛFTPͰυʔϯ͍ͯͨ͠, TomcatͰͱ͍͏͕͋Γ·͢ɻ༗ࣝऀ ͷํʑͲ͏ͧ • ASPͱ͔IISͱ͔Windows Server • mod_perl͔FastCGIͲͪΒΛ͍͔ͬͯͨ • ͓͢͢ΊͷϨϯλϧαʔόʔ • ొஃऀXREAΛ͍ͬͯ·ͨ͠
Slide 66
Slide 66 text
࠙ձͱ͔࿓ԼͰͯ͠ཉ͍͠ ͦͷ2 • ϩʔϦϯάϦελʔτ, ϒϧʔάϦʔϯσϓϩΠ • graceful restart • PullܕσϓϩΠ+graceful restartσϓϩΠ͕ΊͪΌΊͪΌ͔ͬͨ • ΠϯϑϥͷઃఆσϓϩΠͱΞϓϦέʔγϣϯͷσϓϩΠͷڥ