Internal of cpm

E4967f90a08dadff9cc185b863cd99a7?s=47 Shoichi Kaji
July 05, 2018
240

Internal of cpm

shibuya.pm #18 2018/07/05

E4967f90a08dadff9cc185b863cd99a7?s=128

Shoichi Kaji

July 05, 2018
Tweet

Transcript

  1. cpmͷ࣮૷ͷཪଆ Shoichi Kaji

  2. Me • Shoichi Kaji • CPAN, github: skaji • co-maintainer

    of
 Minilla, Perl-Build, Text- Xslate, Mouse, Test-PAUSE- Permissions
  3. ࠓ೔ͷ໨త • cpmͷ࣮૷ͷࢼߦࡨޡΛ࿩͠ɺ
 ͍Ζ͍Ζͳ΍Γ͔͕ͨ͋Δͱ఻͍͑ͨɻ
 ໘ന͍ͱࢥͬͯ΋Β͑ͨΒɺ͞Βʹ͏Ε͍͠ɻ • Ͳ͏͍͏໰୊͕͔͋ͬͨɺͲΜͳղܾҊ͕͋ͬͨ ͷ͔ɺͳͥͦͷղܾҊΛ࠾༻ͨ͠ͷ͔ • େ఍ɺͳͥͦͷҊΛબΜ͔ͩͱݴΘΕͯ΋ɺ"ͳΜ

    ͱͳ͘"ͱ͍͏͜ͱ͕ଟ͍͚ΕͲ:)
  4. ໨࣍ • cpmͱ͸ʁ • CPAN client ߴ଎ԽͷϙΠϯτ(A), (B) • Ͳ͏΍ͬͯ"ͲΜͲΜ"jobΛফԽ͢Δ͔

    • jobͷத਎ • ϓϩάϥϜύϥμΠϜ • IPC • select • ࣮ࡍͷcpmͷίʔυ • ࠷ޙʹ
  5. cpmͱ͸?

  6. cpm is
 a fast CPAN client

  7. https://github.com/skaji/cpm

  8. CPAN clientΛߴ଎Խ͢Δʹ͸ େ͖͘2ͭͷϙΠϯτ͕͋Δ

  9. CPAN clientߴ଎ԽͷϙΠϯτ(A) • Ͳ͏΍ͬͯɺಈతʹܾ·Δ΍Δ΂͖͜ͱ(= job)Λ
 ؅ཧ͢Δ͔ • ͸͡ΊʹΘ͔͍ͬͯΔͷ͸ʮModuleAͷΠϯετʔ ϧʯͱ͍͏ΰʔϧͷΈ •

    ModuleXͷґଘ͸ModuleXͷMakefile.PLΛ࣮ߦ͠ ͯ͸͡Ίͯ֬ఆ͢Δ • Ͳͷjobʹ͸ґଘؔ܎ʹ͋ΓɺͲͷjob͸ಠཱ͔
  10. CPAN clientߴ଎ԽͷϙΠϯτ(B) • Ͳ͏΍ͬͯ"ͲΜͲΜ"jobΛফԽ͢Δ͔ • ࠓ೔͸ͪ͜ΒΛѻ͍͍ͨ

  11. job job job job job job job job job Ͳ͏΍ͬͯjobΛ


    "ͲΜͲΜ"ফԽ͢Δ͔
  12. jobͷத਎ • ֎෦ίϚϯυ࣮ߦ • perl Makefile.PL • tar xzf Module-0.1.tar.gz

    • HTTP௨৴ • API͔ΒdisturlΛऔಘ • CPAN͔ΒtarballΛऔಘ job job job job job job job job job
  13. ϓϩάϥϜύϥμΠϜ • ͲͷϓϩάϥϜύϥμΠϜΛ࠾༻͢Ε͹"ͲΜͲΜ"jobΛফԽͰ͖Δ͔ • Ҋ1: ϚϧνεϨου • ࢒೦ͳ͕ΒPerlͰεϨουϓϩάϥϛϯά͸ݫ͍͠ • Ҋ2:

    Event Driven • jobͷ࣮ࡍͷத਎͸֎෦ϓϩάϥϜ࣮ߦɺHTTP௨৴ͩͬͨɻΑͬͯEvent DrivenʹͽͬͨΓɻ͕ɺطଘͷCPAN clientͷίʔυΛ࢖͑ͳ͍ • Ҋ3: Ϛϧνϓϩηε • ·ͣ͸͜ΕͰ
  14. Ϛϧνϓϩηε • ϚϧνϓϩηεΛ࠾༻ʂ • ໰1: master͔Βworker΁job ͷૹ৴ɺworker͔Βmaster ΁݁Ռͷૹ৴Λ͍ͨ͠ɻͲ͏ ΍ͬͨΒͰ͖ΔͩΖ͏ʁ •

    ໰2 master͸workerͷ "finished"Λ͍ͪૣ͘ݕ஌ ͠ɺ࣍ͷjobΛৼΓ͍ͨɻͲ͏ ΍ͬͨΒͰ͖ΔͩΖ͏ʁ worker worker worker master process
  15. IPC • Ͳ͏΍ͬͯmasterͱworker͸௨৴͢Δͷ͕͍͍ͷ͔ • Ҋ1: File • master͕workerͷ"finished"Λૉૣ͘ݕ஌Ͱ͖ͳ͍ɻinotifyͱ͔݁ߏ஗ ͍ɻ •

    Ҋ2: TCP/IP • େ͔͛͞ͳʁ • Ҋ3: pipe • ͦΕͧΕͷworkerʹૹ৴ɺड৴༻2ຊͷpipeΛܨ͙ͱΑͦ͞͏
  16. select • Ͳ͏΍ͬͨΒɺmaster͸workerͷ"finished"Λ ͍ͪૣ͘ݕ஌Ͱ͖Δ͔ • worker͸pipeʹ݁ՌΛॻ͖ࠐΈɺmasterʹ "finished"Λ఻͑Δͭ΋Γ • Αͬͯ select(2)Ͱworkerͨͪʹܨ͕ΔpipeΛ؂

    ࢹ͢Ε͹ɺ͍ͪૣ͘"finished"Λݕ஌Ͱ͖Δ
  17. ·ͱΊΔͱ • ϚϧνϓϩηεΛ࠾༻ • masterͱworkerΛ2ຊͷpipe Ͱͭͳ͙ • master͸worker͔Βͷड৴ ༻pipeΛselect͢Δ͜ͱͰɺ workerͷ"finished"Λ͍ͪૣ

    ͘ݕ஌Ͱ͖Δ worker worker worker master process pipe pipe pipe select
  18. ࣮ࡍͷcpmͷίʔυ master͕jobΛܭࢉ ready (= "finished")ͳworkerΛऔಘ (಺෦ͰpipeͨͪͷselectΛ͍ͯ͠Δ!) pipeΛ௨ͯ͠ͷworkerͱͷ௨৴෦෼Λ Parallel::PipesϞδϡʔϧͱͯ͠ந৅Խ readyͳworkerʹjobΛૹ৴ ͜ͷίʔυʹCPAN

    clientߴ଎Խͷ΄ͱΜͲ͕٧·ͬͯΔ
  19. ࠷ޙʹ • cpmͷ࣮૷ʹ͍ͭͯ࿩ͨ͠ • cpm͸ૣ͍ͨ͘͠ͱͷࢥ͍Ͱ͍ͭͬͯͨ͘Βɺ
 "ͨ·ͨ·"͍·ͷ࣮૷ʹͳͬͨ • "΍Γ͔ͨ͸ͻͱͭ͡Όͳ͍" • ΍Γ͍ͨ͜ͱɺࢼͯ͠Έ͍ͨ͜ͱ͕ͨ͘͞Μ͋Δ

    • event driven CPAN clientॻ͖͍ͨʂ