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ϑϨʔϜϫʔΫ͕ͦΕ ͧΕɺCGI΍FastCGIɺmod_perl޲͚ͷରԠΛߦͳ͍ͬͯͨ… • ͦ͜ͰWebΞϓϦͷೖग़ྗΛந৅Խͨ͠ΠϯλʔϑΣΠεΛ༻ҙͯ͠ (=PSGI)ͦͷΠϯλʔϑΣΠεΛѻ͍΍ͨ͘͢͠ϥΠϒϥϦ(=Plack)Λ༻ ҙͯ͠ɺPlack::Handlerͱͯ͠CGI΍mod_perlͷϋϯυϥ͕࣮૷͞Εͨ

Slide 36

Slide 36 text

PSGIͷొ৔എܠ ͦͷ2 • ҰํͰϓϩάϥϛϯάݴޠϥϯλΠϜࣗମͰHTTPαʔόʔΛಈ͔͢Α ͏ʹͳͬͨ • ”ϦόʔεϓϩΩγ”ͱ͍͏֓೦͕ҰൠతʹͳΓ࢝Ίͨ • lighttpd, nginx etc… • Plack::Handlerͱͯ͠Starman΍Starletͱ͍ͬͨ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͸σϓϩΠ͕ΊͪΌΊͪΌ଎͔ͬͨ • ΠϯϑϥͷઃఆσϓϩΠͱΞϓϦέʔγϣϯͷσϓϩΠͷڥ໨