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

Go Scheduler

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

Go Scheduler

GoWayFest 2017

Avatar for Cyril Lashkevich

Cyril Lashkevich

July 21, 2017
Tweet

More Decks by Cyril Lashkevich

Other Decks in Technology

Transcript

  1. func main() { var x int threads := runtime.GOMAXPROCS(0) for

    i := 0; i < threads; i++ { go func() { for { x++ } }() } time.Sleep(time.Second) fmt.Println("x =", x) }
  2. func test() { a := 100 for i := 1;

    i < 1000; i++ { a = i*100/i + a } } func main() { runtime.GOMAXPROCS(1) go func() { for { test() } }() time.Sleep(100 * time.Millisecond) fmt.Println("hello world") }
  3. Goroutines VS threads Свойство Goroutines Threads Время создания Быстро Медленно

    Время удаления Быстро Медленно Переключение контекста Быстро Медленно Потребление памяти под стек 2kB 512kB-1MB Допустимое количество 10^4 10^6
  4. Планировщики — Work Sharing при появлении новой задачи попытаться мигрировать

    ее на свободный процессор — Work Stealing когда процессор освобождается, он пытается найти себе задачу
  5. G M P — G - Goroutine — M -

    OS thread — P - "Processor"
  6. Spining threads — M с P ищет G — M

    без P ищет P — Есть готовая к исполнению G, свободная P, но нет M