Why I love Go: Concurrency
DevMemphis - Dec 2024 - Bryce Sharp
Why I love Go: Concurrency
DevMemphis - Dec 2024 - Bryce Sharp
Why I love Go: Concurrency
DevMemphis - Dec 2024 - Bryce Sharp
Why I love Go: Concurrency
DevMemphis - Dec 2024 - Bryce Sharp
What's in the talk?
> Concurrency & Parallelism
> High Level Hardware Concepts
> Real World Problems
> Go Basics
> Go Concurrency
> Goroutines
> Channels
> Live Demo
> Q&A
Concurrency & Parallelism
They are not the same thing.
Concurrency
: handling multiple processes on a single cpu
Parallelism
: running at least one process on multiple cpus at the same time
Concurrency & Parallelism
One Gopher Concurrently 3 Gophers Juggling 3 Balls
Juggling 3 Balls In Parallel
Concurrency & Parallelism
Gophers = CPUs
Balls = Processes
High Level Hardware Concepts
Central Processing Unit
Works with binary streams to do the
binary math that enable modern computing
Modern day CPUs tend to possess multiple
cores
High Level Hardware Concepts
CPU
Memory
Kernel
Apps
CPU
High Level Hardware Concepts
High Level Hardware Concepts
Memory
Random Access Memory (RAM) and Disc Drives
are the most known
Holds physical representation of our application
layer data
CPU
Memory
CPU
00101
00101
10100
High Level Hardware Concepts
CPU
10100
Memory
Real World Problems
#1: Sending multiple http requests at the same time
#2: Throttling SQL queries in batch processing
High Level Hardware Concepts
High Level Hardware Concepts
Go Basics
Designed at Google in 2007 and open sourced in 2009
Efficiency & Usability Focused
Statically Typed
Go Concurrency
Goroutine
: "a lightweight thread managed by the Go runtime"
Channel
: "a typed conduit through which you can send and receive values
with the channel operator, <-"
- Tour of Go
Go Concurrency
" Do not communicate by sharing memory;
instead, share memory by communicating"
Goroutine
Channels
Go Concurrency
Goroutines are not thread safe. Communicating exclusively through
channels solves this problem. There is a mutex on the channel that
serves as synchronization across goroutines
Go Concurrency
Go uses an M:N scheduler to make goroutines "user-space threads"
Live Demo
Q&A
Thank you for listening!
OS Thread 1
OS Thread 2
go 1
go 3
go 2
go 3
go 2
go 1
go 2
Go
package main
import "fmt"
func main() {
fmt.Println("Hello");
}
Chapter 1
Go
package main
import "fmt"
func main() {
fmt.Println("Hello");
}
Chapter 1
Go
package main
import "fmt"
func main() {
fmt.Println("Hello");
}
Chapter 1
Go
package main
import "fmt"
func main() {
fmt.Println("Hello");
}
Chapter 1
Special Thanks To
> Free Gopher Graphics: https://github.com/egonelbre/gophers
> Free Gopher Graphics: https://github.com/MariaLetta/free-gophers-pack
> Background img:
https://pixabay.com/vectors/cartoon-pink-tree-landscape-field-7106965/
> GopherCon 2017 - Kavya Joshi
https://www.youtube.com/watch?v=KBZlN0izeiY
> A Tour of Go: https://go.dev/tour
> Go Docs: https://pkg.go.dev/std
Go
package main
import "fmt"
func main() {
fmt.Println("Hello");
}
Chapter 1
Go
package main
import "fmt"
func main() {
fmt.Println("Hello");
}
Chapter 1
Live Demo
1
New frame
New frame
New frame
New frame
New frame
New frame
New frame
New frame
New frame
New frame
New frame
New frame
New frame
New frame
New frame
New frame
New frame
New frame
New frame
New frame
New frame
New frame
New frame
New frame
New frame