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
580
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
3.6k
昔のGo, 今のGo ~比較, ソート編~
skaji
0
180
Perl Quiz
skaji
0
130
cpm at PerlCon 2019
skaji
0
110
Perl5 Package Manager
skaji
0
660
How to execute external programs in Perl
skaji
3
580
Writing Perl with w0rp/ale
skaji
0
2.2k
nginx unit
skaji
0
44
Perl6 ecosystem
skaji
1
1.4k
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Statistics for Hackers
jakevdp
796
220k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
The Invisible Side of Design
smashingmag
298
50k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Typedesign – Prime Four
hannesfritz
40
2.4k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
Into the Great Unknown - MozCon
thekraken
33
1.5k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
For a Future-Friendly Web
brad_frost
175
9.4k
Raft: Consensus for Rubyists
vanstee
137
6.7k
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ॻ͖͍ͨʂ