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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
“全部コピーしない”ファイルデータの活用 : — FSx for ONTAP × S3 Tables × Icebergで作るメタデータカタログ
yoshiki0705
0
450
GuardrailからGovernanceへ~AIエージェント運用の次の課題~
sbspsy
1
160
AWS Summit Japan 2026の振り返りと2027へ向けて / AWS Summit Japan 2026 Recap and Prospects for 2027
kaminashi
1
200
最近評価が難しくなった
maroon8021
0
230
Baseline対応のDOMの型定義を作った
uhyo
3
690
Hatena Engineer Seminar 37 jj1uzh
jj1uzh
0
430
どうして今サーバーサイドKotlinを選択したのか
nealle
0
200
CVE-2026-20833_脆弱性対応とAES 化について
jukishiya
0
360
デジタル・デザイン構想 by Sayaka Ishizuka
y150saya
0
190
証券システムを10年Scalaで作り続けるということ - 関数型まつり2026
krrrr38
2
460
次世代ランサムウェア対策の考察 / 20260704 Mitsutoshi Matsuo
shift_evolve
PRO
5
1.7k
CSに"SLO"は要らない、経営層に"99.9%"は伝わらない - SREを全社に"翻訳"する3原則
cscengineer
PRO
0
1.7k
Featured
See All Featured
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.4k
Ruling the World: When Life Gets Gamed
codingconduct
0
270
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
220
Discover your Explorer Soul
emna__ayadi
2
1.2k
Mobile First: as difficult as doing things right
swwweet
225
10k
4 Signs Your Business is Dying
shpigford
187
22k
The Spectacular Lies of Maps
axbom
PRO
1
850
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
WCS-LA-2024
lcolladotor
0
670
Speed Design
sergeychernyshev
33
1.9k
Six Lessons from altMBA
skipperchong
29
4.3k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
220
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