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
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
130
catchup.pdf
taxio
0
99
Layered Architecture
taxio
0
170
SummerReport
taxio
0
120
ReactTutorial
taxio
0
110
ボスキタスイッチ.pdf
taxio
0
440
Other Decks in Technology
See All in Technology
AAIFに入ってみた ~内から見えるコミュニティ動向~
sato4
0
140
On-behalf-of Token exchange with AgentCore Identity
hironobuiga
2
140
生成 AI × MCP で切り拓く次世代 SRE!自律型運用への挑戦と開発者体験の進化
_awache
0
190
なぜ Platform Engineering の土台に Kubernetes を選ぶのか
r4ynode
1
570
Oracle AI Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
6
1.9k
Agent Skills設計で柔軟性と硬さのバランスが難しい話
nassy20
0
120
AWSシリコン最前線 〜AI時代のチップ選択を読み解く〜
htokoyo
2
420
Oracle AI Database@AWS:サービス概要のご紹介
oracle4engineer
PRO
4
2.9k
非エンジニアがClaudeと挑んだ「1ヶ月間プロダクト30本ノック」
askokc
0
280
【Cyber-sec+】経営層を"動かす"ための考え方
hssh2_bin
0
120
"何を作るか"を任される エンジニアは、どう育つのか
yutaokafuji
1
590
攻撃者視点で考えるDetection Engineering
cryptopeg
1
980
Featured
See All Featured
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
sira's awesome portfolio website redesign presentation
elsirapls
0
280
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
280
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
210
Evolving SEO for Evolving Search Engines
ryanjones
0
210
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
140
We Are The Robots
honzajavorek
0
240
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
130
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.3k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3.4k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
The Invisible Side of Design
smashingmag
302
52k
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