SlideShare uma empresa Scribd logo
1 de 100
Baixar para ler offline
Gett is changing how people move
around and Gett things
timers
I/O callbacks
Idle, prepare
poll
check
close callbacks
libuv
File I/ONetwork I/O
TCP UDP TTY PIPE
Thread Poolepoll kqueue IOCP
var mysql = require('mysql');
var con = mysql.createConnection({
...
});
con.connect(function(err) {
if (err) throw err;
con.query("SELECT * FROM customers", function (err, result, fields) {
if (err) throw err;
console.log(result);
});
});
... //some more code
var mysql = require('mysql');
var con = mysql.createConnection({
...
});
con.connect(function(err) {
if (err) throw err;
con.query("SELECT * FROM customers", function (err, result, fields) {
if (err) throw err;
console.log(result);
});
});
... //some more code
1
2
3
4
5
6
func Add(a, b int) int {
return a + b
}
go build -gcflags '-N -l'
go tool objdump -s stacksize.Add goway
go build -gcflags '-N -l'
go tool objdump -s stacksize.Add goway
go build -gcflags '-N -l'
go tool objdump -s stacksize.Add goway
go build -gcflags '-N -l'
go tool objdump -s stacksize.Add goway
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:20 0x1087050 488b442410 MOVQ 0x10(SP), AX
stack.go:20 0x1087055 488b4c2408 MOVQ 0x8(SP), CX
stack.go:20 0x108705a 4801c8 ADDQ CX, AX
stack.go:20 0x108705d 4889442418 MOVQ AX, 0x18(SP)
stack.go:20 0x1087062 c3 RET
go build -gcflags '-N -l'
go tool objdump -s stacksize.Add goway
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:20 0x1087050 488b442410 MOVQ 0x10(SP), AX
stack.go:20 0x1087055 488b4c2408 MOVQ 0x8(SP), CX
stack.go:20 0x108705a 4801c8 ADDQ CX, AX
stack.go:20 0x108705d 4889442418 MOVQ AX, 0x18(SP)
stack.go:20 0x1087062 c3 RET
func Add(a, b int) int {
return a + b
}
go build -gcflags '-N -l'
go tool objdump -s stacksize.Add goway
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:20 0x1087050 488b442410 MOVQ 0x10(SP), AX
stack.go:20 0x1087055 488b4c2408 MOVQ 0x8(SP), CX
stack.go:20 0x108705a 4801c8 ADDQ CX, AX
stack.go:20 0x108705d 4889442418 MOVQ AX, 0x18(SP)
stack.go:20 0x1087062 c3 RET
func Add(a, b int) int {
return a + b
}
go build -gcflags '-N -l'
go tool objdump -s stacksize.Add goway
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:20 0x1087050 488b442410 MOVQ 0x10(SP), AX
stack.go:20 0x1087055 488b4c2408 MOVQ 0x8(SP), CX
stack.go:20 0x108705a 4801c8 ADDQ CX, AX
stack.go:20 0x108705d 4889442418 MOVQ AX, 0x18(SP)
stack.go:20 0x1087062 c3 RET
func Add(a, b int) int {
return a + b
}
go build -gcflags '-N -l'
go tool objdump -s stacksize.Add goway
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:20 0x1087050 488b442410 MOVQ 0x10(SP), AX
stack.go:20 0x1087055 488b4c2408 MOVQ 0x8(SP), CX
stack.go:20 0x108705a 4801c8 ADDQ CX, AX
stack.go:20 0x108705d 4889442418 MOVQ AX, 0x18(SP)
stack.go:20 0x1087062 c3 RET
func Add(a, b int) int {
return a + b
}
go build -gcflags '-N -l'
go tool objdump -s stacksize.Add goway
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:20 0x1087050 488b442410 MOVQ 0x10(SP), AX
stack.go:20 0x1087055 488b4c2408 MOVQ 0x8(SP), CX
stack.go:20 0x108705a 4801c8 ADDQ CX, AX
stack.go:20 0x108705d 4889442418 MOVQ AX, 0x18(SP)
stack.go:20 0x1087062 c3 RET
func Add(a, b int) int {
return a + b
}
func Add(a, b int) int {
log()
return a + b
}
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:18 0x1087050 65488b0c25a0080000 GS MOVQ GS:0x8a0, CX
stack.go:18 0x1087059 483b6110 CMPQ 0x10(CX), SP
stack.go:18 0x108705d 7635 JBE 0x1087094
stack.go:18 0x108705f 4883ec08 SUBQ $0x8, SP
stack.go:18 0x1087063 48892c24 MOVQ BP, 0(SP)
stack.go:18 0x1087067 488d2c24 LEAQ 0(SP), BP
stack.go:18 0x108706b 48c744242000000000 MOVQ $0x0, 0x20(SP)
stack.go:19 0x1087074 e827000000 CALL goway/stacksize.log(SB)
stack.go:20 0x1087079 488b442410 MOVQ 0x10(SP), AX
stack.go:20 0x108707e 488b4c2418 MOVQ 0x18(SP), CX
stack.go:20 0x1087083 4801c8 ADDQ CX, AX
stack.go:20 0x1087086 4889442420 MOVQ AX, 0x20(SP)
stack.go:20 0x108708b 488b2c24 MOVQ 0(SP), BP
stack.go:20 0x108708f 4883c408 ADDQ $0x8, SP
stack.go:20 0x1087093 c3 RET
stack.go:18 0x1087094 e8872efcff CALL runtime.morestack_noctxt(SB)
stack.go:18 0x1087099 ebb5 JMP goway/stacksize.Add(SB)
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:18 0x1087050 65488b0c25a0080000 GS MOVQ GS:0x8a0, CX
stack.go:18 0x1087059 483b6110 CMPQ 0x10(CX), SP
stack.go:18 0x108705d 7635 JBE 0x1087094
stack.go:18 0x108705f 4883ec08 SUBQ $0x8, SP
stack.go:18 0x1087063 48892c24 MOVQ BP, 0(SP)
stack.go:18 0x1087067 488d2c24 LEAQ 0(SP), BP
stack.go:18 0x108706b 48c744242000000000 MOVQ $0x0, 0x20(SP)
stack.go:19 0x1087074 e827000000 CALL goway/stacksize.log(SB)
stack.go:20 0x1087079 488b442410 MOVQ 0x10(SP), AX
stack.go:20 0x108707e 488b4c2418 MOVQ 0x18(SP), CX
stack.go:20 0x1087083 4801c8 ADDQ CX, AX
stack.go:20 0x1087086 4889442420 MOVQ AX, 0x20(SP)
stack.go:20 0x108708b 488b2c24 MOVQ 0(SP), BP
stack.go:20 0x108708f 4883c408 ADDQ $0x8, SP
stack.go:20 0x1087093 c3 RET
stack.go:18 0x1087094 e8872efcff CALL runtime.morestack_noctxt(SB)
stack.go:18 0x1087099 ebb5 JMP goway/stacksize.Add(SB)
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:18 0x1087050 65488b0c25a0080000 GS MOVQ GS:0x8a0, CX
stack.go:18 0x1087059 483b6110 CMPQ 0x10(CX), SP
stack.go:18 0x108705d 7635 JBE 0x1087094
stack.go:18 0x108705f 4883ec08 SUBQ $0x8, SP
stack.go:18 0x1087063 48892c24 MOVQ BP, 0(SP)
stack.go:18 0x1087067 488d2c24 LEAQ 0(SP), BP
stack.go:18 0x108706b 48c744242000000000 MOVQ $0x0, 0x20(SP)
stack.go:19 0x1087074 e827000000 CALL goway/stacksize.log(SB)
stack.go:20 0x1087079 488b442410 MOVQ 0x10(SP), AX
stack.go:20 0x108707e 488b4c2418 MOVQ 0x18(SP), CX
stack.go:20 0x1087083 4801c8 ADDQ CX, AX
stack.go:20 0x1087086 4889442420 MOVQ AX, 0x20(SP)
stack.go:20 0x108708b 488b2c24 MOVQ 0(SP), BP
stack.go:20 0x108708f 4883c408 ADDQ $0x8, SP
stack.go:20 0x1087093 c3 RET
stack.go:18 0x1087094 e8872efcff CALL runtime.morestack_noctxt(SB)
stack.go:18 0x1087099 ebb5 JMP goway/stacksize.Add(SB)
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:18 0x1087050 65488b0c25a0080000 GS MOVQ GS:0x8a0, CX
stack.go:18 0x1087059 483b6110 CMPQ 0x10(CX), SP
stack.go:18 0x108705d 7635 JBE 0x1087094
stack.go:18 0x108705f 4883ec08 SUBQ $0x8, SP
stack.go:18 0x1087063 48892c24 MOVQ BP, 0(SP)
stack.go:18 0x1087067 488d2c24 LEAQ 0(SP), BP
stack.go:18 0x108706b 48c744242000000000 MOVQ $0x0, 0x20(SP)
stack.go:19 0x1087074 e827000000 CALL goway/stacksize.log(SB)
stack.go:20 0x1087079 488b442410 MOVQ 0x10(SP), AX
stack.go:20 0x108707e 488b4c2418 MOVQ 0x18(SP), CX
stack.go:20 0x1087083 4801c8 ADDQ CX, AX
stack.go:20 0x1087086 4889442420 MOVQ AX, 0x20(SP)
stack.go:20 0x108708b 488b2c24 MOVQ 0(SP), BP
stack.go:20 0x108708f 4883c408 ADDQ $0x8, SP
stack.go:20 0x1087093 c3 RET
stack.go:18 0x1087094 e8872efcff CALL runtime.morestack_noctxt(SB)
stack.go:18 0x1087099 ebb5 JMP goway/stacksize.Add(SB)
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:18 0x1087050 65488b0c25a0080000 GS MOVQ GS:0x8a0, CX
stack.go:18 0x1087059 483b6110 CMPQ 0x10(CX), SP
stack.go:18 0x108705d 7635 JBE 0x1087094
stack.go:18 0x108705f 4883ec08 SUBQ $0x8, SP
stack.go:18 0x1087063 48892c24 MOVQ BP, 0(SP)
stack.go:18 0x1087067 488d2c24 LEAQ 0(SP), BP
stack.go:18 0x108706b 48c744242000000000 MOVQ $0x0, 0x20(SP)
stack.go:19 0x1087074 e827000000 CALL goway/stacksize.log(SB)
stack.go:20 0x1087079 488b442410 MOVQ 0x10(SP), AX
stack.go:20 0x108707e 488b4c2418 MOVQ 0x18(SP), CX
stack.go:20 0x1087083 4801c8 ADDQ CX, AX
stack.go:20 0x1087086 4889442420 MOVQ AX, 0x20(SP)
stack.go:20 0x108708b 488b2c24 MOVQ 0(SP), BP
stack.go:20 0x108708f 4883c408 ADDQ $0x8, SP
stack.go:20 0x1087093 c3 RET
stack.go:18 0x1087094 e8872efcff CALL runtime.morestack_noctxt(SB)
stack.go:18 0x1087099 ebb5 JMP goway/stacksize.Add(SB)
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:18 0x1087050 65488b0c25a0080000 GS MOVQ GS:0x8a0, CX
stack.go:18 0x1087059 483b6110 CMPQ 0x10(CX), SP
stack.go:18 0x108705d 7635 JBE 0x1087094
stack.go:18 0x108705f 4883ec08 SUBQ $0x8, SP
stack.go:18 0x1087063 48892c24 MOVQ BP, 0(SP)
stack.go:18 0x1087067 488d2c24 LEAQ 0(SP), BP
stack.go:18 0x108706b 48c744242000000000 MOVQ $0x0, 0x20(SP)
stack.go:19 0x1087074 e827000000 CALL goway/stacksize.log(SB)
stack.go:20 0x1087079 488b442410 MOVQ 0x10(SP), AX
stack.go:20 0x108707e 488b4c2418 MOVQ 0x18(SP), CX
stack.go:20 0x1087083 4801c8 ADDQ CX, AX
stack.go:20 0x1087086 4889442420 MOVQ AX, 0x20(SP)
stack.go:20 0x108708b 488b2c24 MOVQ 0(SP), BP
stack.go:20 0x108708f 4883c408 ADDQ $0x8, SP
stack.go:20 0x1087093 c3 RET
stack.go:18 0x1087094 e8872efcff CALL runtime.morestack_noctxt(SB)
stack.go:18 0x1087099 ebb5 JMP goway/stacksize.Add(SB)
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:18 0x1087050 65488b0c25a0080000 GS MOVQ GS:0x8a0, CX
stack.go:18 0x1087059 483b6110 CMPQ 0x10(CX), SP
stack.go:18 0x108705d 7635 JBE 0x1087094
stack.go:18 0x108705f 4883ec08 SUBQ $0x8, SP
stack.go:18 0x1087063 48892c24 MOVQ BP, 0(SP)
stack.go:18 0x1087067 488d2c24 LEAQ 0(SP), BP
stack.go:18 0x108706b 48c744242000000000 MOVQ $0x0, 0x20(SP)
stack.go:19 0x1087074 e827000000 CALL goway/stacksize.log(SB)
stack.go:20 0x1087079 488b442410 MOVQ 0x10(SP), AX
stack.go:20 0x108707e 488b4c2418 MOVQ 0x18(SP), CX
stack.go:20 0x1087083 4801c8 ADDQ CX, AX
stack.go:20 0x1087086 4889442420 MOVQ AX, 0x20(SP)
stack.go:20 0x108708b 488b2c24 MOVQ 0(SP), BP
stack.go:20 0x108708f 4883c408 ADDQ $0x8, SP
stack.go:20 0x1087093 c3 RET
stack.go:18 0x1087094 e8872efcff CALL runtime.morestack_noctxt(SB)
stack.go:18 0x1087099 ebb5 JMP goway/stacksize.Add(SB)
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:18 0x1087050 65488b0c25a0080000 GS MOVQ GS:0x8a0, CX
stack.go:18 0x1087059 483b6110 CMPQ 0x10(CX), SP
stack.go:18 0x108705d 7635 JBE 0x1087094
stack.go:18 0x108705f 4883ec08 SUBQ $0x8, SP
stack.go:18 0x1087063 48892c24 MOVQ BP, 0(SP)
stack.go:18 0x1087067 488d2c24 LEAQ 0(SP), BP
stack.go:18 0x108706b 48c744242000000000 MOVQ $0x0, 0x20(SP)
stack.go:19 0x1087074 e827000000 CALL goway/stacksize.log(SB)
stack.go:20 0x1087079 488b442410 MOVQ 0x10(SP), AX
stack.go:20 0x108707e 488b4c2418 MOVQ 0x18(SP), CX
stack.go:20 0x1087083 4801c8 ADDQ CX, AX
stack.go:20 0x1087086 4889442420 MOVQ AX, 0x20(SP)
stack.go:20 0x108708b 488b2c24 MOVQ 0(SP), BP
stack.go:20 0x108708f 4883c408 ADDQ $0x8, SP
stack.go:20 0x1087093 c3 RET
stack.go:18 0x1087094 e8872efcff CALL runtime.morestack_noctxt(SB)
stack.go:18 0x1087099 ebb5 JMP goway/stacksize.Add(SB)
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:18 0x1087050 65488b0c25a0080000 GS MOVQ GS:0x8a0, CX
stack.go:18 0x1087059 483b6110 CMPQ 0x10(CX), SP
stack.go:18 0x108705d 7635 JBE 0x1087094
stack.go:18 0x108705f 4883ec08 SUBQ $0x8, SP
stack.go:18 0x1087063 48892c24 MOVQ BP, 0(SP)
stack.go:18 0x1087067 488d2c24 LEAQ 0(SP), BP
stack.go:18 0x108706b 48c744242000000000 MOVQ $0x0, 0x20(SP)
stack.go:19 0x1087074 e827000000 CALL goway/stacksize.log(SB)
stack.go:20 0x1087079 488b442410 MOVQ 0x10(SP), AX
stack.go:20 0x108707e 488b4c2418 MOVQ 0x18(SP), CX
stack.go:20 0x1087083 4801c8 ADDQ CX, AX
stack.go:20 0x1087086 4889442420 MOVQ AX, 0x20(SP)
stack.go:20 0x108708b 488b2c24 MOVQ 0(SP), BP
stack.go:20 0x108708f 4883c408 ADDQ $0x8, SP
stack.go:20 0x1087093 c3 RET
stack.go:18 0x1087094 e8872efcff CALL runtime.morestack_noctxt(SB)
stack.go:18 0x1087099 ebb5 JMP goway/stacksize.Add(SB)
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:18 0x1087050 65488b0c25a0080000 GS MOVQ GS:0x8a0, CX
stack.go:18 0x1087059 483b6110 CMPQ 0x10(CX), SP
stack.go:18 0x108705d 7635 JBE 0x1087094
stack.go:18 0x108705f 4883ec08 SUBQ $0x8, SP
stack.go:18 0x1087063 48892c24 MOVQ BP, 0(SP)
stack.go:18 0x1087067 488d2c24 LEAQ 0(SP), BP
stack.go:18 0x108706b 48c744242000000000 MOVQ $0x0, 0x20(SP)
stack.go:19 0x1087074 e827000000 CALL goway/stacksize.log(SB)
stack.go:20 0x1087079 488b442410 MOVQ 0x10(SP), AX
stack.go:20 0x108707e 488b4c2418 MOVQ 0x18(SP), CX
stack.go:20 0x1087083 4801c8 ADDQ CX, AX
stack.go:20 0x1087086 4889442420 MOVQ AX, 0x20(SP)
stack.go:20 0x108708b 488b2c24 MOVQ 0(SP), BP
stack.go:20 0x108708f 4883c408 ADDQ $0x8, SP
stack.go:20 0x1087093 c3 RET
stack.go:18 0x1087094 e8872efcff CALL runtime.morestack_noctxt(SB)
stack.go:18 0x1087099 ebb5 JMP goway/stacksize.Add(SB)
func Add(a, b int) int {
log()
return a + b
}
func Add(a, b int) int {
var bytes [100]byte
return a + b + int(bytes[0])
}
func Add(a, b int) int {
var bytes [105]byte
return a + b + int(bytes[0])
}
func TestScheduler() {
numOfGoRoutines := 1
progress := make([]int, numOfGoRoutines)
done := int64(0)
goRoutineStarted := sync.WaitGroup{}
goRoutineStarted.Add(numOfGoRoutines)
goRoutineFinished := sync.WaitGroup{}
goRoutineFinished.Add(numOfGoRoutines)
for i := 0; i < numOfGoRoutines; i++ {
go func(id int) {
fmt.Println("Go routine started:", id)
goRoutineStarted.Done()
for atomic.LoadInt64(&done) == 0 {
progress[id]++
}
goRoutineFinished.Done()
}(i)
}
goRoutineStarted.Wait()
atomic.StoreInt64(&done, 1)
goRoutineFinished.Wait()
fmt.Println("All done. Progress: ", progress)
}
Main
goroutine
func TestScheduler() {
numOfGoRoutines := 2
progress := make([]int, numOfGoRoutines)
done := int64(0)
goRoutineStarted := sync.WaitGroup{}
goRoutineStarted.Add(numOfGoRoutines)
goRoutineFinished := sync.WaitGroup{}
goRoutineFinished.Add(numOfGoRoutines)
for i := 0; i < numOfGoRoutines; i++ {
go func(id int) {
fmt.Println("Go routine started:", id)
goRoutineStarted.Done()
for atomic.LoadInt64(&done) == 0 {
progress[id]++
}
goRoutineFinished.Done()
}(i)
}
goRoutineStarted.Wait()
atomic.StoreInt64(&done, 1)
goRoutineFinished.Wait()
fmt.Println("All done. Progress: ", progress)
}
Main
goroutine
Create several goroutinesgoroutine
func TestScheduler() {
numOfGoRoutines := 1
progress := make([]int, numOfGoRoutines)
done := int64(0)
goRoutineStarted := sync.WaitGroup{}
goRoutineStarted.Add(numOfGoRoutines)
goRoutineFinished := sync.WaitGroup{}
goRoutineFinished.Add(numOfGoRoutines)
for i := 0; i < numOfGoRoutines; i++ {
go func(id int) {
fmt.Println("Go routine started:", id)
goRoutineStarted.Done()
for atomic.LoadInt64(&done) == 0 {
progress[id]++
}
goRoutineFinished.Done()
}(i)
}
goRoutineStarted.Wait()
atomic.StoreInt64(&done, 1)
goRoutineFinished.Wait()
fmt.Println("All done. Progress: ", progress)
}
Main
goroutine
goroutine
Main signals goroutines to stop
func TestScheduler() {
numOfGoRoutines := 1
progress := make([]int, numOfGoRoutines)
done := int64(0)
goRoutineStarted := sync.WaitGroup{}
goRoutineStarted.Add(numOfGoRoutines)
goRoutineFinished := sync.WaitGroup{}
goRoutineFinished.Add(numOfGoRoutines)
for i := 0; i < numOfGoRoutines; i++ {
go func(id int) {
fmt.Println("Go routine started:", id)
goRoutineStarted.Done()
for !done {
progress[id]++
}
goRoutineFinished.Done()
}(i)
}
goRoutineStarted.Wait()
done = true
goRoutineFinished.Wait()
fmt.Println("All done. Progress: ", progress)
}
Main
goroutine
goroutine
While not done: progress++
func TestScheduler() {
numOfGoRoutines := 1
progress := make([]int, numOfGoRoutines)
done := int64(0)
goRoutineStarted := sync.WaitGroup{}
goRoutineStarted.Add(numOfGoRoutines)
goRoutineFinished := sync.WaitGroup{}
goRoutineFinished.Add(numOfGoRoutines)
for i := 0; i < numOfGoRoutines; i++ {
go func(id int) {
fmt.Println("Go routine started:", id)
goRoutineStarted.Done()
for atomic.LoadInt64(&done) == 0 {
progress[id]++
}
goRoutineFinished.Done()
}(i)
}
goRoutineStarted.Wait()
atomic.StoreInt64(&done, 1)
goRoutineFinished.Wait()
fmt.Println("All done. Progress: ", progress)
}
Main
goroutine
goroutine
How much progress will each
goroutine make before it stopped?
func TestScheduler() {
numOfGoRoutines := 1
progress := make([]int, numOfGoRoutines)
done := int64(0)
goRoutineStarted := sync.WaitGroup{}
goRoutineStarted.Add(numOfGoRoutines)
goRoutineFinished := sync.WaitGroup{}
goRoutineFinished.Add(numOfGoRoutines)
for i := 0; i < numOfGoRoutines; i++ {
go func(id int) {
fmt.Println("Go routine started:", id)
goRoutineStarted.Done()
for atomic.LoadInt64(&done) == 0 {
progress[id]++
}
goRoutineFinished.Done()
}(i)
}
goRoutineStarted.Wait()
atomic.StoreInt64(&done, 1)
goRoutineFinished.Wait()
fmt.Println("All done. Progress: ", progress)
}
Main
goroutine
goroutine
Are they scheduled equally?
Go routine started: 1
Go routine started: 0
All done. Progress: [576524 578794]
Total Time 4.84726ms
Go routine started: 2
Go routine started: 1
Go routine started: 0
All done. Progress: [1281232 1537252 711224]
Total Time 19.286207ms
?
Go routine started: 0
Go routine started: 1
Go routine started: 3
Go routine started: 2
Go routine started: 0
Go routine started: 1
Go routine started: 3
Go routine started: 2
Go routine started: 0
Go routine started: 1
Go routine started: 3
Go routine started: 2
func TestScheduler() {
numOfGoRoutines := 1
progress := make([]int, numOfGoRoutines)
done := int64(0)
goRoutineStarted := sync.WaitGroup{}
goRoutineStarted.Add(numOfGoRoutines)
goRoutineFinished := sync.WaitGroup{}
goRoutineFinished.Add(numOfGoRoutines)
for i := 0; i < numOfGoRoutines; i++ {
go func(id int) {
fmt.Println("Go routine started:", id)
goRoutineStarted.Done()
for atomic.LoadInt64(&done) == 0 {
progress[id]++
}
goRoutineFinished.Done()
}(i)
}
goRoutineStarted.Wait()
atomic.StoreInt64(&done, 1)
goRoutineFinished.Wait()
fmt.Println("All done. Progress: ", progress)
}
No switching point
func TestScheduler() {
numOfGoRoutines := 1
progress := make([]int, numOfGoRoutines)
done := int64(0)
goRoutineStarted := sync.WaitGroup{}
goRoutineStarted.Add(numOfGoRoutines)
goRoutineFinished := sync.WaitGroup{}
goRoutineFinished.Add(numOfGoRoutines)
for i := 0; i < numOfGoRoutines; i++ {
go func(id int) {
fmt.Println("Go routine started:", id)
goRoutineStarted.Done()
for atomic.LoadInt64(&done) == 0 {
progress[id]++
time.Sleep(0)
}
goRoutineFinished.Done()
}(i)
}
goRoutineStarted.Wait()
atomic.StoreInt64(&done, 1)
goRoutineFinished.Wait()
fmt.Println("All done. Progress: ", progress)
}
Go routine started: 3
Go routine started: 2
Go routine started: 1
Go routine started: 0
All done. Progress: [782164 773498 742771 794478]
Total Time 42.244354ms
func TestScheduler() {
numOfGoRoutines := 1
progress := make([]int, numOfGoRoutines)
done := int64(0)
goRoutineStarted := sync.WaitGroup{}
goRoutineStarted.Add(numOfGoRoutines)
goRoutineFinished := sync.WaitGroup{}
goRoutineFinished.Add(numOfGoRoutines)
for i := 0; i < numOfGoRoutines; i++ {
go func(id int) {
fmt.Println("Go routine started:", id)
goRoutineStarted.Done()
for atomic.LoadInt64(&done) == 0 {
progress[id]++
doSomething()
}
goRoutineFinished.Done()
}(i)
}
goRoutineStarted.Wait()
atomic.StoreInt64(&done, 1)
goRoutineFinished.Wait()
fmt.Println("All done. Progress: ", progress)
}
func doSomething() {
doNothing()
}
func doNothing() {
}
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:18 0x1087050 65488b0c25a0080000 GS MOVQ GS:0x8a0, CX
stack.go:18 0x1087059 483b6110 CMPQ 0x10(CX), SP
stack.go:18 0x108705d 7635 JBE 0x1087094
stack.go:18 0x108705f 4883ec08 SUBQ $0x8, SP
stack.go:18 0x1087063 48892c24 MOVQ BP, 0(SP)
stack.go:18 0x1087067 488d2c24 LEAQ 0(SP), BP
stack.go:18 0x108706b 48c744242000000000 MOVQ $0x0, 0x20(SP)
stack.go:19 0x1087074 e827000000 CALL goway/stacksize.log(SB)
stack.go:20 0x1087079 488b442410 MOVQ 0x10(SP), AX
stack.go:20 0x108707e 488b4c2418 MOVQ 0x18(SP), CX
stack.go:20 0x1087083 4801c8 ADDQ CX, AX
stack.go:20 0x1087086 4889442420 MOVQ AX, 0x20(SP)
stack.go:20 0x108708b 488b2c24 MOVQ 0(SP), BP
stack.go:20 0x108708f 4883c408 ADDQ $0x8, SP
stack.go:20 0x1087093 c3 RET
stack.go:18 0x1087094 e8872efcff CALL runtime.morestack_noctxt(SB)
stack.go:18 0x1087099 ebb5 JMP goway/stacksize.Add(SB)
File I/ONetwork I/O
Thread Poolepoll kqueue IOCP
File I/O
Syscalls
Network I/O
Thread Cache
Netpoller
epoll kqueue IOCP
Node.JS Go
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales

Mais conteúdo relacionado

Mais procurados

Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3
guesta3202
 

Mais procurados (20)

CBSE Computer Project for Class 12 ( C++)
CBSE Computer Project for Class 12 ( C++)CBSE Computer Project for Class 12 ( C++)
CBSE Computer Project for Class 12 ( C++)
 
MySQL 8.0 NF : Common Table Expressions (CTE)
MySQL 8.0 NF : Common Table Expressions (CTE)MySQL 8.0 NF : Common Table Expressions (CTE)
MySQL 8.0 NF : Common Table Expressions (CTE)
 
Going Loopy - Adventures in Iteration with Google Go
Going Loopy - Adventures in Iteration with Google GoGoing Loopy - Adventures in Iteration with Google Go
Going Loopy - Adventures in Iteration with Google Go
 
Hybrid Inheritance in C++
Hybrid Inheritance in C++Hybrid Inheritance in C++
Hybrid Inheritance in C++
 
Development by the numbers
Development by the numbersDevelopment by the numbers
Development by the numbers
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th Study
 
6. binary tree
6. binary tree6. binary tree
6. binary tree
 
Data Structure
Data StructureData Structure
Data Structure
 
Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3
 
System programmin practical file
System programmin practical fileSystem programmin practical file
System programmin practical file
 
Going Loopy: Adventures in Iteration with Go
Going Loopy: Adventures in Iteration with GoGoing Loopy: Adventures in Iteration with Go
Going Loopy: Adventures in Iteration with Go
 
Railway reservation system
Railway reservation systemRailway reservation system
Railway reservation system
 
System programs in C language.
System programs in C language.System programs in C language.
System programs in C language.
 
Hsn code not show
Hsn code not showHsn code not show
Hsn code not show
 
Wildlife conservation project management adri jovin
Wildlife conservation project management  adri jovinWildlife conservation project management  adri jovin
Wildlife conservation project management adri jovin
 
How to extend map? Or why we need collections redesign? - Scalar 2017
How to extend map? Or why we need collections redesign? - Scalar 2017How to extend map? Or why we need collections redesign? - Scalar 2017
How to extend map? Or why we need collections redesign? - Scalar 2017
 
The Ring programming language version 1.4 book - Part 21 of 30
The Ring programming language version 1.4 book - Part 21 of 30The Ring programming language version 1.4 book - Part 21 of 30
The Ring programming language version 1.4 book - Part 21 of 30
 
CPP Quiz
CPP QuizCPP Quiz
CPP Quiz
 
Taking your side effects aside
Taking your side effects asideTaking your side effects aside
Taking your side effects aside
 
Awk hints
Awk hintsAwk hints
Awk hints
 

Semelhante a Why Go Scales

Semelhante a Why Go Scales (20)

Graphical representation of Stack
Graphical representation of StackGraphical representation of Stack
Graphical representation of Stack
 
The forgotten art of assembly
The forgotten art of assemblyThe forgotten art of assembly
The forgotten art of assembly
 
Disassembling Go
Disassembling GoDisassembling Go
Disassembling Go
 
How the stack works(1)
How the stack works(1)How the stack works(1)
How the stack works(1)
 
Examining Malware with Python
Examining Malware with PythonExamining Malware with Python
Examining Malware with Python
 
BlueTeam-RedTeam Exercise - Backdoor containment
BlueTeam-RedTeam Exercise - Backdoor containmentBlueTeam-RedTeam Exercise - Backdoor containment
BlueTeam-RedTeam Exercise - Backdoor containment
 
ARM 64bit has come!
ARM 64bit has come!ARM 64bit has come!
ARM 64bit has come!
 
Chapter6-mikroprocessor
Chapter6-mikroprocessorChapter6-mikroprocessor
Chapter6-mikroprocessor
 
RISC-V Zce Extension
RISC-V Zce ExtensionRISC-V Zce Extension
RISC-V Zce Extension
 
When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)
 
Lecture6
Lecture6Lecture6
Lecture6
 
Аварийный дамп – чёрный ящик упавшей JVM. Андрей Паньгин
Аварийный дамп – чёрный ящик упавшей JVM. Андрей ПаньгинАварийный дамп – чёрный ящик упавшей JVM. Андрей Паньгин
Аварийный дамп – чёрный ящик упавшей JVM. Андрей Паньгин
 
Java bytecode Malware Analysis
Java bytecode Malware AnalysisJava bytecode Malware Analysis
Java bytecode Malware Analysis
 
Let's talks about string operations in C++17
Let's talks about string operations in C++17Let's talks about string operations in C++17
Let's talks about string operations in C++17
 
Exploiting Memory Overflows
Exploiting Memory OverflowsExploiting Memory Overflows
Exploiting Memory Overflows
 
Performance e Produtividade: 2 Habilidades para Transformar seu Relacionament...
Performance e Produtividade: 2 Habilidades para Transformar seu Relacionament...Performance e Produtividade: 2 Habilidades para Transformar seu Relacionament...
Performance e Produtividade: 2 Habilidades para Transformar seu Relacionament...
 
ITGM #9 - Коварный CodeType, или от segfault'а к работающему коду
ITGM #9 - Коварный CodeType, или от segfault'а к работающему кодуITGM #9 - Коварный CodeType, или от segfault'а к работающему коду
ITGM #9 - Коварный CodeType, или от segfault'а к работающему коду
 
Reverse engineering of binary programs for custom virtual machines
Reverse engineering of binary programs for custom virtual machinesReverse engineering of binary programs for custom virtual machines
Reverse engineering of binary programs for custom virtual machines
 
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
 
Коварный code type ITGM #9
Коварный code type ITGM #9Коварный code type ITGM #9
Коварный code type ITGM #9
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Why Go Scales

  • 1.
  • 2.
  • 3. Gett is changing how people move around and Gett things
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 19. libuv File I/ONetwork I/O TCP UDP TTY PIPE Thread Poolepoll kqueue IOCP
  • 20.
  • 21. var mysql = require('mysql'); var con = mysql.createConnection({ ... }); con.connect(function(err) { if (err) throw err; con.query("SELECT * FROM customers", function (err, result, fields) { if (err) throw err; console.log(result); }); }); ... //some more code
  • 22. var mysql = require('mysql'); var con = mysql.createConnection({ ... }); con.connect(function(err) { if (err) throw err; con.query("SELECT * FROM customers", function (err, result, fields) { if (err) throw err; console.log(result); }); }); ... //some more code 1 2 3 4 5 6
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33. func Add(a, b int) int { return a + b }
  • 34. go build -gcflags '-N -l' go tool objdump -s stacksize.Add goway
  • 35. go build -gcflags '-N -l' go tool objdump -s stacksize.Add goway
  • 36. go build -gcflags '-N -l' go tool objdump -s stacksize.Add goway
  • 37. go build -gcflags '-N -l' go tool objdump -s stacksize.Add goway TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go stack.go:20 0x1087050 488b442410 MOVQ 0x10(SP), AX stack.go:20 0x1087055 488b4c2408 MOVQ 0x8(SP), CX stack.go:20 0x108705a 4801c8 ADDQ CX, AX stack.go:20 0x108705d 4889442418 MOVQ AX, 0x18(SP) stack.go:20 0x1087062 c3 RET
  • 38. go build -gcflags '-N -l' go tool objdump -s stacksize.Add goway TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go stack.go:20 0x1087050 488b442410 MOVQ 0x10(SP), AX stack.go:20 0x1087055 488b4c2408 MOVQ 0x8(SP), CX stack.go:20 0x108705a 4801c8 ADDQ CX, AX stack.go:20 0x108705d 4889442418 MOVQ AX, 0x18(SP) stack.go:20 0x1087062 c3 RET func Add(a, b int) int { return a + b }
  • 39. go build -gcflags '-N -l' go tool objdump -s stacksize.Add goway TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go stack.go:20 0x1087050 488b442410 MOVQ 0x10(SP), AX stack.go:20 0x1087055 488b4c2408 MOVQ 0x8(SP), CX stack.go:20 0x108705a 4801c8 ADDQ CX, AX stack.go:20 0x108705d 4889442418 MOVQ AX, 0x18(SP) stack.go:20 0x1087062 c3 RET func Add(a, b int) int { return a + b }
  • 40. go build -gcflags '-N -l' go tool objdump -s stacksize.Add goway TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go stack.go:20 0x1087050 488b442410 MOVQ 0x10(SP), AX stack.go:20 0x1087055 488b4c2408 MOVQ 0x8(SP), CX stack.go:20 0x108705a 4801c8 ADDQ CX, AX stack.go:20 0x108705d 4889442418 MOVQ AX, 0x18(SP) stack.go:20 0x1087062 c3 RET func Add(a, b int) int { return a + b }
  • 41. go build -gcflags '-N -l' go tool objdump -s stacksize.Add goway TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go stack.go:20 0x1087050 488b442410 MOVQ 0x10(SP), AX stack.go:20 0x1087055 488b4c2408 MOVQ 0x8(SP), CX stack.go:20 0x108705a 4801c8 ADDQ CX, AX stack.go:20 0x108705d 4889442418 MOVQ AX, 0x18(SP) stack.go:20 0x1087062 c3 RET func Add(a, b int) int { return a + b }
  • 42. go build -gcflags '-N -l' go tool objdump -s stacksize.Add goway TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go stack.go:20 0x1087050 488b442410 MOVQ 0x10(SP), AX stack.go:20 0x1087055 488b4c2408 MOVQ 0x8(SP), CX stack.go:20 0x108705a 4801c8 ADDQ CX, AX stack.go:20 0x108705d 4889442418 MOVQ AX, 0x18(SP) stack.go:20 0x1087062 c3 RET func Add(a, b int) int { return a + b }
  • 43. func Add(a, b int) int { log() return a + b }
  • 44. TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go stack.go:18 0x1087050 65488b0c25a0080000 GS MOVQ GS:0x8a0, CX stack.go:18 0x1087059 483b6110 CMPQ 0x10(CX), SP stack.go:18 0x108705d 7635 JBE 0x1087094 stack.go:18 0x108705f 4883ec08 SUBQ $0x8, SP stack.go:18 0x1087063 48892c24 MOVQ BP, 0(SP) stack.go:18 0x1087067 488d2c24 LEAQ 0(SP), BP stack.go:18 0x108706b 48c744242000000000 MOVQ $0x0, 0x20(SP) stack.go:19 0x1087074 e827000000 CALL goway/stacksize.log(SB) stack.go:20 0x1087079 488b442410 MOVQ 0x10(SP), AX stack.go:20 0x108707e 488b4c2418 MOVQ 0x18(SP), CX stack.go:20 0x1087083 4801c8 ADDQ CX, AX stack.go:20 0x1087086 4889442420 MOVQ AX, 0x20(SP) stack.go:20 0x108708b 488b2c24 MOVQ 0(SP), BP stack.go:20 0x108708f 4883c408 ADDQ $0x8, SP stack.go:20 0x1087093 c3 RET stack.go:18 0x1087094 e8872efcff CALL runtime.morestack_noctxt(SB) stack.go:18 0x1087099 ebb5 JMP goway/stacksize.Add(SB)
  • 45. TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go stack.go:18 0x1087050 65488b0c25a0080000 GS MOVQ GS:0x8a0, CX stack.go:18 0x1087059 483b6110 CMPQ 0x10(CX), SP stack.go:18 0x108705d 7635 JBE 0x1087094 stack.go:18 0x108705f 4883ec08 SUBQ $0x8, SP stack.go:18 0x1087063 48892c24 MOVQ BP, 0(SP) stack.go:18 0x1087067 488d2c24 LEAQ 0(SP), BP stack.go:18 0x108706b 48c744242000000000 MOVQ $0x0, 0x20(SP) stack.go:19 0x1087074 e827000000 CALL goway/stacksize.log(SB) stack.go:20 0x1087079 488b442410 MOVQ 0x10(SP), AX stack.go:20 0x108707e 488b4c2418 MOVQ 0x18(SP), CX stack.go:20 0x1087083 4801c8 ADDQ CX, AX stack.go:20 0x1087086 4889442420 MOVQ AX, 0x20(SP) stack.go:20 0x108708b 488b2c24 MOVQ 0(SP), BP stack.go:20 0x108708f 4883c408 ADDQ $0x8, SP stack.go:20 0x1087093 c3 RET stack.go:18 0x1087094 e8872efcff CALL runtime.morestack_noctxt(SB) stack.go:18 0x1087099 ebb5 JMP goway/stacksize.Add(SB)
  • 46. TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go stack.go:18 0x1087050 65488b0c25a0080000 GS MOVQ GS:0x8a0, CX stack.go:18 0x1087059 483b6110 CMPQ 0x10(CX), SP stack.go:18 0x108705d 7635 JBE 0x1087094 stack.go:18 0x108705f 4883ec08 SUBQ $0x8, SP stack.go:18 0x1087063 48892c24 MOVQ BP, 0(SP) stack.go:18 0x1087067 488d2c24 LEAQ 0(SP), BP stack.go:18 0x108706b 48c744242000000000 MOVQ $0x0, 0x20(SP) stack.go:19 0x1087074 e827000000 CALL goway/stacksize.log(SB) stack.go:20 0x1087079 488b442410 MOVQ 0x10(SP), AX stack.go:20 0x108707e 488b4c2418 MOVQ 0x18(SP), CX stack.go:20 0x1087083 4801c8 ADDQ CX, AX stack.go:20 0x1087086 4889442420 MOVQ AX, 0x20(SP) stack.go:20 0x108708b 488b2c24 MOVQ 0(SP), BP stack.go:20 0x108708f 4883c408 ADDQ $0x8, SP stack.go:20 0x1087093 c3 RET stack.go:18 0x1087094 e8872efcff CALL runtime.morestack_noctxt(SB) stack.go:18 0x1087099 ebb5 JMP goway/stacksize.Add(SB)
  • 47. TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go stack.go:18 0x1087050 65488b0c25a0080000 GS MOVQ GS:0x8a0, CX stack.go:18 0x1087059 483b6110 CMPQ 0x10(CX), SP stack.go:18 0x108705d 7635 JBE 0x1087094 stack.go:18 0x108705f 4883ec08 SUBQ $0x8, SP stack.go:18 0x1087063 48892c24 MOVQ BP, 0(SP) stack.go:18 0x1087067 488d2c24 LEAQ 0(SP), BP stack.go:18 0x108706b 48c744242000000000 MOVQ $0x0, 0x20(SP) stack.go:19 0x1087074 e827000000 CALL goway/stacksize.log(SB) stack.go:20 0x1087079 488b442410 MOVQ 0x10(SP), AX stack.go:20 0x108707e 488b4c2418 MOVQ 0x18(SP), CX stack.go:20 0x1087083 4801c8 ADDQ CX, AX stack.go:20 0x1087086 4889442420 MOVQ AX, 0x20(SP) stack.go:20 0x108708b 488b2c24 MOVQ 0(SP), BP stack.go:20 0x108708f 4883c408 ADDQ $0x8, SP stack.go:20 0x1087093 c3 RET stack.go:18 0x1087094 e8872efcff CALL runtime.morestack_noctxt(SB) stack.go:18 0x1087099 ebb5 JMP goway/stacksize.Add(SB)
  • 48. TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go stack.go:18 0x1087050 65488b0c25a0080000 GS MOVQ GS:0x8a0, CX stack.go:18 0x1087059 483b6110 CMPQ 0x10(CX), SP stack.go:18 0x108705d 7635 JBE 0x1087094 stack.go:18 0x108705f 4883ec08 SUBQ $0x8, SP stack.go:18 0x1087063 48892c24 MOVQ BP, 0(SP) stack.go:18 0x1087067 488d2c24 LEAQ 0(SP), BP stack.go:18 0x108706b 48c744242000000000 MOVQ $0x0, 0x20(SP) stack.go:19 0x1087074 e827000000 CALL goway/stacksize.log(SB) stack.go:20 0x1087079 488b442410 MOVQ 0x10(SP), AX stack.go:20 0x108707e 488b4c2418 MOVQ 0x18(SP), CX stack.go:20 0x1087083 4801c8 ADDQ CX, AX stack.go:20 0x1087086 4889442420 MOVQ AX, 0x20(SP) stack.go:20 0x108708b 488b2c24 MOVQ 0(SP), BP stack.go:20 0x108708f 4883c408 ADDQ $0x8, SP stack.go:20 0x1087093 c3 RET stack.go:18 0x1087094 e8872efcff CALL runtime.morestack_noctxt(SB) stack.go:18 0x1087099 ebb5 JMP goway/stacksize.Add(SB)
  • 49. TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go stack.go:18 0x1087050 65488b0c25a0080000 GS MOVQ GS:0x8a0, CX stack.go:18 0x1087059 483b6110 CMPQ 0x10(CX), SP stack.go:18 0x108705d 7635 JBE 0x1087094 stack.go:18 0x108705f 4883ec08 SUBQ $0x8, SP stack.go:18 0x1087063 48892c24 MOVQ BP, 0(SP) stack.go:18 0x1087067 488d2c24 LEAQ 0(SP), BP stack.go:18 0x108706b 48c744242000000000 MOVQ $0x0, 0x20(SP) stack.go:19 0x1087074 e827000000 CALL goway/stacksize.log(SB) stack.go:20 0x1087079 488b442410 MOVQ 0x10(SP), AX stack.go:20 0x108707e 488b4c2418 MOVQ 0x18(SP), CX stack.go:20 0x1087083 4801c8 ADDQ CX, AX stack.go:20 0x1087086 4889442420 MOVQ AX, 0x20(SP) stack.go:20 0x108708b 488b2c24 MOVQ 0(SP), BP stack.go:20 0x108708f 4883c408 ADDQ $0x8, SP stack.go:20 0x1087093 c3 RET stack.go:18 0x1087094 e8872efcff CALL runtime.morestack_noctxt(SB) stack.go:18 0x1087099 ebb5 JMP goway/stacksize.Add(SB)
  • 50. TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go stack.go:18 0x1087050 65488b0c25a0080000 GS MOVQ GS:0x8a0, CX stack.go:18 0x1087059 483b6110 CMPQ 0x10(CX), SP stack.go:18 0x108705d 7635 JBE 0x1087094 stack.go:18 0x108705f 4883ec08 SUBQ $0x8, SP stack.go:18 0x1087063 48892c24 MOVQ BP, 0(SP) stack.go:18 0x1087067 488d2c24 LEAQ 0(SP), BP stack.go:18 0x108706b 48c744242000000000 MOVQ $0x0, 0x20(SP) stack.go:19 0x1087074 e827000000 CALL goway/stacksize.log(SB) stack.go:20 0x1087079 488b442410 MOVQ 0x10(SP), AX stack.go:20 0x108707e 488b4c2418 MOVQ 0x18(SP), CX stack.go:20 0x1087083 4801c8 ADDQ CX, AX stack.go:20 0x1087086 4889442420 MOVQ AX, 0x20(SP) stack.go:20 0x108708b 488b2c24 MOVQ 0(SP), BP stack.go:20 0x108708f 4883c408 ADDQ $0x8, SP stack.go:20 0x1087093 c3 RET stack.go:18 0x1087094 e8872efcff CALL runtime.morestack_noctxt(SB) stack.go:18 0x1087099 ebb5 JMP goway/stacksize.Add(SB)
  • 51. TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go stack.go:18 0x1087050 65488b0c25a0080000 GS MOVQ GS:0x8a0, CX stack.go:18 0x1087059 483b6110 CMPQ 0x10(CX), SP stack.go:18 0x108705d 7635 JBE 0x1087094 stack.go:18 0x108705f 4883ec08 SUBQ $0x8, SP stack.go:18 0x1087063 48892c24 MOVQ BP, 0(SP) stack.go:18 0x1087067 488d2c24 LEAQ 0(SP), BP stack.go:18 0x108706b 48c744242000000000 MOVQ $0x0, 0x20(SP) stack.go:19 0x1087074 e827000000 CALL goway/stacksize.log(SB) stack.go:20 0x1087079 488b442410 MOVQ 0x10(SP), AX stack.go:20 0x108707e 488b4c2418 MOVQ 0x18(SP), CX stack.go:20 0x1087083 4801c8 ADDQ CX, AX stack.go:20 0x1087086 4889442420 MOVQ AX, 0x20(SP) stack.go:20 0x108708b 488b2c24 MOVQ 0(SP), BP stack.go:20 0x108708f 4883c408 ADDQ $0x8, SP stack.go:20 0x1087093 c3 RET stack.go:18 0x1087094 e8872efcff CALL runtime.morestack_noctxt(SB) stack.go:18 0x1087099 ebb5 JMP goway/stacksize.Add(SB)
  • 52. TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go stack.go:18 0x1087050 65488b0c25a0080000 GS MOVQ GS:0x8a0, CX stack.go:18 0x1087059 483b6110 CMPQ 0x10(CX), SP stack.go:18 0x108705d 7635 JBE 0x1087094 stack.go:18 0x108705f 4883ec08 SUBQ $0x8, SP stack.go:18 0x1087063 48892c24 MOVQ BP, 0(SP) stack.go:18 0x1087067 488d2c24 LEAQ 0(SP), BP stack.go:18 0x108706b 48c744242000000000 MOVQ $0x0, 0x20(SP) stack.go:19 0x1087074 e827000000 CALL goway/stacksize.log(SB) stack.go:20 0x1087079 488b442410 MOVQ 0x10(SP), AX stack.go:20 0x108707e 488b4c2418 MOVQ 0x18(SP), CX stack.go:20 0x1087083 4801c8 ADDQ CX, AX stack.go:20 0x1087086 4889442420 MOVQ AX, 0x20(SP) stack.go:20 0x108708b 488b2c24 MOVQ 0(SP), BP stack.go:20 0x108708f 4883c408 ADDQ $0x8, SP stack.go:20 0x1087093 c3 RET stack.go:18 0x1087094 e8872efcff CALL runtime.morestack_noctxt(SB) stack.go:18 0x1087099 ebb5 JMP goway/stacksize.Add(SB)
  • 53. TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go stack.go:18 0x1087050 65488b0c25a0080000 GS MOVQ GS:0x8a0, CX stack.go:18 0x1087059 483b6110 CMPQ 0x10(CX), SP stack.go:18 0x108705d 7635 JBE 0x1087094 stack.go:18 0x108705f 4883ec08 SUBQ $0x8, SP stack.go:18 0x1087063 48892c24 MOVQ BP, 0(SP) stack.go:18 0x1087067 488d2c24 LEAQ 0(SP), BP stack.go:18 0x108706b 48c744242000000000 MOVQ $0x0, 0x20(SP) stack.go:19 0x1087074 e827000000 CALL goway/stacksize.log(SB) stack.go:20 0x1087079 488b442410 MOVQ 0x10(SP), AX stack.go:20 0x108707e 488b4c2418 MOVQ 0x18(SP), CX stack.go:20 0x1087083 4801c8 ADDQ CX, AX stack.go:20 0x1087086 4889442420 MOVQ AX, 0x20(SP) stack.go:20 0x108708b 488b2c24 MOVQ 0(SP), BP stack.go:20 0x108708f 4883c408 ADDQ $0x8, SP stack.go:20 0x1087093 c3 RET stack.go:18 0x1087094 e8872efcff CALL runtime.morestack_noctxt(SB) stack.go:18 0x1087099 ebb5 JMP goway/stacksize.Add(SB)
  • 54.
  • 55. func Add(a, b int) int { log() return a + b }
  • 56. func Add(a, b int) int { var bytes [100]byte return a + b + int(bytes[0]) }
  • 57. func Add(a, b int) int { var bytes [105]byte return a + b + int(bytes[0]) }
  • 58.
  • 59.
  • 60.
  • 61. func TestScheduler() { numOfGoRoutines := 1 progress := make([]int, numOfGoRoutines) done := int64(0) goRoutineStarted := sync.WaitGroup{} goRoutineStarted.Add(numOfGoRoutines) goRoutineFinished := sync.WaitGroup{} goRoutineFinished.Add(numOfGoRoutines) for i := 0; i < numOfGoRoutines; i++ { go func(id int) { fmt.Println("Go routine started:", id) goRoutineStarted.Done() for atomic.LoadInt64(&done) == 0 { progress[id]++ } goRoutineFinished.Done() }(i) } goRoutineStarted.Wait() atomic.StoreInt64(&done, 1) goRoutineFinished.Wait() fmt.Println("All done. Progress: ", progress) } Main goroutine
  • 62. func TestScheduler() { numOfGoRoutines := 2 progress := make([]int, numOfGoRoutines) done := int64(0) goRoutineStarted := sync.WaitGroup{} goRoutineStarted.Add(numOfGoRoutines) goRoutineFinished := sync.WaitGroup{} goRoutineFinished.Add(numOfGoRoutines) for i := 0; i < numOfGoRoutines; i++ { go func(id int) { fmt.Println("Go routine started:", id) goRoutineStarted.Done() for atomic.LoadInt64(&done) == 0 { progress[id]++ } goRoutineFinished.Done() }(i) } goRoutineStarted.Wait() atomic.StoreInt64(&done, 1) goRoutineFinished.Wait() fmt.Println("All done. Progress: ", progress) } Main goroutine Create several goroutinesgoroutine
  • 63. func TestScheduler() { numOfGoRoutines := 1 progress := make([]int, numOfGoRoutines) done := int64(0) goRoutineStarted := sync.WaitGroup{} goRoutineStarted.Add(numOfGoRoutines) goRoutineFinished := sync.WaitGroup{} goRoutineFinished.Add(numOfGoRoutines) for i := 0; i < numOfGoRoutines; i++ { go func(id int) { fmt.Println("Go routine started:", id) goRoutineStarted.Done() for atomic.LoadInt64(&done) == 0 { progress[id]++ } goRoutineFinished.Done() }(i) } goRoutineStarted.Wait() atomic.StoreInt64(&done, 1) goRoutineFinished.Wait() fmt.Println("All done. Progress: ", progress) } Main goroutine goroutine Main signals goroutines to stop
  • 64. func TestScheduler() { numOfGoRoutines := 1 progress := make([]int, numOfGoRoutines) done := int64(0) goRoutineStarted := sync.WaitGroup{} goRoutineStarted.Add(numOfGoRoutines) goRoutineFinished := sync.WaitGroup{} goRoutineFinished.Add(numOfGoRoutines) for i := 0; i < numOfGoRoutines; i++ { go func(id int) { fmt.Println("Go routine started:", id) goRoutineStarted.Done() for !done { progress[id]++ } goRoutineFinished.Done() }(i) } goRoutineStarted.Wait() done = true goRoutineFinished.Wait() fmt.Println("All done. Progress: ", progress) } Main goroutine goroutine While not done: progress++
  • 65. func TestScheduler() { numOfGoRoutines := 1 progress := make([]int, numOfGoRoutines) done := int64(0) goRoutineStarted := sync.WaitGroup{} goRoutineStarted.Add(numOfGoRoutines) goRoutineFinished := sync.WaitGroup{} goRoutineFinished.Add(numOfGoRoutines) for i := 0; i < numOfGoRoutines; i++ { go func(id int) { fmt.Println("Go routine started:", id) goRoutineStarted.Done() for atomic.LoadInt64(&done) == 0 { progress[id]++ } goRoutineFinished.Done() }(i) } goRoutineStarted.Wait() atomic.StoreInt64(&done, 1) goRoutineFinished.Wait() fmt.Println("All done. Progress: ", progress) } Main goroutine goroutine How much progress will each goroutine make before it stopped?
  • 66. func TestScheduler() { numOfGoRoutines := 1 progress := make([]int, numOfGoRoutines) done := int64(0) goRoutineStarted := sync.WaitGroup{} goRoutineStarted.Add(numOfGoRoutines) goRoutineFinished := sync.WaitGroup{} goRoutineFinished.Add(numOfGoRoutines) for i := 0; i < numOfGoRoutines; i++ { go func(id int) { fmt.Println("Go routine started:", id) goRoutineStarted.Done() for atomic.LoadInt64(&done) == 0 { progress[id]++ } goRoutineFinished.Done() }(i) } goRoutineStarted.Wait() atomic.StoreInt64(&done, 1) goRoutineFinished.Wait() fmt.Println("All done. Progress: ", progress) } Main goroutine goroutine Are they scheduled equally?
  • 67.
  • 68. Go routine started: 1 Go routine started: 0 All done. Progress: [576524 578794] Total Time 4.84726ms
  • 69. Go routine started: 2 Go routine started: 1 Go routine started: 0 All done. Progress: [1281232 1537252 711224] Total Time 19.286207ms
  • 70. ?
  • 71. Go routine started: 0 Go routine started: 1 Go routine started: 3 Go routine started: 2
  • 72. Go routine started: 0 Go routine started: 1 Go routine started: 3 Go routine started: 2
  • 73. Go routine started: 0 Go routine started: 1 Go routine started: 3 Go routine started: 2
  • 74.
  • 75.
  • 76.
  • 77.
  • 78. func TestScheduler() { numOfGoRoutines := 1 progress := make([]int, numOfGoRoutines) done := int64(0) goRoutineStarted := sync.WaitGroup{} goRoutineStarted.Add(numOfGoRoutines) goRoutineFinished := sync.WaitGroup{} goRoutineFinished.Add(numOfGoRoutines) for i := 0; i < numOfGoRoutines; i++ { go func(id int) { fmt.Println("Go routine started:", id) goRoutineStarted.Done() for atomic.LoadInt64(&done) == 0 { progress[id]++ } goRoutineFinished.Done() }(i) } goRoutineStarted.Wait() atomic.StoreInt64(&done, 1) goRoutineFinished.Wait() fmt.Println("All done. Progress: ", progress) } No switching point
  • 79. func TestScheduler() { numOfGoRoutines := 1 progress := make([]int, numOfGoRoutines) done := int64(0) goRoutineStarted := sync.WaitGroup{} goRoutineStarted.Add(numOfGoRoutines) goRoutineFinished := sync.WaitGroup{} goRoutineFinished.Add(numOfGoRoutines) for i := 0; i < numOfGoRoutines; i++ { go func(id int) { fmt.Println("Go routine started:", id) goRoutineStarted.Done() for atomic.LoadInt64(&done) == 0 { progress[id]++ time.Sleep(0) } goRoutineFinished.Done() }(i) } goRoutineStarted.Wait() atomic.StoreInt64(&done, 1) goRoutineFinished.Wait() fmt.Println("All done. Progress: ", progress) }
  • 80. Go routine started: 3 Go routine started: 2 Go routine started: 1 Go routine started: 0 All done. Progress: [782164 773498 742771 794478] Total Time 42.244354ms
  • 81. func TestScheduler() { numOfGoRoutines := 1 progress := make([]int, numOfGoRoutines) done := int64(0) goRoutineStarted := sync.WaitGroup{} goRoutineStarted.Add(numOfGoRoutines) goRoutineFinished := sync.WaitGroup{} goRoutineFinished.Add(numOfGoRoutines) for i := 0; i < numOfGoRoutines; i++ { go func(id int) { fmt.Println("Go routine started:", id) goRoutineStarted.Done() for atomic.LoadInt64(&done) == 0 { progress[id]++ doSomething() } goRoutineFinished.Done() }(i) } goRoutineStarted.Wait() atomic.StoreInt64(&done, 1) goRoutineFinished.Wait() fmt.Println("All done. Progress: ", progress) } func doSomething() { doNothing() } func doNothing() { }
  • 82.
  • 83.
  • 84. TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go stack.go:18 0x1087050 65488b0c25a0080000 GS MOVQ GS:0x8a0, CX stack.go:18 0x1087059 483b6110 CMPQ 0x10(CX), SP stack.go:18 0x108705d 7635 JBE 0x1087094 stack.go:18 0x108705f 4883ec08 SUBQ $0x8, SP stack.go:18 0x1087063 48892c24 MOVQ BP, 0(SP) stack.go:18 0x1087067 488d2c24 LEAQ 0(SP), BP stack.go:18 0x108706b 48c744242000000000 MOVQ $0x0, 0x20(SP) stack.go:19 0x1087074 e827000000 CALL goway/stacksize.log(SB) stack.go:20 0x1087079 488b442410 MOVQ 0x10(SP), AX stack.go:20 0x108707e 488b4c2418 MOVQ 0x18(SP), CX stack.go:20 0x1087083 4801c8 ADDQ CX, AX stack.go:20 0x1087086 4889442420 MOVQ AX, 0x20(SP) stack.go:20 0x108708b 488b2c24 MOVQ 0(SP), BP stack.go:20 0x108708f 4883c408 ADDQ $0x8, SP stack.go:20 0x1087093 c3 RET stack.go:18 0x1087094 e8872efcff CALL runtime.morestack_noctxt(SB) stack.go:18 0x1087099 ebb5 JMP goway/stacksize.Add(SB)
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94. File I/ONetwork I/O Thread Poolepoll kqueue IOCP File I/O Syscalls Network I/O Thread Cache Netpoller epoll kqueue IOCP Node.JS Go