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
Shutdown workers
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
taxio
April 20, 2019
Technology
310
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Shutdown workers
taxio
April 20, 2019
More Decks by taxio
See All by taxio
go gc algorithm 101
taxio
12
9.8k
go-gc-1
taxio
1
420
Go CLI Hands-on
taxio
0
750
ISUCON出ようぜ!
taxio
0
140
catchup.pdf
taxio
0
99
Layered Architecture
taxio
0
170
SummerReport
taxio
0
130
ReactTutorial
taxio
0
120
ボスキタスイッチ.pdf
taxio
0
440
Other Decks in Technology
See All in Technology
SRE依存からの脱却 運用を開 発チームへ移す、 フルサイ クル開 発体制の実践
joooee0000
0
2.5k
「最後に責任を取るのはチーム」— 人間のPRレビューを最小化してアップデートしたメンタルモデル
jnishime_dresscode
0
130
生成AI活用によるODC欠陥分析の分類高速化の実践と導入効果 / 20260703 Suguru Ishii
shift_evolve
PRO
2
120
AWS Summit の片隅で、体育座りしながらコミュニティがにぎわう理由を考えた
k_adachi_01
2
370
貴方はどのエンジニアリングを磨くのか
hatyibei
0
110
最近評価が難しくなった
maroon8021
0
280
証券システムを10年Scalaで作り続けるということ - 関数型まつり2026
krrrr38
3
830
ADDF - ループエンジニアリングするフレームワークを作ったら/I Didn't Set Out to Build Loop Engineering, But ADDF Did
fruitriin
0
110
AI Driven AI Governance
pict3
0
320
はじめてのWDM
miyukichi_ospf
1
140
Claude Codeとハーネスについて考えてみる
oikon48
18
9.1k
しぶいSRE: サーバから見えない障害にどう向き合うか。ラストワンマイルのデバッグ実践 / Shibui SRE
kanny
13
5.8k
Featured
See All Featured
Designing Powerful Visuals for Engaging Learning
tmiket
1
440
Docker and Python
trallard
47
3.9k
Writing Fast Ruby
sferik
630
63k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
Into the Great Unknown - MozCon
thekraken
41
2.6k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.5k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
330
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
230
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
320
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
340
sira's awesome portfolio website redesign presentation
elsirapls
0
300
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Transcript
ґଘํͷ͋Δ 8PSLFSΛཧ͢Δ 6NFEBHP4QSJOH
ґଘํͷ͋Δ 8PSLFSΛཧ͢Δ ࢭΊΔ 6NFEBHP4QSJOH
8JLJΈ͍ͨͳαʔϏεͰΑ͋͘Δͭ w ࣗͷهࣄͷ༰Λશͯμϯϩʔυ͍ͨ͠ Ὂ %VNQϦΫΤετΛૹΔ Ὂ ཪଆͰॲཧΛΒͤΔ Ὂ Ϣʔβʔʹରͯ͠μϯϩʔυՄೳͷ௨ΛૹΔ !3
"1*4FSWFS %VNQ8PSLFS /PUJpDBUJPO 8PSLFS 3FRVFTU ϝʔϧͱ͔
"1*4FSWFS %VNQ8PSLFS /PUJpDBUJPO 8PSLFS 3FRVFTU ϝʔϧͱ͔ DIBOOFM DIBOOFM HSPVUJOF HSPVUJOF
HSPVUJOF
Ͳ͏ͬͯࢭΊΔʁ w 04ͷγάφϧΛݟͯॱ൪ʹࢭΊ͍͖͍ͯͨ w طʹड͚͚ͨ%VNQॲཧऴΘΒ͔ͤͯΒࢭΊ͍ͨ Ὂ ͘͠దʹୀආͤ͞Δ w DPOUFYUΛ͑Ͱ͖ͦ͏ !6
"1*4FSWFS %VNQ8PSLFS /PUJpDBUJPO 8PSLFS 4JHOBM 8BUDIFS TZTDBMM4*(*/5 TZTDBMM4*(5&3. DBODFM DMPTF
DI DBODFM DMPTF DI DBODFM DMPTF DI PT&YJU
4JHOBM8BUDIFS w 4*(*/5ͱ4*(5&3.Λࢹ Ὂ ड৴ͨ͠Β"1*4FSWFSʹͨ͠DPOUFYU ͷcancel()Λ࣮ߦ w sigStopCh Ὂ શମͷॲཧ͕ऴ͔ྃͨ͠Ͳ͏͔ΛݟΔ
▷ ࿈ଓͰγάφϧ͕དྷͯେৎ • golang.org/x/sync/errgroup Ὂ HPSPVUJOFͷཧ͕͍͢͠Α͏ʹ !8 eg, ctx := errgroup.WithContext(context.Background()) srvCtx, srvCancel := context.WithCancel(ctx) sigCh := make(chan os.Signal) sigStopCh := make(chan struct{}) signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM) eg.Go(func() error { defer close(sigCh) for { select { case <-sigStopCh: log.Println("finish signal watching") return nil case sig := <-sigCh: log.Printf("received signal %+v\n", sig) srvCancel() } } })
"1*4FSWFS w BQJEVNQ͕ୟ͔ΕΔͱɼ DumpIds DIBOOFM ʹσʔλΛ٧ΊΔ Ὂ CMPDL͕ൃੜ͢ΔͷͰຊྑ͘ͳ͍ w γάφϧʹΑͬͯDUY͕Ωϟϯηϧ͞ΕͨΒɼ
Shutdown()ΛݺͿ Ὂ ͍͍ײ͡ʹ(SBDFGVM4IVUEPXOͯ͘͠ΕΔʁ Ὂ ໌ࣔతʹClose()͠ͳ͍ͱ௨৴தͷॲཧ λΠϜΞτͯ͘͠Εͳ͍ʁ w %VNQͷDUYΛΩϟϯηϧ͠ɼ DIBOOFMΛด͡Δ !9 func (s *APIServer) Run(...) ... { ... go func() { log.Println("start server") err := srv.ListenAndServe() if err != nil { log.Print(err) } }() defer close(s.DumpIds) defer cancelDump() <-ctx.Done() ctxShutdown, _ := context.WithTimeout(...) if err := srv.Shutdown(ctxShutdown); err != nil { log.Print(err) } log.Println("shutdown server!!") ... }
%VNQ8PSLFS w DIBOOFM dumpIds ʹ٧·͍ͬͯΔ σʔλΛҰ୴ୀආ͍ͤͨ͞߹ɼ ctxͷDone()ΛݟͯϋϯυϦϯά͢Δ Ὂ dompIdsDMPTF͞ΕͯΔͷͰɼೖͬͯΔ σʔλΛॲཧ͖͠ΕGPSൈ͚Δ
w ࠷ޙʹ/PUJpDBUJPO8PSLFSͷDUYΛ Ωϟϯηϧ͠ɼDIBOOFMΛด͡Δ !10 eg.Go(func() error { defer close(notificationMsgs) defer notificationCancel() defer log.Println("shutdown dump worker") for d := range dumpIds { select { case <-dumpCtx.Done(): // TODO: save dump ids return nil default: time.Sleep(5 * time.Second) log.Printf("dump: %#v\n", d) notificationMsgs <- dumpData(d) } } return nil })
/PUJpDBUJPO8PSLFS w %VNQ8PSLFSͱಉ͡ !11 eg.Go(func() error { defer log.Println("shutdown notification
worker") defer close(sigStopCh) for msg := range notificationMsgs { select { case <-notificationCtx.Done(): // TODO: save messages return nil default: time.Sleep(4 * time.Second) sendNotification(msg) log.Printf("notification message: %s\n", msg) } } return nil })
ࢀߟ࣮ w HJTUHJUIVCDPNUBYJPCDFBECGBCDFEFGB w HJUIVCDPNXBOUFEMZTVCFF !12