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
Internal of cpm
Search
Shoichi Kaji
July 05, 2018
0
570
Internal of cpm
shibuya.pm #18 2018/07/05
Shoichi Kaji
July 05, 2018
Tweet
Share
More Decks by Shoichi Kaji
See All by Shoichi Kaji
宿泊予約サイトにおける検索と料金計算の両立
skaji
2
1.6k
昔のGo, 今のGo ~比較, ソート編~
skaji
0
150
Perl Quiz
skaji
0
130
cpm at PerlCon 2019
skaji
0
110
Perl5 Package Manager
skaji
0
650
How to execute external programs in Perl
skaji
3
560
Writing Perl with w0rp/ale
skaji
0
2.2k
nginx unit
skaji
0
44
Perl6 ecosystem
skaji
1
1.4k
Featured
See All Featured
Fontdeck: Realign not Redesign
paulrobertlloyd
81
5.2k
Art, The Web, and Tiny UX
lynnandtonic
296
20k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
A Philosophy of Restraint
colly
203
16k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
How GitHub (no longer) Works
holman
311
140k
Happy Clients
brianwarren
97
6.7k
Unsuck your backbone
ammeep
668
57k
Building Better People: How to give real-time feedback that sticks.
wjessup
363
19k
What's new in Ruby 2.0
geeforr
342
31k
Automating Front-end Workflow
addyosmani
1365
200k
GraphQLとの向き合い方2022年版
quramy
43
13k
Transcript
cpmͷ࣮ͷཪଆ Shoichi Kaji
Me • Shoichi Kaji • CPAN, github: skaji • co-maintainer
of Minilla, Perl-Build, Text- Xslate, Mouse, Test-PAUSE- Permissions
ࠓͷత • cpmͷ࣮ͷࢼߦࡨޡΛ͠ɺ ͍Ζ͍ΖͳΓ͔͕ͨ͋Δͱ͍͑ͨɻ ໘ന͍ͱࢥͬͯΒ͑ͨΒɺ͞Βʹ͏Ε͍͠ɻ • Ͳ͏͍͏͕͔͋ͬͨɺͲΜͳղܾҊ͕͋ͬͨ ͷ͔ɺͳͥͦͷղܾҊΛ࠾༻ͨ͠ͷ͔ • େɺͳͥͦͷҊΛબΜ͔ͩͱݴΘΕͯɺ"ͳΜ
ͱͳ͘"ͱ͍͏͜ͱ͕ଟ͍͚ΕͲ:)
࣍ • cpmͱʁ • CPAN client ߴԽͷϙΠϯτ(A), (B) • Ͳ͏ͬͯ"ͲΜͲΜ"jobΛফԽ͢Δ͔
• jobͷத • ϓϩάϥϜύϥμΠϜ • IPC • select • ࣮ࡍͷcpmͷίʔυ • ࠷ޙʹ
cpmͱ?
cpm is a fast CPAN client
https://github.com/skaji/cpm
CPAN clientΛߴԽ͢Δʹ େ͖͘2ͭͷϙΠϯτ͕͋Δ
CPAN clientߴԽͷϙΠϯτ(A) • Ͳ͏ͬͯɺಈతʹܾ·ΔΔ͖͜ͱ(= job)Λ ཧ͢Δ͔ • ͡ΊʹΘ͔͍ͬͯΔͷʮModuleAͷΠϯετʔ ϧʯͱ͍͏ΰʔϧͷΈ •
ModuleXͷґଘModuleXͷMakefile.PLΛ࣮ߦ͠ ͯ͡Ίͯ֬ఆ͢Δ • Ͳͷjobʹґଘؔʹ͋ΓɺͲͷjobಠཱ͔
CPAN clientߴԽͷϙΠϯτ(B) • Ͳ͏ͬͯ"ͲΜͲΜ"jobΛফԽ͢Δ͔ • ࠓͪ͜ΒΛѻ͍͍ͨ
job job job job job job job job job Ͳ͏ͬͯjobΛ
"ͲΜͲΜ"ফԽ͢Δ͔
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
ϓϩάϥϜύϥμΠϜ • ͲͷϓϩάϥϜύϥμΠϜΛ࠾༻͢Ε"ͲΜͲΜ"jobΛফԽͰ͖Δ͔ • Ҋ1: ϚϧνεϨου • ೦ͳ͕ΒPerlͰεϨουϓϩάϥϛϯάݫ͍͠ • Ҋ2:
Event Driven • jobͷ࣮ࡍͷத֎෦ϓϩάϥϜ࣮ߦɺHTTP௨৴ͩͬͨɻΑͬͯEvent DrivenʹͽͬͨΓɻ͕ɺطଘͷCPAN clientͷίʔυΛ͑ͳ͍ • Ҋ3: Ϛϧνϓϩηε • ·ͣ͜ΕͰ
Ϛϧνϓϩηε • ϚϧνϓϩηεΛ࠾༻ʂ • 1: master͔Βworkerjob ͷૹ৴ɺworker͔Βmaster ݁Ռͷૹ৴Λ͍ͨ͠ɻͲ͏ ͬͨΒͰ͖ΔͩΖ͏ʁ •
2 masterworkerͷ "finished"Λ͍ͪૣ͘ݕ ͠ɺ࣍ͷjobΛৼΓ͍ͨɻͲ͏ ͬͨΒͰ͖ΔͩΖ͏ʁ worker worker worker master process
IPC • Ͳ͏ͬͯmasterͱworker௨৴͢Δͷ͕͍͍ͷ͔ • Ҋ1: File • master͕workerͷ"finished"Λૉૣ͘ݕͰ͖ͳ͍ɻinotifyͱ͔݁ߏ ͍ɻ •
Ҋ2: TCP/IP • େ͔͛͞ͳʁ • Ҋ3: pipe • ͦΕͧΕͷworkerʹૹ৴ɺड৴༻2ຊͷpipeΛܨ͙ͱΑͦ͞͏
select • Ͳ͏ͬͨΒɺmasterworkerͷ"finished"Λ ͍ͪૣ͘ݕͰ͖Δ͔ • workerpipeʹ݁ՌΛॻ͖ࠐΈɺmasterʹ "finished"Λ͑ΔͭΓ • Αͬͯ select(2)Ͱworkerͨͪʹܨ͕ΔpipeΛ
ࢹ͢Εɺ͍ͪૣ͘"finished"ΛݕͰ͖Δ
·ͱΊΔͱ • ϚϧνϓϩηεΛ࠾༻ • masterͱworkerΛ2ຊͷpipe Ͱͭͳ͙ • masterworker͔Βͷड৴ ༻pipeΛselect͢Δ͜ͱͰɺ workerͷ"finished"Λ͍ͪૣ
͘ݕͰ͖Δ worker worker worker master process pipe pipe pipe select
࣮ࡍͷcpmͷίʔυ master͕jobΛܭࢉ ready (= "finished")ͳworkerΛऔಘ (෦ͰpipeͨͪͷselectΛ͍ͯ͠Δ!) pipeΛ௨ͯ͠ͷworkerͱͷ௨৴෦Λ Parallel::PipesϞδϡʔϧͱͯ͠நԽ readyͳworkerʹjobΛૹ৴ ͜ͷίʔυʹCPAN
clientߴԽͷ΄ͱΜͲ͕٧·ͬͯΔ
࠷ޙʹ • cpmͷ࣮ʹ͍ͭͯͨ͠ • cpmૣ͍ͨ͘͠ͱͷࢥ͍Ͱ͍ͭͬͯͨ͘Βɺ "ͨ·ͨ·"͍·ͷ࣮ʹͳͬͨ • "Γ͔ͨͻͱͭ͡Όͳ͍" • Γ͍ͨ͜ͱɺࢼͯ͠Έ͍ͨ͜ͱ͕ͨ͘͞Μ͋Δ
• event driven CPAN clientॻ͖͍ͨʂ