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
2.5k
昔のGo, 今のGo ~比較, ソート編~
skaji
0
170
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
570
Writing Perl with w0rp/ale
skaji
0
2.2k
nginx unit
skaji
0
44
Perl6 ecosystem
skaji
1
1.4k
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
Embracing the Ebb and Flow
colly
84
4.5k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Building Adaptive Systems
keathley
38
2.3k
Faster Mobile Websites
deanohume
305
30k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Gamification - CAS2011
davidbonilla
80
5k
10 Git Anti Patterns You Should be Aware of
lemiorhan
655
59k
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ॻ͖͍ͨʂ