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
Gohperに逆らうとどうなるのか
Search
Seiji Takahashi
April 23, 2016
Technology
3
4.2k
Gohperに逆らうとどうなるのか
Go Conference Spring 2016
Seiji Takahashi
April 23, 2016
Tweet
Share
More Decks by Seiji Takahashi
See All by Seiji Takahashi
Go Backends for frontends with GraphQL and gRPC
timakin
6
3.7k
Design Pattern for Image and Text Composition in Go
timakin
5
6.5k
Golang API Testing the HARD way
timakin
13
6.4k
Head First Golang Image Package
timakin
2
9.9k
React Native Beyond Prototype
timakin
2
1.6k
Performance Optimization on Google AppEngine
timakin
5
6.1k
testcache.pdf
timakin
1
120
How Go cache
timakin
1
63
How Go cache tests
timakin
1
2.9k
Other Decks in Technology
See All in Technology
アプリエンジニアのためのGraphQL入門.pdf
spycwolf
0
120
OCI 運用監視サービス 概要
oracle4engineer
PRO
0
4.8k
あなたの知らない Function.prototype.toString() の世界
mizdra
PRO
3
760
rootlessコンテナのすゝめ - 研究室サーバーでもできる安全なコンテナ管理
kitsuya0828
3
390
【LT】ソフトウェア産業は進化しているのか? #Agilejapan
takabow
0
110
RubyのWebアプリケーションを50倍速くする方法 / How to Make a Ruby Web Application 50 Times Faster
hogelog
3
950
CDCL による厳密解法を採用した MILP ソルバー
imai448
3
220
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
310
【Pycon mini 東海 2024】Google Colaboratoryで試すVLM
kazuhitotakahashi
2
580
オープンソースAIとは何か? --「オープンソースAIの定義 v1.0」詳細解説
shujisado
10
1.5k
The Rise of LLMOps
asei
9
1.9k
20241120_JAWS_東京_ランチタイムLT#17_AWS認定全冠の先へ
tsumita
2
320
Featured
See All Featured
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
140
A better future with KSS
kneath
238
17k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Building Applications with DynamoDB
mza
90
6.1k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Optimizing for Happiness
mojombo
376
70k
Transcript
Gopherʹ ٯΒ͏ͱ Ͳ͏ͳΔͷ͔ timakin / @__timakin__ Go Conference 2016 Spring
ࣗݾհ • ߴڮೋ / ͪ·͖Μ • Github: timakin • Twitter:
@__timakin__ • Gmail:
[email protected]
• hatena: timakin.log • ϓϥΠϕʔτͰGoͰ࡞ͬͨCLIπʔϧ • timakin/ts - teckstack (ςοΫܥͷใऩूCLI) • timakin/octop - octopatrol (github tracking CLI)
ΞδΣϯμ • ʮgo-lxcΛ௨࣮ͯ͠ײͨ͠Golangͷྑ͞ʯ͕ ਖ਼ࣜͰ͢ɻ • LXCपΓͷ͠·͢ɻ • CLIπʔϧΛGoͰॻ͖ͨ͠ΒߴԽͨ͠ ͠Α͏ͱࢥ͚ͬͨͲ࣌ؒͳ͛͞ͳͷͰࠓ…
Կ͕ىͬͨ͜ͷ͔ • DockerΫϩʔϯΛ࡞ͬͯͨ • YAPC::Asia Tokyo 2015ͰʮGitͷ࡞Γํʯͱ͍͏ LTʹײԽ͞Εͯɺ”࣮͕ͦ͠͏ͩ” ͱࢥ͏ͷΛϓν࣮ͯ͠ΈΑ͏ͱߟ͑ͨɻ •
खݩͰͪΌΜͱதΘ͔ͬͯͦ͏Ͱ Θ͔ͬͯͳ͍πʔϧ… • DockerͩͶʂ
Կ͕ىͬͨ͜ͷ͔ • p8952/bockerͱ͍͏shell100ߦͷ࣮͕͋Δ • ͜ΕΛRubyͰͬͨΒՄಡੑ͕͍͋ͬͯ ͍ͷͰɻʢԿΑ͘ͳ͔ͬͨʣ • Dockerͱ͍͏͔LXCΛϥοϓͨ͠timakin/ Oceanusͱ͍͏ͷΛॻ͖·ͨ͠ɻ
LXC(Linux Containers)ͷ֓ཁ • ίϯςφԾԽʹඞཁͳchrootcgroupɺnamespaceͷׂΛ ѻ͏APIΛఏڙ͢Δٕज़Ͱ͢ɻ • ԾϚγϯΛ࡞ΔͷͰͳ͘ɺϗετOSͷϦιʔεΛׂɺཧ ͢Δ͜ͱͰִۭؒΛ࡞Γग़͠·͢ɻϋʔυΣΞͷγϛϡϨʔγϣ ϯ͕ඞཁͳ͍ͨΊɺԾԽʹΑΔΦʔόʔϔου͕গͳ͍Ͱ͢ɻ •
v0.8ҎલͷDockerLXCܦ༝ͰҰ෦ϦιʔεཧΛ͍ͯ͠·ͨ͠ɻ • DockerϦιʔεׂͦ͏Ͱ͕͢ɺΞϓϦέʔγϣϯͷσϓϩ ΠڥΠϝʔδͷόʔδϣχϯάʹओ؟Λஔ͍͍ͯΔͰɺࠩҟ ͕͋Δͷͩͱ͍͏ҹͰ͢ɻ
go-lxcͷ֓ཁ • Go Bindings for LXC (Linux Containers) • LXD
(REST APIΛఏڙ͢ΔσʔϞϯΛඋ͓͑ͯ ΓɺωοτϫʔΫܦ༝Ͱͷૢ࡞͕Մೳͳίϯ ςφٕज़ɻLXCͷਐԽ൛తͳͷ)ʹಋೖ͞ Ε͍ͯ·͢ɻ • ଞʹruby-lxcpython2-lxc͋Γ·͕͢ɺ ։ൃࢭ·ͬͯ·͢…
go-lxcͷAPIͷྫ • ίϯςφͷجຊૢ࡞ • ৽ن࡞ɿfunc NewContainer • ίϯςφىಈɿfunc (*Container) Start
• ίϯςφͰͷίϚϯυ࣮ߦɿfunc (*Container) Execute • ίϯςφഁغɿfunc (*Container) Destroy • ίϯςφఀࢭɿfunc (*Container) Shutdown • ίϯςφҰཡɿfunc Containers
go-lxcͷAPIͷྫ • ίϯςφ͝ͱͷಠࣗઃఆɺsnapshotɺϓϩη εͷσʔϞϯԽ • func (*Container) SetMemorySwapLimit • func
(*Container) CreateSnapshot • func (*Container) Daemonize
go-lxcͷίʔυϦʔσΟϯά // go-lxc/container.go func (c *Container) Start() error { if
err := c.makeSure(isNotRunning); err != nil { return err } c.mu.Lock() defer c.mu.Unlock() if !bool(C.go_lxc_start(c.container, 0, nil)) { return ErrStartFailed } return nil }
go-lxcͷίʔυϦʔσΟϯά // go-lxc/lxc-binding.c bool go_lxc_start(struct lxc_container *c, int useinit, char
* const argv[]) { return c->start(c, useinit, argv); }
go-lxcͷίʔυϦʔσΟϯά // lxc/src/lxc/lxccontainer.c struct lxc_container *lxc_container_new(const char *name, const char
*configpath) { struct lxc_container *c; ... c->start = lxcapi_start; ... } static bool lxcapi_start(struct lxc_container *c, int useinit, char * const argv[]) { bool ret; current_config = c ? c->lxc_conf : NULL; ret = do_lxcapi_start(c, useinit, argv); current_config = NULL; return ret; }
Dockerϓν࣮աఔɿֶश • cgroup, chroot, snapshot࡞पΓͷษڧɻ • Ծڥͱ͍͏ΑΓִۭؒΛ࡞ΔΠϝʔδΛ࣋ͭɻ • ॳظͷDockerLXCͬͯͨΑ͏ͳͷͰɺLXCͷษڧ …
• Docker HubͷAPIͷ༷ಡΉ… • ͪΖΜdockerͦͷͷͷ࣮ͱlxcͷίʔυಡ Ήɻ
Dockerϓν࣮աఔɿ࣮ • e.g. pull -> run, execͷྲྀΕ • Docker HubͷAPIΛୟ͖ɺimages
endpointΛୟ͍ͯɺඞཁͳsession tokenΛऔಘ͢Δ • session token͖ͰRegistry APIΛୟ͍ͯɺ֘λάͷimage_idΛऔಘ͢ Δ • Imageͷancestry(diffཤྺ)Λऔಘ͢Δ • layer(ImageͷόΠφϦσʔλ)Λऔಘ͠ɺಛఆσΟϨΫτϦԼʹల։͢Δ • ετϨʔδͷঢ়ଶͷࠩ(ancestry)ΛϨΠϠͱͯ͠ॏͶ߹ΘͤΔ͜ͱͰɺΠ ϝʔδΛܗ͢ΔɻʢϢχΦϯϑΝΠϧγεςϜʣ • snapshotΛҙͷσΟϨΫτϦʹอଘͭͭ͠ɺͦͷΠϝʔδΛݩʹLXCΛ ىಈɺίϚϯυ࣮ߦ
Dockerϓν࣮աఔɿ࣮ • e.g. pull -> run, execͷྲྀΕ • Docker HubͷAPIΛୟ͖ɺimages
endpointΛୟ͍ͯɺඞཁͳsession tokenΛऔಘ͢Δ • session token͖ͰRegistry APIΛୟ͍ͯɺ֘λάͷimage_idΛऔಘ͢ Δ • Imageͷancestry(diffཤྺ)Λऔಘ͢Δ • layer(ImageͷόΠφϦσʔλ)Λऔಘ͠ɺಛఆσΟϨΫτϦԼʹల։͢Δ • ετϨʔδͷঢ়ଶͷࠩ(ancestry)ΛϨΠϠͱͯ͠ॏͶ߹ΘͤΔ͜ͱͰɺΠ ϝʔδΛܗ͢ΔɻʢϢχΦϯϑΝΠϧγεςϜʣ • snapshotΛҙͷσΟϨΫτϦʹอଘͭͭ͠ɺͦͷΠϝʔδΛݩʹLXCΛ ىಈɺίϚϯυ࣮ߦʢ͕͜͜LXCΛ͏ॴʣ
Dockerϓν࣮աఔɿ࣮ • imageͷϩʔυͰ֎෦APIΛୟ͖ʹߦ͘ͷ ͷɺجຊతʹLXCͷػೳͰ݁͢Δɻ • bockerbtrfsʹΑΔsnapshot࡞ɺcgroupʹ ΑΔϦιʔεཧɺωοτϫʔΫઃఆɺ chrootͰϧʔτมߋΛϕλͰ࣮ɻ
݁ՌɺGolang͡Όͳ͔͔ͬͨΒ… • ·ͣɺવGoDocͳΜͯͳͷͳ͍ • ͨΓલͷ͜ͱͰ͕͢ɺ͜Ε͕ݪҼͰAPIͷ ༷ΛѲ͢ΔͨΊʹίʔυΛಡΉ͜ͱ ʹͳΓ·͢ɻ • ͦͷίʔυ͕LXCΛΧϓηϧԽͨ͠ɺ͔Γ ͍͢ίʔυͳΒ·ͩ͠ɺC֦ுͷίʔυ
ͳͷͰࢮɻ
ͨͱ͑container_start static VALUE container_start(int argc, VALUE *argv, VALUE self) {
int ret; VALUE rb_use_init, rb_daemonize, rb_close_fds, rb_args, rb_opts; struct start_without_gvl_args args; args.use_init = 0; args.daemonize = 1; args.close_fds = 0; args.args = NULL; rb_args = Qnil; rb_scan_args(argc, argv, "01", &rb_opts); if (!NIL_P(rb_opts)) { Check_Type(rb_opts, T_HASH); rb_use_init = rb_hash_aref(rb_opts, SYMBOL("use_init")); if (!NIL_P(rb_use_init)) ͓͏ɺͦ͏ͩͳɻ
݁ՌɺGolang͡Όͳ͔͔ͬͨΒ… • rubyͷ߹ɺGolangͷΑ͏ʹૉఢʹAPI͕ੜ ͍͑ͯΔΘ͚Ͱͳͯ͘ɺ͜͏ɻ • GoҎ֎ͷLXC࣮lxcΛݺͼग़͚ͩ͢Ͱɺ APIͱͯ͠ϦʔμϒϧͩͬͨΓɺརศੑΛߟྀ ͨ͠୯Ґʹϝιουׂ͕͞Εͯͳ͔ͬͨΓ ͠·͢ɻ require
'lxc/lxc'
݁ՌɺGolang͡Όͳ͔͔ͬͨΒ… • GolangͳΒ func (*Container) IPAddress func (*Container) CPUStatsͳͲɺ ίϯςφΛཧ͢Δʹͨͬͯݟ͍ͨใ͕
ࣗ༝ʹݟΕ·͢ɻ • Ұํlxc/lxc-ruby… ϝϞϦωοτϫʔΫཧconfigͷΈ… ͏ͪΐͬͱ࿑ಇͯ͠ʂ
͓લͳΜͰ RubyͰ ࣮͠Α͏ ͱࢥͬͨΜͩʁ
·ͱΊ • GoͷLXCपΓͷ࣮ॆ࣮ͯ͠·͢ɻ • APIͷ༷͕ࡉԽ͞ΕͯͯɺυΩϡϝϯτ ੜ͞ΕͯΔͷͰɺαοͱίϯςφԾԽͷ ίʔυΛಡΉ͜ͱ͕Ͱ͖·͢ɻͥͻɻ • GoͰ͔ͬ͠Γͨ͠API͕Ͱ͖͕͋ͬͯΔͱɺ ͦΕҎ֎ͷݴޠͰͷ࣮͕Γͳ͘ײ͡·͢ɻ
ٯΒ͏ͷΊ·͠ΐ͏ɻ
Thank you!