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
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
Software Supply Chain Attackからクラウド環境を守るためにできること
lhazy
2
290
Flutter × BLE Centralを自前Pluginで実装する設計パターン - MethodChannel / EventChannelで作る双方向ブリッジの実践 / Building Custom Flutter BLE Central Plugins: Bidirectional Bridging with Method & Event Channels
bitkey
PRO
0
190
自宅NWにISR4331を導入してみた話
okaits
0
120
AIコーディングの次。コードレビューと理解負荷を解消して組織の開発生産性を高める
moongift
PRO
2
2.7k
関東Kaggler会発表資料
takoi
1
270
NANDでも描画したい!
nichica906
0
230
tamachi.go 誕生の裏側
rymiyamoto
1
190
作って理解するCoding Agent 〜フレームワークに頼らないピュア Python での実装〜
takapy
2
140
国家プロジェクトを支える「さくらONE」 大規模LLM開発におけるGPU障害を乗り越えるクラスター運用戦略
gpuunite_official
0
170
Digitization部 紹介資料
sansan33
PRO
2
7.7k
Sets in Go
ramalho
1
1.1k
AIのためのEthernet技術動向 (SerDes)
markunet
1
250
Featured
See All Featured
Writing Fast Ruby
sferik
630
63k
From π to Pie charts
rasagy
0
310
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
390
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.5k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
370
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
620
Optimising Largest Contentful Paint
csswizardry
37
3.9k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3k
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