Slide 1

Slide 1 text

ͦΖͦΖPerlͰͷ HTTP/2ʹ͍ͭͯ ৮Ε͍ͨ Yuji Shimada @xaicron YAPC::Okinawa 2018 ONNASON Mar 03, 2018

Slide 2

Slide 2 text

͸͍

Slide 3

Slide 3 text

Έͳ͞Μԭೄ ͨͷ͠ΜͰ·͔͢ʂʁ

Slide 4

Slide 4 text

ΦϦΦϯ࠷ߴͰ͢Ͷʂʂ

Slide 5

Slide 5 text

ࣗ෼͸ւͿͲ͏͕େ޷͖Ͱ͢

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

ே͔ΒւͿͲ͏৯΂ΒΕͯ ࠷ߴͰ͢Ͷ

Slide 8

Slide 8 text

ͯ͞

Slide 9

Slide 9 text

͖ͬ͞ @kazuho ͞Μͷ τʔΫฉ͍ͨਓʙʁ

Slide 10

Slide 10 text

్த·Ͱ৸ͯͯେৎ෉Ͱ͢

Slide 11

Slide 11 text

HTTP/2ʹ͍ͭͯΘ͔Βͳ͍͜ ͱ͕͋Δਓ͸ @kazuho ͞Μ ʹฉ͜͏ʂʂ

Slide 12

Slide 12 text

Perlʹ͍ͭͯΘ͔Βͳ͍͜ͱ ͕͋Δਓ͸࠙਌ձͰ༗ࣝऀʹ ฉ͜͏ʂʂ

Slide 13

Slide 13 text

ͯ͞

Slide 14

Slide 14 text

HTTP/1.1ͱHTTP/2Ͳ͕ͬͪ ଎͍ͱࢥ͍·͔͢ʁ

Slide 15

Slide 15 text

H1ͱH2Ͳ͕ͬͪ͸΍͍ʁ • H1͕͸΍͍ • H2͕͸΍͍ • ৔߹ʹΑΔ • Θ͔Βͳ͍

Slide 16

Slide 16 text

H1ͱH2Ͳ͕ͬͪ͸΍͍ʁ • H1͕͸΍͍ • H2͕͸΍͍ • ৔߹ʹΑΔ • Θ͔Βͳ͍

Slide 17

Slide 17 text

͸͍

Slide 18

Slide 18 text

ΞδΣϯμ • HTTP/2ʹ͍ͭͯ • PerlͰHTTP/2Λѻ͓͏ • ͓·͚: gRPCͱPerl • ·ͱΊ

Slide 19

Slide 19 text

HTTP/2ʹ͍ͭͯ

Slide 20

Slide 20 text

HTTP/2஀ੜ·ͰͷܦҢ

Slide 21

Slide 21 text

͸͡ΊʹSPDY͕͋ͬͨ

Slide 22

Slide 22 text

͸͡ΊʹSPDY͕͋ͬͨ • 2009೥11݄ʹGoogle͕SPDYͷυϥϑτ࢓༷ Λެ։ • 2010೥6݄ʹϦϦʔε͞ΕͨChrome 6͔Βσ ϑΥϧτͰ༗ޮʹͳͬͨ

Slide 23

Slide 23 text

SPDYྑͦ͞͏ͩ͠ ඪ४Խ͠Α͏ʂʂ

Slide 24

Slide 24 text

ͷͪͷHTTP/2Ͱ͋Δ

Slide 25

Slide 25 text

ͷͪͷHTTP/2Ͱ͋Δ • ࠷ॳ͸HTTP/2.0ͱ͍͏໊લͩͬͨ • HTTP/2͕ਖ਼໊ࣜশʹ • 2015೥5݄ʹHTTP/2͕RFC 7540ͱͯ͠ެ։ • ಉ࣌ʹHPACK͕RFC 7541ͱͯ͠ެ։

Slide 26

Slide 26 text

໿16೥ͿΓʹHTTP͕ Ξοϓσʔτ͞Εͨʂʂ (ͦΕ·Ͱʹ΋ͪΐͪ͘ΐ͘มߋ͸͚͋ͬͨͲ΋)

Slide 27

Slide 27 text

SPDY͸Ͳ͏ͳͬͨʁ

Slide 28

Slide 28 text

SPDY͸Ͳ͏ͳͬͨʁ • SPDY͸όʔδϣϯ3.1Ͱऴྃ • SPDY4͸࠷ऴతʹHTTP/2ͷυϥϑτ14ͷΤ ΠϦΞεʹͳͬͨ • 2016/5/15ʹChrome͸SPDYͷαϙʔτΛऴ ྃ

Slide 29

Slide 29 text

SPDY͸HTTP/2ʹ ஔ͖׵Θͬͨʂ

Slide 30

Slide 30 text

ͱ͜ΖͰ

Slide 31

Slide 31 text

ͳͥHTTP/2(SPDY) ͕ඞཁʹͳͬͨʁ

Slide 32

Slide 32 text

ͳͥHTTP/2͕ඞཁʹͳͬͨʁ • HTTP/1.1ͷެ։ʢ1999೥ʣ͔Β10೥ܦͬͯɺ Webίϯςϯπͷ༰ྔ͕ग़དྷతʹ૿Ճ • ੩తϖʔδ͚ͩͰͳ͘ಈతϖʔδ͕૿͖͑ͯ ͨ • 1ϖʔδදࣔ͢ΔͨΊʹ਺ेճҎ্ͷϦΫΤ ετ͕ൃߦ͞ΕΔ͜ͱ΋βϥʹ

Slide 33

Slide 33 text

Web͕஗͘ͳ͖ͬͯͨʂʁ

Slide 34

Slide 34 text

Web͕஗͍͍͔ͭ͘ͷཧ༝(1) • ωοτϫʔΫͷଳҬ͕ڱ͍ʢ·ͩ·ͩ3Gճઢ΋ଟ͍ʣ • ղܾࡦͷྫ • ૹ৴͢ΔσʔλΛѹॖͯ͠ݮΒ͢ • ΑΓૣ͍ճઢΛීٴͤ͞Δ • 10GbpsͷݻఆճઢΛීٴͤ͞Δ • 5Gͷొ৔Ͱ௿஗Ԇ͔ͭ20Gbpsඈ͹ͤΔͧ • 120TbpsͷւఈέʔϒϧʹҾ͖௚͢ʢPLCNʣ

Slide 35

Slide 35 text

Web͕஗͍͍͔ͭ͘ͷཧ༝(2) • TCPʹແବ͕ଟ͍ • ղܾࡦͷྫ • ᫔᫓΢Οϯυ΢αΠζͷॳظ஋Λେ͖͘͢Δ • Google͕৽͍͠᫔᫓੍ޚΞϧΰϦζϜBBRΛ։ൃ • ͨͱ͑͹TCPΛ΍ΊͯUDPϕʔεͷQUICʹ͢Δ

Slide 36

Slide 36 text

Web͕஗͍͍͔ͭ͘ͷཧ༝(3) • HTTP/1.1ͷϓϩτίϧ্ͷ໰୊ʹىҼ • HTTP/2͸͜͜ʹΞϓϩʔνʂ

Slide 37

Slide 37 text

HTTP/1.1ͷ໰୊఺

Slide 38

Slide 38 text

HTTP/1.1ͷ໰୊఺ • 1ͭͷϦΫΤετ͕׬ྃ͢Δ·Ͱ࣍ͷϦΫΤετ Λૹ৴͢Δ͜ͱ͕Ͱ͖ͳ͍ • ଴͕ͪ࣌ؒແବ • ಉ͡HTTP HeaderΛԿ౓΋Կ౓΋ૹड৴͍ͯ͠Δ • ύέοτ͕ແବ

Slide 39

Slide 39 text

1ͭͷϦΫΤετ͕׬ྃ͢Δ ·Ͱ࣍ͷϦΫΤετΛૹ৴͢ Δ͜ͱ͕Ͱ͖ͳ͍ ↓ ϦΫΤετ͕௚ྻ

Slide 40

Slide 40 text

ϦΫΤετ͕௚ྻ • HTTP/1.1Ͱ͸1ͭͷTCPίωΫγϣϯʹରͯ͠ɺ1 ϦΫΤετ͕ऴΘΔ·Ͱ଴ͨͳͯ͘͸͍͚ͳ͍ • ChromeͰ͸1ͭͷυϝΠϯʹରͯ͠࠷େ6ͭ· ͰTCPίωΫγϣϯΛషΔ͜ͱͰߴ଎ԽΛ࣮ݱ ʢ౰ࣾൺ6ഒʣ • ͨͩ͠ɺHTTP/1.1ͷ࢓༷Ͱ͸2ͭ·Ͱʹ੍ݶ

Slide 41

Slide 41 text

ͦ͜Ͱ HTTPύΠϓϥΠϯ Ͱ͢Αʂ

Slide 42

Slide 42 text

HTTPύΠϓϥΠϯͱ͸ • 1ͭͷTCP্ͰϨεϙϯεΛ଴ͭ͜ͱͳ͘ϦΫ ΤετΛૹ৴͢Δ͜ͱ͕Ͱ͖Δ࢓༷

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

HTTPύΠϓϥΠϯ • ႈ౳ͳϦΫΤετͰ͔͠ར༻Ͱ͖ͳ͍ • GET΍HEAD͕࿈ଓ͢ΔϦΫΤετͰ͸ར༻Մೳ • PUT΍DELETEͰ΋ར༻Ͱ͖Δ৔߹͕͋Δ • Ϩεϙϯε͸ϦΫΤετΛૹͬͨॱ൪Ͱड৴͠ͳ͚Ε͹ͳΒͳ͍ • Head of Line (HOL) Blocking ͸݁ہൃੜ͢Δ • ຆͲͷϒϥ΢βͰ࣮૷͞Ε͍ͯͳ͍͔σϑΥϧτͰແޮ • ΫϥΠΞϯτଆ͸ߟྀ͢Δ͜ͱ͕ଟ࣮͘૷͕೉͍͠

Slide 45

Slide 45 text

ͦͷଞͷ༷ʑͳ࠷దԽ • Ϧιʔεͷ݁߹ • JavaScriptϑΝΠϧͷ݁߹΍ը૾ͷCSSεϓϥΠτʹΑΔϦΫΤετ ਺ͷ࡟ݮ • ը૾ͷΠϯϥΠϯԽ • base64ܗࣜͰը૾ΛHTMLʹຒΊࠐΉ͜ͱʹΑΔϦΫΤετ਺ͷ࡟ݮ • υϝΠϯγϟʔσΟϯά • ෳ਺ͷυϝΠϯΛར༻͢Δ͜ͱͰTCPͷಉ࣌઀ଓ਺Λ૿΍͢

Slide 46

Slide 46 text

ಉ͡HTTP HeaderΛԿ౓΋Կ ౓΋ૹ৴͍ͯ͠Δ

Slide 47

Slide 47 text

͕Μ͹ͬͯෆཁͳϔομʔΛ ৬ਓ͕࡟Δ͔͠ແ͍ʂʂ

Slide 48

Slide 48 text

HTTP/1.1Ͱ͸ ύϑΥʔϚϯεΛ্͛ΔͨΊ ʹϓϩτίϧҎ֎ͷͱ͜ΖͰ ͳΜͱ͔͠ͳ͚Ε͹͍͚ͳ͔ͬ ͨ

Slide 49

Slide 49 text

HTTP/2Ͱ͸ϓϩτίϧΛ վྑ͢Δ͜ͱͰղܾ͠Α͏ͱ ͨ͠

Slide 50

Slide 50 text

ͱ͍͏Θ͚Ͱ

Slide 51

Slide 51 text

HTTP/2ͷಛ௃

Slide 52

Slide 52 text

HTTP/2ͷಛ௃ • HTTP/1.1ͷηϚϯςΟΫεͱޓ׵ੑ͕͋Δ • ετϦʔϜ • όΠφϦϓϩτίϧ • HTTPϔομʔѹॖ • αʔόʔϓογϡ

Slide 53

Slide 53 text

HTTP/1.1ͷηϚϯςΟΫεͱ ޓ׵ੑ͕͋Δ • εΩʔϚ͸”http://“ٴͼ”https://“Λͦͷ··ར༻ • ϙʔτ͸80ͱ443Λͦͷ··ར༻ • HTTPϔομʔ΋΄΅ͦͷ··ར༻ • શͯখจࣈʹͳͬͨΓར༻ෆՄͷΩʔ͕͋ͬ ͨΓ͸͢Δ

Slide 54

Slide 54 text

ετϦʔϜ(1) • ༏ઌ౓෇͖શೋॏଟॏԽ௨৴ • ̍ͭͷTCPίωΫγϣϯ্Ͱෳ਺ͷετϦʔϜΛฒྻ ʹѻ͏͜ͱ͕Ͱ͖Δ • SETTINGS_MAX_CONCURRENT_STREAMSͰ࠷ େ஋Λઃఆ • ͦΕͧΕͷετϦʔϜ͸ಠཱ͍ͯͯ͠ϒϩοΫ͠ͳ͍

Slide 55

Slide 55 text

ετϦʔϜ(2) • ΫϥΠΞϯτɺαʔόʔͲͪΒ͔ΒͰ΋։࢝͢Δ͜ͱ͕Ͱ ͖Δ • ετϦʔϜIDͰ֤ετϦʔϜΛ؅ཧ͢Δ • ΫϥΠΞϯτ͸ح਺ɺαʔόʔ͸ۮ਺͔Β࢝ΊΔ͜ͱͰ ڝ߹Λճආ • ૹड৴͢Δσʔλ͸όΠφϦܗࣜ • ૹड৴͢Δσʔλ͸ϑϨʔϜͱ͍͏୯ҐͰૹड৴͢Δ

Slide 56

Slide 56 text

όΠφϦϓϩτίϧ • HTTP/2͸ϦΫΤετ/ϨεϙϯεʹϑϨʔϜͱ ͍͏όΠφϦϑΥʔϚοτͰσʔλͷ΍Γऔ ΓΛߦ͏ • ͍··ͰςΩετϓϩτίϧͰύʔε΍ղऍ͕ ͕ᐆດͩͬͨͱ͜Ζ͕ݫ֨ʹͳͬͨ

Slide 57

Slide 57 text

ϑϨʔϜͷϑΥʔϚοτ # 9ΦΫςοτͷϔομʔͱՄม௕ͷϖΠϩʔυ͔Β੒Δ # ͔ͬ͜ͷதͷ਺ࣈ͸1Ϗοτ +-----------------------------------------------+ | Length (24) | +---------------+---------------+---------------+ | Type (8) | Flags (8) | +-+-+-----------+---------------+-------------------------------+ |R| Stream Identifier (31) | +=+=============================================================+ | Frame Payload (0...) ... +———————————————————————————————+

Slide 58

Slide 58 text

ϑϨʔϜͷछྨ 5ZQF छྨ ໾ׂ %"5" ϦΫΤετϨεϙϯεͷϘσΟʔ )&"%&34 ϦΫΤετϨεϙϯεͷϔομʔ 13*03*5: ετϦʔϜͷ༏ઌॱҐΛࢦఆʢΫϥΠΞϯτͷΈʣ 345@453&". ΤϥʔͳͲͰετϦʔϜΛऴྃ͢Δͱ͖ʹ࢖༻ 4&55*/(4 ઀ଓઃఆΛมߋ͢Δ 164)@130.*4& αʔόʔϓογϡΛ༧ࠂ͢ΔʢαʔόʔͷΈʣ 1*/( ઀ଓͷੜଘ֬ೝ (0"8": ΤϥʔͳͲͰ઀ଓΛऴྃ͢Δͱ͖ʹ࢖༻ 8*/%08@61%"5& ΢Οϯυ΢αΠζΛมߋ͢Δ $0/5*/6"5*0/ αΠζͷେ͖ͳ)&"%&34164)@130.*4&ͷஅย

Slide 59

Slide 59 text

HTTPϔομʔѹॖ • “HPACK”ͱ͍͏ܗࣜͰϔομΛѹॖ͢Δ • SPDYͰ͸gzipΛ༻͍͍͕ͯͨʮCRIMEʯͱ͍ ͏߈ܸํ๏͕ݟ͔ͭͬͨͨΊผͷํ๏Ͱ࢓༷ ࡦఆ

Slide 60

Slide 60 text

HPACKͷಛ௃ • όΠφϦܗࣜ • ΩʔΛখจࣈʹ౷Ұ • Α͘࢖ΘΕΔϔομʔͷΩʔͱ஋Λ૊Έʹͨࣙ͠ॻΛ࣋ͭ • ಈతʹࣙॻΛߋ৽͠ɺ2ճ໨Ҏ߱͸ΠϯσοΫεΛ༻͍Δ • Ωʔ΍஋ͷจࣈྻΛϋϑϚϯූ߸Ͱѹॖ͢Δ͜ͱ΋Ͱ͖Δ

Slide 61

Slide 61 text

αʔόʔϓογϡ • HTTP/2Ͱ͸ΫϥΠΞϯτ͔ΒͷϦΫΤετ͕ͳ ͯ͘΋αʔόʔ͔ΒσʔλΛૹ৴͢Δ͜ͱ͕Ͱ ͖Δ • HTMLʹؔ࿈෇͚ΒΕ͍ͯΔCSS΍JavaScriptɺ ը૾ͳͲΛΫϥΠΞϯτͷϦΫΤετΛ଴ͨͣ ʹૹΓ͚ͭΒΕΔͷͰɺϖʔδදࣔ·Ͱͷ࣌ؒ ୹ॖ͕ݟࠐΊΔ

Slide 62

Slide 62 text

αʔόʔϓογϡͷྲྀΕ • ΫϥΠΞϯτ͕ετϦʔϜ1Ͱindex.htmlΛཁٻ • αʔόʔ͸index.htmlʹ͸style.css͕ؔ࿈͍͍ͮͯΔ͜ͱΛ஌͍ͬͯ ΔͷͰstyle.cssΛετϦʔϜ2Ͱϓογϡ͢ΔʢPUSH_PROMISEʣ • ετϦʔϜ1Ͱindex.htmlΛड͚औͬͨΫϥΠΞϯτ͸ϦΫΤετΛ ߦ͏͜ͱͳ͘style.cssͷ౸ணΛ଴ͭ • αʔόʔ͔ΒετϦʔϜ2ʹΑͬͯstyle.css͕ಧ͖ɺϨϯμϦϯάΛ ։࢝͢Δ

Slide 63

Slide 63 text

αʔόʔϓογϡͷ஫ҙ఺ • HTTP/2Λಋೖ͚ͨͩ͠Ͱࣗಈతʹ͜ͷΑ͏ͳڍಈʹͳΔΘ͚Ͱ ͸ͳ͍ • ΞϓϦέʔγϣϯଆͰઃఆ΍ϩδοΫΛ࣮૷͢Δඞཁ͕͋Δ • ϓογϡ͢Δίϯςϯπ͕ΫϥΠΞϯτͰΩϟογϡ͞Ε͍ͯ Δ͔Ͳ͏͔Θ͔Βͳ͍ͷͰແବͳϦΫΤετ͕ൃੜ͢ΔՄೳੑ ͕͋Δ • 103 Early HintsͳͲΛར༻͢Δ͜ͱͰΑΓޮ཰తʹͰ͖ΔՄ ೳੑ͕͋Δ

Slide 64

Slide 64 text

HTTP/2Ͱ઀ଓΛߦ͏ํ๏

Slide 65

Slide 65 text

HTTP/2Ͱ઀ଓΛߦ͏ํ๏ (http઀ଓͷ৔߹) • HTTP/1.1ͱޓ׵ੑ͕͋ΔͨΊɺΫϥΠΞϯτ͸HTTP/ 2ͰΞΫηεͰ͖Δ͔Ͳ͏͔Λ൑ఆ͠ͳͯ͘͸͍͚ͳ͍ • URL΍ϙʔτ൪߸͚ͩͰ͸൑அ͕Ͱ͖ͳ͍ • ΫϥΠΞϯτ͸HTTP/1.1ͰಛఆͷHTTPϔομʔΛૹ ৴͢Δ͜ͱͰαʔόʔ͕HTTP/2ʹରԠ͍ͯ͠Δ͔Ͳ͏ ͔൑அ͢Δ

Slide 66

Slide 66 text

HTTP/2Ͱ઀ଓΛߦ͏ํ๏ (http઀ଓͷ৔߹) • ϦΫΤετ࣌ʹ·ͣҎԼͷϔομʔΛ෇͚ͯ HTTP/1.1ϦΫΤετΛߦ͏ • Connection: Upgrade, HTTP2-Settings • Upgrade: h2c • HTTP2-Settings:

Slide 67

Slide 67 text

ॳճϦΫΤετͷྫ # http://www.example.com/ ʹϦΫΤετͨ͠৔߹ > GET / HTTP/1.1 > Host: www.example.com > Connection: Upgrade, HTTP2-Settings > Upgrade: h2c > HTTP2-Settings: AAMAAABkAARAAAAAAAIAAAAA

Slide 68

Slide 68 text

ॳճϦΫΤετͷྫ # http://www.example.com/ ʹϦΫΤετͨ͠৔߹ > GET / HTTP/1.1 > Host: www.example.com > Connection: Upgrade, HTTP2-Settings > Upgrade: h2c > HTTP2-Settings: AAMAAABkAARAAAAAAAIAAAAA < HTTP/1.1 101 Switching Protocols < Connection: Upgrade < Upgrade: h2c # ͔͜͜ΒHTTP/2઀ଓ < server: perl-Protocol-HTTP2/1.08 < content-length: 13 < cache-control: max-age=3600 < date: Thu, 01 Mar 2018 14:30:15 GMT < last-modified: Thu, 01 Mar 2018 14:30:15 GMT < hello, world!

Slide 69

Slide 69 text

HTTP/2Ͱ઀ଓΛߦ͏ํ๏ (http઀ଓͷ৔߹) • 101 Switching Protocol͕ฦ͖ͬͯͨΒ੒ޭ • ্هͷ͋ͱʹϦΫΤετΛૹΒͣʹHTTP/2 Ϩεϙϯε͕ฦ͖͍ͬͯͯΔͱ͜Ζ͕ϛι • ͍͍ͩͨWebSocketͱҰॹ

Slide 70

Slide 70 text

HTTP/2Ͱ઀ଓΛߦ͏ํ๏ (https઀ଓͷ৔߹) • HTTP/2͸TLS1.2Ҏ্͕ඞਢ • application-layer protocol negotiation (ALPN) extension ͕ར ༻Ͱ͖Δඞཁ͕͋Δ • ҉߸εΠʔτ͸ TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256Ҏ্͕ඞਢ • TLSϋϯυγΣΠΫ͕ऴΘͬͨޙʹʮHTTP/2ίωΫγϣϯϓϦ ϑΣΠεʯͱ͍͏24ΦΫςοτͷσʔλΛૹ৴͢Δ

Slide 71

Slide 71 text

ίωΫγϣϯϓϦϑΣΠε • “PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n” Λૹ৴ • ͜Ε͸HTTP/1.1ͷαʔόʔͩͱ PRI ͱ͍͏ METHOD ͱͯ͠ղऍ͞Εͯ౴͑ΒΕͳ͍ͷͰ HTTP/2ʹରԠ͍ͯ͠ͳ͍ͱ൑அͰ͖Δ • ௚ޙʹαʔόʔ͔Β SETTINGS ϑϨʔϜʢޙड़ʣ ͕ฦͬͯ͘Ε͹੒ޭ

Slide 72

Slide 72 text

͸͍

Slide 73

Slide 73 text

͜͜·Ͱ؆୯ʹͰ͕͢ HTTP/2ͷ֓ཁʹ͍ͭͯ৮Εͯ ͖·ͨ͠

Slide 74

Slide 74 text

·ͩ·ͩແݶʹ࿩୊͸͋Γ· ͢

Slide 75

Slide 75 text

ͨͱ͑͹ • ετϦʔϜͷ༏ઌ౓ • ϑϩʔ੍ޚ • HTTP/2࣌୅ͷυϝΠϯγϟʔσΟϯά • Smart Shadingͷݕ౼ • ίωΫγϣϯ࠶ར༻ͱϫΠϧυΧʔυূ໌ॻ • 421 Misdirected Requestͷར༻΍OriginϑϨʔϜͷݕ౼ • αʔόʔϓογϡͱϦόʔεϓϩΩγʔ • 103 Early Hintsͷར༻

Slide 76

Slide 76 text

࣮ࡍʹӡ༻͢ΔͱͳΔͱߟྀ ͢Δ͜ͱ͕͍ͬͺ͍

Slide 77

Slide 77 text

͕͍࣌ؒ͘Β͋ͬͯ΋ͨΓͳ ͍ͷͰࠓ೔͸Ұ୴͜͜·Ͱ

Slide 78

Slide 78 text

͜͜·Ͱͷ·ͱΊ • HTTP/1.1ͷϓϩτίϧΛվྑ͠ɺ͍͔ͭ͘ͷ େ͖ͳϘτϧωοΫΛղফ͢Δ͜ͱ͕Ͱ͖Δ Α͏ͳͬͨ • όΠφϦʹͳͬͨΓɺετϦʔϜ΍HPACKͳ Ͳ৽͍֓͠೦͕૿͑ͯͪΐͬͱෳࡶʹͳͬͨ

Slide 79

Slide 79 text

PerlͰHTTP/2Λѻ͓͏

Slide 80

Slide 80 text

PerlͰͷHTTP/2ͷରԠঢ়گ • http-perlͱProtocol::HTTP2 ͱ͍͏ϥΠϒϥ Ϧʔ͕͋Δ • http-perl͸h2-04ʢυϥϑτ4ʣͰ։ൃ͕ധ ·͍ͬͯΔ • Protocol::HTTP2 Ұ୒

Slide 81

Slide 81 text

https://github.com/http2/http2-spec/wiki/Implementations

Slide 82

Slide 82 text

΄΅શͯͷػೳ͕ ࣮૷͞Ε͍ͯΔʂʂ

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

Protocol::HTTP2ͷಛ௃ • TPCίωΫγϣϯͷ؅ཧ͸΍ͬͯ͘Εͳ͍ͷͰࣗ෼ Ͱ΍Δඞཁ͕͋Δ • ετϦʔϜͷ؅ཧΛ΍ͬͯ͘ΕΔ • ϑϨʔϜ΍HTTPϔομʔͷencode/decode΋΍ͬ ͯ͘ΕΔ • LWP΍Furl΄Ͳ؆୯Ͱ͸ͳ͍ʂ

Slide 85

Slide 85 text

ͱ͍͏Θ͚Ͱ࣮ࡍʹ࢖ͬͯΈ ·͠ΐ͏

Slide 86

Slide 86 text

Protocol::HTTP2Λ࢖ͬͯΈΔ • Protocol::HTTP2::ClientͰHTTP/2ͳαʔόʔʹΞΫηεͯ͠ΈΔ • Protocol::HTTP2::ServerͰαʔόʔΛͨͯΔ • ฒྻϦΫΤετΛࢼ͢ • αʔόʔϓογϡΛࢼ͢ • PSGIͰHTTP/2 • TLSͰૹड৴͢Δ

Slide 87

Slide 87 text

Protocol::HTTP2::ClientͰ HTTP/2ͳαʔόʔʹΞΫηε ͯ͠ΈΔ

Slide 88

Slide 88 text

ࠓճ͸ ͏·͘ಈ͔ͳ͔ͬͨͷͰ ࠷ॳ͔ΒHTTP/2ͩͱΘ͔ͬͯ ͍ΔͷͰUpgradeͷॲཧ͸ε Ωοϓ͠·͢

Slide 89

Slide 89 text

HTTP/2 ClientΛࢼ͢ • ͱΓ͋͑ͣαʔόʔ͸ϩʔΧϧʹ nghttpd ͱ ͍͏΍ͭΛ —no_tls Ͱཱͯ·͢ • ΧϨϯτσΟϨΫτϦͷϑΝΠϧΛදࣔͯ͘͠ ΕΔͷͰద౰ʹ index.html ΛͰ্ͬͪ͛·͢ • Protocol::HTTP2::ClientͰΞΫηεͯ͠Έ·͢

Slide 90

Slide 90 text

nghttpdΛىಈ͢Δ $ echo 'Hello, HTTP/2!!' >! index.html # index.html Λ࡞͓ͬͯ͘ $ nghttpd —no-tls -v 8080 IPv6: listen :::8080 IPv4: listen 0.0.0.0:8080

Slide 91

Slide 91 text

ClientΦϒδΣΫτͷ࡞੒ use Protocol::HTTP2::Client; use Protocol::HTTP2::Constant qw(constant_name); my $client = Protocol::HTTP2::Client->new( on_change_state => sub { my ($stream_id, $previous_state, $current_state) = @_; printf( "Stream %i changed state from %s to %s\n", $stream_id, const_name(states => $previous_state), const_name(states => $current_state), ); }, on_error => sub { my $error = shift; printf "Error occurred: %s\n", const_name(errors => $error); }, );

Slide 92

Slide 92 text

ϦΫΤετͷ࡞੒ (͜ͷ࣌఺Ͱ͸·ͩϦΫΤετ͸ඈ͹ͳ͍) my $port = 80; my $host = ‘example.com'; $client->request( # HTTP/2 headers ':scheme' => 'http', ':authority' => "$host:$port", ':path' => '/', ':method' => 'GET', # HTTP/1.1 headers headers => [ 'accept' => '*/*', 'user-agent' => "perl-Protocol-HTTP2/$Protocol::HTTP2::VERSION", ], on_done => sub { my ($headers, $data) = @_; use Data::Dumper; warn Dumper [ $headers, $data ]; }, );

Slide 93

Slide 93 text

tcpίωΫγϣϯΛுΔ use AnyEvent; use AnyEvent::Socket; use AnyEvent::Handler; my $w = AnyEvent->condvar; tcp_connect $host, $port, sub { my ($fh) = @_ or die “connection failed: $!”; my $handle; $handle = AnyEvent::Handle->new( fh => $fh, autocork => 1, on_error => sub { $_[0]->destroy; warn "connection error\n” $w->send; }, on_eof => sub { $handle->destroy; $w->send; }, ); # ࣍ͷεϥΠυʹͭͮ͘ }; $w->recv;

Slide 94

Slide 94 text

ϦΫΤετΛૹड৴͢Δ tcp_connect $host, $port, sub { … # ϦΫΤετΛૹ৴ while (my $frame = $client->next_frame) { $handle->push_write($frame); } # ϨεϙϯεΛॲཧ $handle->on_read(sub { my $handle = shift; $client->feed(delete $handle->{rbuf}); while (my $frame = $client->next_frame) { $handle->push_write($frame); } $handle->push_shutdown if $client->shutdown; }); }; $w->recv;

Slide 95

Slide 95 text

ΰϦΰϦͷAnyEventʂʂ

Slide 96

Slide 96 text

࣮ߦͯ͠Έ·͢ $ perl no_tls_client.pl Stream 1 changed state from IDLE to HALF_CLOSED Stream 1 changed state from HALF_CLOSED to CLOSED [ [ ":status", "200", "server", "nghttpd nghttp2/1.30.0", "cache-control", "max-age=3600", "date", "Fri, 02 Mar 2018 11:03:24 GMT", "content-length", "16", "last-modified", "Fri, 02 Mar 2018 11:02:50 GMT" ], "Hello, HTTP/2!!\n" ]

Slide 97

Slide 97 text

͏·͍ͬͨͧ͘ʂʂʂ

Slide 98

Slide 98 text

ϓϩάϥϜʹ౉ͬͯ͘Δϔο μʔ͸ͪΌΜͱಡΊΔײ͡Ͱ ͕͢ɺϦΫΤετத͸HPACK Ͱѹॖ͞Ε͍ͯ·͢

Slide 99

Slide 99 text

࣍͸ Protocol::HTTP2::ServerͰ αʔόʔΛཱͯͯΈ·͠ΐ͏

Slide 100

Slide 100 text

αʔόʔͷ࣮૷ my $w = AnyEvent->condvar; tcp_server '127.0.0.1', 8080, sub { my ($fh, $peer_host, $peer_port) = @_; my $handle; $handle = AnyEvent::Handle->new( fh => $fh, autocork => 1, on_error => sub { my ($handle, $fatal, $message) = @_; $handle->destroy; say "connection error (fatal: $fatal, message: $message)"; }, on_eof => sub { $handle->destroy; }, ); # ࣍ͷεϥΠυ΁ }; $w->recv;

Slide 101

Slide 101 text

αʔόʔͷ࣮૷ tcp_server '127.0.0.1', 8080, sub { … my $server; $server = Protocol::HTTP2::Server->new( on_request => sub { my ($stream_id, $headers, $data) = @_; my $message = "hello, world!"; $server->response( ':status' => 200, stream_id => $stream_id, headers => [ 'server' => 'perl-Protocol-HTTP2/1.08', 'content-length' => length($message), ], data => $message, ); }, ); # ࣍ͷεϥΠυʹଓ͘ }; $w->recv;

Slide 102

Slide 102 text

αʔόʔͷ࣮૷ tcp_server '127.0.0.1', 8080, sub { … while (my $frame = $server->next_frame) { $handle->push_write($frame); } $handle->on_read(sub { my $handle = shift; $server->feed($handle->{rbuf}); $handle->{rbuf} = undef; while (my $frame = $server->next_frame) { $handle->push_write($frame); } $handle->push_shutdown if $server->shutdown; }); }; $w->recv;

Slide 103

Slide 103 text

αʔόʔΛىಈͯ͠ ϦΫΤετૹͬͯΈΔ $ perl no_tls_server.pl $ perl no_tls_client.pl Stream 1 changed state from IDLE to HALF_CLOSED Stream 1 changed state from HALF_CLOSED to CLOSED [ [ ":status", "200", "server", "perl-Protocol-HTTP2/1.08" ], "hello, world!" ]

Slide 104

Slide 104 text

΍ͬͨʔʂಈ͍ͨͧʂʂ

Slide 105

Slide 105 text

ͯ͞

Slide 106

Slide 106 text

HTTP/2Ͱ͸1ͭͷTCP্Ͱෳ ਺ͷετϦʔϜΛѻ͑ΔΜͰ ͨ͠

Slide 107

Slide 107 text

ฒྻϦΫΤετΛࢼ͢ • ΫϥΠΞϯτଆͰ͸request()Λෳ਺ճൃߦ͢Δ͜ͱͰෳ਺ͷ ετϦʔϜΛੜ੒͠ɺฒྻͰϦΫΤετΛૹ৴͢Δ͜ͱ͕Մೳ ʹͳΔ • ࠓճ͸ετϦʔϜ1Ͱ”dummy.iso”ͱ͍͏ͦΕͳΓͷαΠζͷ ϑΝΠϧΛऔಘ͠ɺετϦʔϜ3ͷ΄͏͕ૣ͘Ϩεϙϯε͕ ฦͬͯ͘Δ͜ͱΛ֬ೝ͢Δ • ϦΫΤετͷετϦʔϜID͸ح਺ͳͷͰ1ͷ࣍͸3ʹͳΓ· ͢

Slide 108

Slide 108 text

ฒྻϦΫΤετΛࢼ͢ ʢΫϥΠΞϯτଆൈਮʣ $client->request( # ετϦʔϜ1 # HTTP/2 headers ':scheme' => 'http', ':authority' => "$host:$port", ':path' => “/dummy.iso", # ڊେͳϑΝΠϧͷऔಘ ':method' => 'GET', … )->request( # ετϦʔϜ3 # HTTP/2 headers ':scheme' => 'http', ':authority' => "$host:$port", ':path' => "/", ':method' => 'GET', … );

Slide 109

Slide 109 text

ฒྻϦΫΤετΛࢼ͢ ʢαʔόʔଆൈਮʣ on_request => sub { my ($stream_id, $headers, $data) = @_; my $header_map = { @$headers }; if ($header_map->{':path'} eq '/') { # path ͰॲཧΛৼΓ෼͚Δ # લͱҰॹ } elsif ($header_map->{':path'} eq '/dummy.iso') { aio_load './dummy.iso', sub { # ಡΈࠐΈͰϒϩοΫ͠ͳ͍Α͏ʹ aio_load Λ࢖༻ my ($data) = @_; $server->response( ':status' => 200, stream_id => $stream_id, headers => [ 'server' => 'perl-Protocol-HTTP2/1.08', 'content-length' => length($data), ], data => $data, ); }; } },

Slide 110

Slide 110 text

࣮ࡍʹࢼͯ͠ΈΔ $ perl no_tls_server_multistream.pl $ perl no_tls_client_multistream.pl Stream 1 changed state from IDLE to HALF_CLOSED Stream 3 changed state from IDLE to HALF_CLOSED Stream 3 changed state from HALF_CLOSED to CLOSED [ [ ":status", "200", "server", "perl-Protocol-HTTP2/1.08", "content-length", "13" ] ] Stream 1 changed state from HALF_CLOSED to CLOSED [ [ ":status", "200", "server", "perl-Protocol-HTTP2/1.08", "content-length", "102400" ] ]

Slide 111

Slide 111 text

؆୯Ͱ͢Ͷʢʁʣ

Slide 112

Slide 112 text

αʔόʔ࣮૷ͷ஫ҙ఺ • αʔόʔʹؔͯ͠͸ී௨ʹHeaderΛνΣοΫͯͦ͠ΕͧΕͷॲཧΛॻ͍ ͍ͯ͘͜ͱͰWebΞϓϦέʔγϣϯΛ͍··Ͱ௨Γʹ࣮૷ग़དྷ·͢Ͷ • ͨͩ͠ɺશͯͷϦΫΤετͰϒϩοΩϯά͠ͳ͍Α͏ʹࡉ৺ͷ஫ҙΛ෷ ͏ඞཁ͕͋Δ • DB΍memcachedɺredisͳͲͷΞΫηε΍ϩάϑΝΠϧ΁ͷॻ͖ࠐ ΈͳͲ͢΂ͯAnyEvent΍CoroͳͲΛར༻ͯ͠ϒϩοΩϯά͠ͳ͍Α ͏ʹ͢Δ • ϛεΔͱશͯͷϦΫΤετ͕٧·Γ·͢

Slide 113

Slide 113 text

͸͍

Slide 114

Slide 114 text

ੈͷதͷϒϥ΢β͸h2Ͱ͔͠ جຊతʹΞΫηεͯ͜͠ͳ͍ ΜͰͨ͠

Slide 115

Slide 115 text

ͳͷͰTLSʹରԠ͢Δඞཁ͕ ͋Γ·͢

Slide 116

Slide 116 text

TLSʹରԠ • ࠓճ͸Let’s EncryptͰ࡞੒ͨ͠ূ໌ॻΛར༻ • ݸਓͰ͍࣋ͬͯΔυϝΠϯΛར༻͠ɺΠϯλʔωοτʹ ެ։ʂ • αʔόʔɺΫϥΠΞϯτͱ΋ʹίωΫγϣϯΛTLSʹରԠ ͤ͞Δ • ͲͪΒ΋AnyEvent::HandlerΛ࢖͍ͬͯΔͱ͜ΖΛվम

Slide 117

Slide 117 text

TLSʹରԠ ʢαʔόʔฤʣ Net::SSLeay::initialize(); tcp_server ‘127.0.0.1’, 443, sub { my ($fh, $peer_host, $peer_port) = @_; my $tls; eval { $tls = AnyEvent::TLS->new( method => 'TLSv1_2', cert_file => ‘/etc/letsencrypt/live/http2-test.api.moe/fullchain.pem’, key_file => ‘/etc/letsencrypt/live/http2-test.api.moe/privkey.pem’, ); # ͜͜Ͱ҉߸εΠʔτΛબ୒͢Δ # ࣍ͷεϥΠυ΁ }; if ($@) { print "Some problem with SSL CTX: $@\n"; $w->send; return; } …

Slide 118

Slide 118 text

TLSʹରԠ ʢαʔόʔฤʣ … eval { … # ECDH curve ( Net-SSLeay >= 1.56, openssl >= 1.0.0 ) if (exists &Net::SSLeay::CTX_set_tmp_ecdh) { my $curve = Net::SSLeay::OBJ_txt2nid('prime256v1'); my $ecdh = Net::SSLeay::EC_KEY_new_by_curve_name($curve); Net::SSLeay::CTX_set_tmp_ecdh( $tls->ctx, $ecdh ); Net::SSLeay::EC_KEY_free($ecdh); } # ALPN (Net-SSLeay > 1.55, openssl >= 1.0.2) if (exists &Net::SSLeay::CTX_set_alpn_select_cb) { Net::SSLeay::CTX_set_alpn_select_cb( $tls->ctx, [Protocol::HTTP2::ident_tls] ); } # NPN (Net-SSLeay > 1.45, openssl >= 1.0.1) elsif (exists &Net::SSLeay::CTX_set_next_protos_advertised_cb) { Net::SSLeay::CTX_set_next_protos_advertised_cb( $tls->ctx, [Protocol::HTTP2::ident_tls] ); } }; # ࣍ͷεϥΠυ΁

Slide 119

Slide 119 text

TLSʹରԠ ʢαʔόʔฤʣ my $handle; $handle = AnyEvent::Handle->new( fh => $fh, tls => 'accept', tls_ctx => $tls, autocork => 1, on_error => sub { my ($handle, $fatal, $message) = @_; $handle->destroy; warn "connection error (fatal: $fatal, message: $message)"; }, on_eof => sub { $handle->destroy; }, );

Slide 120

Slide 120 text

ΊͪΌͪ͘Ό ढจͩΒ͚Ͱ͢Ͷʂʂ

Slide 121

Slide 121 text

Ұ୴͜ΕͰىಈͯ͠Έͯcurl ͰΞΫηεͯ͠Έ·͠ΐ͏

Slide 122

Slide 122 text

TLSʹରԠ͔ͨ֬͠ೝ $ curl -v —http2 https://http2-test.api.moe/ தུ… * Using HTTP2, server supports multi-use * Connection state changed (HTTP/2 confirmed) * Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0 * Using Stream ID: 1 (easy handle 0x7ff59c00cc00) > GET / HTTP/2 > Host: http2-test.api.moe > User-Agent: curl/7.54.0 > Accept: */* > * Connection state changed (MAX_CONCURRENT_STREAMS updated)! < HTTP/2 200 < server: perl-Protocol-HTTP2/1.08 < content-length: 21 < cache-control: max-age=3600 < date: Fri, 02 Mar 2018 14:58:59 GMT < last-modified: Fri, 02 Mar 2018 14:58:59 GMT < * Connection #0 to host http2-test.api.moe left intact Hello, HTTP/2 World!!

Slide 123

Slide 123 text

͍͚ͨͬΆ͍Ͱ͢Ͷʂ

Slide 124

Slide 124 text

ͭ͗͸ΫϥΠΞϯτଆ΋ରԠ ͠·͠ΐ͏

Slide 125

Slide 125 text

TLSʹରԠ ʢΫϥΠΞϯτฤʣ Net::SSLeay::initialize(); tcp_connect $host, $port, sub { my ($fh) = @_ or die "connection failed: $!"; my $tls; eval { $tls = AnyEvent::TLS->new(method => ‘TLSv1_2’); # ALPN (Net-SSLeay > 1.55, openssl >= 1.0.2) if (exists &Net::SSLeay::CTX_set_alpn_protos) { Net::SSLeay::CTX_set_alpn_protos( $tls->ctx, [Protocol::HTTP2::ident_tls] ); } # NPN (Net-SSLeay > 1.45, openssl >= 1.0.1) elsif (exists &Net::SSLeay::CTX_set_next_proto_select_cb) { Net::SSLeay::CTX_set_next_proto_select_cb( $tls->ctx, [Protocol::HTTP2::ident_tls] ); } else { die "ALPN and NPN is not supported\n"; } }; # ࣍ͷεϥΠυ΁

Slide 126

Slide 126 text

TLSʹରԠ ʢΫϥΠΞϯτฤʣ … my $handle; $handle = AnyEvent::Handle->new( fh => $fh, tls => "connect", tls_ctx => $tls, autocork => 1, on_error => sub { $_[0]->destroy; print "connection error\n"; $w->send; }, on_eof => sub { $handle->destroy; $w->send; } ); …

Slide 127

Slide 127 text

ΫϥΠΞϯτଆ΋΄΅αʔόʔ ͱҰॹͰ͢Ͷ

Slide 128

Slide 128 text

͜ΕͰΞΫηεͯ͠Έ·͢

Slide 129

Slide 129 text

TLSʹରԠ͔ͨ֬͠ೝ $ perl tls_client.pl [/Users/shimada.yuji/misc/yapc-okinawa] Stream 1 changed state from IDLE to HALF_CLOSED Stream 1 changed state from HALF_CLOSED to CLOSED [ [ ":status", "200", "server", "perl-Protocol-HTTP2/1.08", "content-length", "21", "cache-control", "max-age=3600", "date", "Fri, 02 Mar 2018 15:24:03 GMT", "last-modified", "Fri, 02 Mar 2018 15:24:03 GMT" ], "Hello, HTTP/2 World!!" ]

Slide 130

Slide 130 text

ͪΌΜͱΞΫηεͰ͖·ͨ͠ Ͷʂʂ

Slide 131

Slide 131 text

͜ΕͰଞͷαΠτ΋ී௨ʹ HTTP/2ͰΞΫηεͰ͖ΔΑ͏ ʹͳΓ·ͨ͠

Slide 132

Slide 132 text

HTTP/2͔͠ରԠ͍ͯ͠ͳ͍α Πτ΋εΫϨΠϐϯά͠์୊ Ͱ͢Ͷʁ

Slide 133

Slide 133 text

No content

Slide 134

Slide 134 text

͜͜Ͱࣗ෼ͷ࡞ͬͨ Ϟδϡʔϧͷ঺հ

Slide 135

Slide 135 text

Net::APNs::HTTP2

Slide 136

Slide 136 text

Net::APNs::HTTP2 • Appleͷϓογϡ௨஌Λαʔόʔ͔ΒૹΕΔ΍ ͭ • ฒྻϦΫΤετΛ؆୯ʹߦ͏͜ͱ͕Ͱ͖Δ • ಺෦Ͱ͸Protocol::HTTP2::Clientͱ AnyEvent::TLSΛར༻

Slide 137

Slide 137 text

͜Μͳײ͡Ͱ࢖͑Δ(1) my $apns = Net::APNs::HTTP2->new( is_development => 1, auth_key => 'auth_key.p8', key_id => $key_id, team_id => $team_id, bundle_id => $bundle_id, );

Slide 138

Slide 138 text

͜Μͳײ͡Ͱ࢖͑Δ(2) while (1) { # ͜Ε͸ͳʹ͔͠Βͷαʔόʔͱ͔ϫʔΧʔͰӬଓతʹಈ࡞͍ͯ͠Δͱࢥ͍ͬͯͩ͘͞ $apns->prepare($device_token, { aps => { alert => 'some message', badge => 1, }, }, sub { my ($header, $content) = @_; # $header = [ # ":status" => "200", # "apns-id" => "82B34E17-370A-DBF4-5046-FF56A4EA1FAF", # ]; ... }); # You can chainged $apns->prepare(...)->prepare(...)->prepare(...); # send all prepared requests in parallel $apns->send; # do something } # must call `close` when finished $apns->close;

Slide 139

Slide 139 text

Net::APNs::HTTP2 • version 0.01͚ͩͲී௨ʹϓϩμΫγϣϯͰಈ ͍ͯ·͢ • ຖ೔਺ඦ݅Ҏ্ͷϓογϡ௨஌Λݩؾʹૹ৴த • ͥͻ࢖ͬͯΈ͍ͯͩ͘͞ʂʂ • ϑΟʔυόοΫ΋͓Ͷ͕͍͠·͢ʂʂ

Slide 140

Slide 140 text

ؓ࿩ٳ୊

Slide 141

Slide 141 text

ͦΖͦΖαʔόʔϓογϡΛ ࣮૷ͯ͠Έ·͠ΐ͏

Slide 142

Slide 142 text

αʔόʔϓογϡΛ࣮૷͢Δ • “/push.html”ʹϦΫΤετΛߦ͏ͱ”/style.css”͕αʔ όʔϓογϡ͞ΕΔΑ͏ʹ͢Δ • มߋ͢Δ৔ॴ͸ on_request() ͷதͷΈ • push() ͸ response() ΑΓ΋ઌʹهड़͠ͳ͚Ε͹ͳΒͳ͍ • ChromeͰΞΫηε͠style.cssͷinitiatorʹ”Push”ͱग़ͯ ͍ͨΒ੒ޭ

Slide 143

Slide 143 text

αʔόʔϓογϡͷ࣮૷ if ($header_map->{':path'} eq '/push.html') { $server->push( ':authority' => $host . ':' . $port, ':method' => 'GET', ':path' => '/style.css', ':scheme' => 'https', stream_id => $stream_id, ); aio_load './push.html', sub { my ($data) = @_; $server->response( ':status' => 200, stream_id => $stream_id, headers => [ 'server' => 'perl-Protocol-HTTP2/1.08', 'content-length' => length($data), 'content-type' => 'text/html', ], data => $data, ); }; } elsif ($header_map->{':path'} eq '/style.css') { # ࣍ͷεϥΠυ }

Slide 144

Slide 144 text

αʔόʔϓογϡͷ࣮૷ elsif ($header_map->{':path'} eq '/style.css') { aio_load './style.css', sub { my ($data) = @_; $server->response( ':status' => 200, stream_id => $stream_id, headers => [ 'server' => 'perl-Protocol-HTTP2/1.08', 'content-length' => length($data), 'content-type' => 'text/css', ], data => $data, ); }; } …

Slide 145

Slide 145 text

Time͕1msʹͳ͍ͬͯΔʂʂ ※ࠓճ͸cacheपΓͷϔομʔΛೖΕ͍ͯͳ͍ͷͰcss͕ڧ͘ Ωϟογϡ͞Εͯ͠·͏ͨΊγʔΫϨοτϞʔυਪ঑

Slide 146

Slide 146 text

ଓ͍ͯΫϥΠΞϯτଆΛ࣮૷ ͠·͢

Slide 147

Slide 147 text

αʔόʔϓογϡͷड৴ • Protocol::HTTP2::ClientͷΠϯελϯε࡞੒࣌ ʹ on_push() Λࢦఆ͢Δ͜ͱͰ PUSH_PROMISEΛड͚औΔ͜ͱ͕Ͱ͖Δ • ίʔϧόοΫΛฦ͢͜ͱͰσʔλΛड৴Ͱ͖Δ • undef Λฦͨ͠ΒΩϟϯηϧѻ͍

Slide 148

Slide 148 text

αʔόʔϓογϡͷड৴ my $client = Protocol::HTTP2::Client->new( on_push => sub { my ($push_headers) = @_; print "Server want to push some resource to us\n”; return sub { my ($headers, $data) = @_; print "Received promised resource\n"; }; }, on_change_state => sub { }, on_error => sub { }, );

Slide 149

Slide 149 text

ͨͬͨ͜Ε͚ͩʂ

Slide 150

Slide 150 text

࣮ࡍʹࢼͯ͠ΈΔ $ perl tls_client_server_push.pl Stream 1 changed state from IDLE to HALF_CLOSED Stream 2 changed state from IDLE to RESERVED Server want to push some resource to us Stream 1 changed state from HALF_CLOSED to CLOSED [ [ தུ ], "\n \n HTTP/2 Server Push Test\n \n \n \n

Server Push Test

\n \n" ] Stream 2 changed state from RESERVED to HALF_CLOSED Stream 2 changed state from HALF_CLOSED to CLOSED Received promised resource $VAR1 = [ [ ':status', '200', 'server', 'perl-Protocol-HTTP2/1.08', 'content-length', '26', 'content-type', 'text/css' ], '.push { color: red; } ' ];

Slide 151

Slide 151 text

ͪΌΜͱड৴Ͱ͖ͯ·͢Ͷʂʂ

Slide 152

Slide 152 text

͸͍

Slide 153

Slide 153 text

࠷ޙʹPSGIͰHTTP/2ʹରԠ ͢Δํ๏Λ঺հ͠·͢

Slide 154

Slide 154 text

ͱ͍ͬͯ΋ͱͬͯ΋؆୯

Slide 155

Slide 155 text

Protocol::HTTP2ͱಉ͡࡞ऀ ͕࡞͍ͬͯΔ”Shuvgey”Λ࢖ ͏͚ͩͰ͢

Slide 156

Slide 156 text

Shuvgeyͷ࢖͍ํ $ shuvgey --listen :8000 --tls_key=cert.key --tls_crt=cert.crt app.psgi

Slide 157

Slide 157 text

ͨͬͨ͜Ε͚ͩͰPSGIରԠͷ HTTP2αʔόʔ্ཱ͕͕ͪΔ ͧʂʂʂ

Slide 158

Slide 158 text

ϦΫΤετͯ͠ΈΔ ʢࠓճ͸ —no_tls Ͱʣ $ shuvgey —listen 8080 —no_tls app.psgi $ perl no_tls_client.pl Stream 1 changed state from IDLE to HALF_CLOSED Stream 1 changed state from HALF_CLOSED to CLOSED [ [ ":status", "200", "content-type", "text/plain", "content-lenth", "13", "server", "Shuvgey/0.09" ], "hello, world!" ]

Slide 159

Slide 159 text

؆୯Ͱ͢Ͷʂʂ

Slide 160

Slide 160 text

APIαʔόʔͱ͔ͩͬͨΒ͜ ΕΛ࢖͏ͱָͪΜͰ͢Ͷ

Slide 161

Slide 161 text

͜͜·Ͱͷ·ͱΊ • Protocol::HTTP2Λ࢖͑͹PerlͰ΋όϦόϦ HTTP/2Λ஻Δ͜ͱ͕Ͱ͖Δ • ͱ͸͍͑AnyEventͳͲΛར༻ͨ͠Πϕϯτۦ ಈͳϓϩάϥϛϯάεΩϧ͕ඞਢ • ShuvgeyΛ࢖͑͹؆୯ʹPSGI͕஻ΕΔ

Slide 162

Slide 162 text

͸͍

Slide 163

Slide 163 text

͓·͚: gRPCͱPerl

Slide 164

Slide 164 text

݁࿦

Slide 165

Slide 165 text

ݱঢ়·ͱ΋ʹಈ࣮͘૷͸ͳ͍ ͱ͓΋ΘΕΔ

Slide 166

Slide 166 text

No content

Slide 167

Slide 167 text

࣮૷ࣗମ͸͋Δ • Grpc::XS • gRPCͷC++ͷόΠϯσΟϯά • Google::Protocol::Buffer::Dynamic • ϓϩτίϧόοϑΝʔͷC++ͷόΠϯσΟϯά • protoxs-perl • protocͰperlΛग़ྗͰ͖ΔΑ͏ʹ͢Δ΋ͷ

Slide 168

Slide 168 text

͔͠͠

Slide 169

Slide 169 text

࣮૷ࣗମ͸͋Δ • Grpc::XS • ࠷৽ͷϓϩτίϧόοϑΝʔͰϏϧυͰ͖ͳ͍ • ϏϧυͰ͖Δ؀ڥͱόʔδϣϯ͕ෆ໌ • Google::Protocol::Buffer::Dynamic • ࠷৽ͷϓϩτίϧόοϑΝʔͰϏϧυͰ͖ͳ͍ • ϏϧυͰ͖Δ؀ڥͱόʔδϣϯ͕ෆ໌ • protoxs-perl • ߋ৽͕10೥લ͔Β͋Δྺ࢙͋ΔϞδϡʔϧ • proto2·Ͱ͔͠ରԠ͍ͯ͠ͳ͍

Slide 170

Slide 170 text

ͱ͍͏Θ͚Ͱ

Slide 171

Slide 171 text

༗ࣝऀͷํɺ࢖͍ํڭ͑ͯ͘ ͍ͩ͞ʂʂ

Slide 172

Slide 172 text

ͨͩɺ࢓ࣄͰPerlͰgRPC࢖͏ ؾ͕͠ͳ͍

Slide 173

Slide 173 text

No content

Slide 174

Slide 174 text

·ͱΊ

Slide 175

Slide 175 text

·ͱΊ • HTTP/2͸HTTP/1.1ͷϓϩτίϧ্ͷϘτϧωοΫΛղ ফ͍͍ͯͬͯ͠Δ • ·ͩ·ͩ࠷దԽͷٞ࿦͸ଓ͍͍ͯΔ • PerlͰ΋HTTP/2͸όϦόϦ࢖͑Δ • ͨͩ͠ɺ͢΂ͯΠϕϯτۦಈͩ • gRPCϥΠϒϥϦʔɺGoogle͞Μग़͍ͯͩ͘͠͞

Slide 176

Slide 176 text

͝ਗ਼ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂʂ