Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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;
c...
var mysql = require('mysql');
var con = mysql.createConnection({
...
});
con.connect(function(err) {
if (err) throw err;
c...
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/gowa...
go build -gcflags '-N -l'
go tool objdump -s stacksize.Add goway
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/gowa...
go build -gcflags '-N -l'
go tool objdump -s stacksize.Add goway
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/gowa...
go build -gcflags '-N -l'
go tool objdump -s stacksize.Add goway
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/gowa...
go build -gcflags '-N -l'
go tool objdump -s stacksize.Add goway
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/gowa...
go build -gcflags '-N -l'
go tool objdump -s stacksize.Add goway
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/gowa...
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 ...
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:18 0x1087050 65488b0c25a0080000 GS ...
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:18 0x1087050 65488b0c25a0080000 GS ...
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:18 0x1087050 65488b0c25a0080000 GS ...
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:18 0x1087050 65488b0c25a0080000 GS ...
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:18 0x1087050 65488b0c25a0080000 GS ...
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:18 0x1087050 65488b0c25a0080000 GS ...
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:18 0x1087050 65488b0c25a0080000 GS ...
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:18 0x1087050 65488b0c25a0080000 GS ...
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:18 0x1087050 65488b0c25a0080000 GS ...
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 := ...
func TestScheduler() {
numOfGoRoutines := 2
progress := make([]int, numOfGoRoutines)
done := int64(0)
goRoutineStarted := ...
func TestScheduler() {
numOfGoRoutines := 1
progress := make([]int, numOfGoRoutines)
done := int64(0)
goRoutineStarted := ...
func TestScheduler() {
numOfGoRoutines := 1
progress := make([]int, numOfGoRoutines)
done := int64(0)
goRoutineStarted := ...
func TestScheduler() {
numOfGoRoutines := 1
progress := make([]int, numOfGoRoutines)
done := int64(0)
goRoutineStarted := ...
func TestScheduler() {
numOfGoRoutines := 1
progress := make([]int, numOfGoRoutines)
done := int64(0)
goRoutineStarted := ...
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 ...
?
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 := ...
func TestScheduler() {
numOfGoRoutines := 1
progress := make([]int, numOfGoRoutines)
done := int64(0)
goRoutineStarted := ...
Go routine started: 3
Go routine started: 2
Go routine started: 1
Go routine started: 0
All done. Progress: [782164 773498...
func TestScheduler() {
numOfGoRoutines := 1
progress := make([]int, numOfGoRoutines)
done := int64(0)
goRoutineStarted := ...
TEXT goway/stacksize.Add(SB) /Users/eyalp/gocode/src/goway/stacksize/stack.go
stack.go:18 0x1087050 65488b0c25a0080000 GS ...
File I/ONetwork I/O
Thread Poolepoll kqueue IOCP
File I/O
Syscalls
Network I/O
Thread Cache
Netpoller
epoll kqueue IOCP
No...
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Why Go Scales
Upcoming SlideShare
Loading in …5
×

Why Go Scales

1,419 views

Published on

Comparing the concurrency\thread model of Go and other languages\technologies like Node.JS, Java etc to understand how Go solves the C10K problem
The video for this session is available here: https://www.youtube.com/watch?v=e2QVjmN5IF4

Published in: Technology

Why Go Scales

  1. 1. Gett is changing how people move around and Gett things
  2. 2. timers I/O callbacks Idle, prepare poll check close callbacks
  3. 3. libuv File I/ONetwork I/O TCP UDP TTY PIPE Thread Poolepoll kqueue IOCP
  4. 4. 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
  5. 5. 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
  6. 6. func Add(a, b int) int { return a + b }
  7. 7. go build -gcflags '-N -l' go tool objdump -s stacksize.Add goway
  8. 8. go build -gcflags '-N -l' go tool objdump -s stacksize.Add goway
  9. 9. go build -gcflags '-N -l' go tool objdump -s stacksize.Add goway
  10. 10. 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
  11. 11. 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 }
  12. 12. 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 }
  13. 13. 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 }
  14. 14. 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 }
  15. 15. 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 }
  16. 16. func Add(a, b int) int { log() return a + b }
  17. 17. 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)
  18. 18. 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)
  19. 19. 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)
  20. 20. 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)
  21. 21. 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)
  22. 22. 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)
  23. 23. 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)
  24. 24. 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)
  25. 25. 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)
  26. 26. 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)
  27. 27. func Add(a, b int) int { log() return a + b }
  28. 28. func Add(a, b int) int { var bytes [100]byte return a + b + int(bytes[0]) }
  29. 29. func Add(a, b int) int { var bytes [105]byte return a + b + int(bytes[0]) }
  30. 30. 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
  31. 31. 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
  32. 32. 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
  33. 33. 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++
  34. 34. 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?
  35. 35. 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?
  36. 36. Go routine started: 1 Go routine started: 0 All done. Progress: [576524 578794] Total Time 4.84726ms
  37. 37. Go routine started: 2 Go routine started: 1 Go routine started: 0 All done. Progress: [1281232 1537252 711224] Total Time 19.286207ms
  38. 38. ?
  39. 39. Go routine started: 0 Go routine started: 1 Go routine started: 3 Go routine started: 2
  40. 40. Go routine started: 0 Go routine started: 1 Go routine started: 3 Go routine started: 2
  41. 41. Go routine started: 0 Go routine started: 1 Go routine started: 3 Go routine started: 2
  42. 42. 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
  43. 43. 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) }
  44. 44. 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
  45. 45. 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() { }
  46. 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. 47. 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

×