Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Goroutine Pool in 17LIVE

Viney
April 27, 2021

Goroutine Pool in 17LIVE

Golang Taipei Gathering #56 x 旋轉拍賣
https://www.meetup.com/golang-taipei-meetup/events/277374228/

# 講者
Viney Shih @ 17Live

# 題目
那些年我們追的 Goroutine Pool

# 議程摘要
Go 語言的開發者一定對 goroutine 不陌生,它非常的簡單容易操作,也能快速達到高併發的效果,另一方面它的 stack 很小,相較於傳統的 thread,context switch 速度更快。然而沒有限制的使用它也會造成系統負擔。

本次主題會分享 17LIVE 在 2018 年曾經面對的開播通知問題,進而發展自己的 goroutine pool 的心路歷程。

Viney

April 27, 2021
Tweet

More Decks by Viney

Other Decks in Technology

Transcript

  1. Agenda • System issues in 2018 • Analysis and requirement

    • Goroutine Pool (Goroutines) in 17LIVE • Conclusion • Q&A
  2. System issues in 2018 (cont.) • Complex process during sending

    PN - Personal preferences - Streamer’s blacklist - System rules - Millions of fans
  3. Analysis • Memory limitation - The default starting size for

    a goroutine's stack in 1.4 is 2048 bytes - On 4GB memory, this limits the max number of goroutines to less than 2 million
  4. Analysis (cont.) • System performance - Allocate the stacks and

    destroy them high frequently - Adjust the stack size dynamically by factor 2 (this is how go runtime works), and copy the previous in the new one
  5. Requirements • Limit the maximum number of goroutines • Recycle

    and reuse goroutines • Need a queue to be the buffer of goroutines
  6. Conclusion • Goroutines in 17LIVE save the PN issue significantly

    - No PN lost for hot streamers - Views receive PN within two minutes • We also do other optimization with goroutines - One time batch jobs: Batch