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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
760
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
メルカリのグローバルアプリで挑んだ AlloyDB 運用と課題解決の実践記
hatappi
0
110
AIエージェントの知識表現と推論に なぜグラフが使われるのか - 記号的AIの復権とニューラルAIとの統合
yohei1126
1
270
システム監視を 「システムを監視するだけ」で 終わらせないために
seiud
0
170
SmartHR Engineering Team Deck
smarthr
0
160
AI エージェント時代のデジタルアイデンティティ
fujie
3
1.4k
A Bag-of-Documents Model for Query Specificity
dtunkelang
0
210
DevOps Agentで運用判断をチーム資産にする~Agent InstructionsとAgent Skillを継続的に育てる~
fujioka6789
0
200
20260801_スクフェス大阪
kgnkhkr
1
1k
実践が先生だった— 新卒サーバーエンジニア1年目のリアル
mixi_engineers
PRO
0
240
ガバメントクラウドでのランサムウェア対策
techniczna
1
650
Claude Code並行開発環境の ムダ‧ムラ‧ムリを見直した話
muranakaaa
2
420
13年運用タイトルのサーバーサイドが辿り着いた現在地 ― モンスターストライクにおける技術・組織・AI活用から得た知見
mixi_engineers
PRO
1
430
Featured
See All Featured
Producing Creativity
orderedlist
PRO
348
40k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Code Reviewing Like a Champion
maltzj
528
40k
Amusing Abliteration
ianozsvald
1
240
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Docker and Python
trallard
47
4k
How to build a perfect <img>
jonoalderson
1
5.8k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
430
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
400
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
450
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