History
"What should a modern, practical programming language look like?"
History
Design began in late 2007.
History
system programming.
10 November 2009: Go was released. (78c47c3)
The Release
Open Source
- 개발속도
- 모듈화를 위한 의존성
- 정적타입이지만 동적타입 언어의 속성도 가진 언어
- 가비지 컬렉션 (Garbage Collection)
- 병렬처리 (Parallelism)
The feature of Go
Go is fast
https://www.techempower.com/benchmarks/#section=data-r10&hw=ec2&test=json&f=3qvc8-8vn3eo-4-0
Concurrency is not parallelism
Lock Condition
Actor
Communicating Sequential Processes
Actor와 다른점은 Actor 는 pid에게 전달을 하지만 Csp는 anonymous로 channel로 전달함
Interpreted Language?
Statically compiled language
• gc compiler
• gccgo compiler
gcc is required only if you plan to use cgo.
Godoc
Go 는 Object-Oriented 언어인가?
• 맞기도 하고 아니기도 하다.
• http://golang.org/doc/faq#Is_Go_an_object-oriented_language
• 아닌 이유
• 상속관계가 없다. No subclass
• 맞는 이유
• object-oriented 스타일의 프로그래밍을 허용한다. interface제공.
• object-oriented 스타일의 프로그래밍?
• 상속은 제공하지 않으며 interface만 제공.
• implements"라는 선언 필요없음.
• 단순히 해당 인터페이스의 메소드를 구현하기만 하면 인터페이스 사용가능
Go루틴(Goroutines)
• OS 쓰레드보다 경량화된 Go 쓰레드
• 같은 메모리 공간을 공유해서 다른 Goroutines을 병렬로 실행한다.
• 스택에서 작은 메모리로 시작 필요에 따라 힙 메모리에 할당/해제
• 프로그래머는 쓰레드를 처리하지 않고 마찬가지로 OS도 Goroutine의 존재를 모른다.
• OS관점에서는 Goroutine은 C program의 event-driven형식처럼 작동한다.
Goroutines vs OS threads
Goroutines OS threads
Memory
consumption
4kb 1mb
Setup and
teardown costs
pretty cheap high-priced
Switching costs
(saved/restored)
Program Counter,
Stack Pointer and DX.
ALL registers, that is, 16 general
purpose registers, PC (Program
Counter), SP (Stack Pointer),
Goroutines blocking
• network input
• sleeping
• channel operations or
• blocking on primitives in the sync package.
GOMAXPROCS
Channel
Unbuffered Channels
Buffered Channels
Go 언어는 메모리를 관리해주는 가비지 컬렉터(Garbage Collector)가
실행 파일(runtime)안에 내장되어 있습니다.
Garbage Collector
Go isn’t Java: GC Related Go Differences
Garbage Collector
Google Confidential and Proprietary
GC 101
Scan Phase
Heap
Stacks/Registers
Globals
Garbage Collector
Google Confidential and Proprietary
Mark Phase
Stacks/Registers
Globals
Righteous Concurrent GC struggles with Evil Application changing pointers
Google Confidential and Proprietary
Sweep Phase
Stacks/Registers
Globals
Garbage Collector
Google Confidential and Proprietary
GC Algorithm Phases
Off
Stack scan
Mark
Mark termination
Sweep
Off
Correctness proofs in literature (see me)
WBon
STW
GC disabled
Pointer writes are just memory writes: *slot = ptr
Collect pointers from globals and goroutine stacks
Stacks scanned at preemption points
Mark objects and follow pointers until pointer queue is empty
Write barrier tracks pointer changes by mutator
Rescan globals/changed stacks, finish marking, shrink stacks, …
Literature contains non-STW algorithms: keeping it simple for now
Reclaim unmarked objects as needed
Adjust GC pacing for next cycle
Rinse and repeat
Garbage Collector
Google Confidential and Proprietary
1.4 Stop the World
GCGC
Application Application
Garbage Collector
Google Confidential and Proprietary
Application
ApplicationApplication
Assist
GC
Application
Assist
GC
1 ms 3 ms
1.5 Concurrent GC
Garbage Collector
Garbage Collector

JSON: Increasing Heap Size == Better Performance
Memory model
• Go에서 각 변수는 참조가 존재하는 한 계속 남아 있다.
• 가능하면 Go 컴파일러는 변수를 함수의 스택 프레임(stack frame)에 있는 

함수에 지역변수로 할당한다.
• 컴파일러가 함수가 리턴되고 난 후에 변수가 참조되지 않는다는 것을 증명할 수 없다면 컴

파일러는 dangling pointer 오류를 피하기 위해서 가비지 콜렉션이 되는 힙에 변수를 

할당해야만 한다.
Defer
Panic & recover
For

Introduction to Golang

  • 2.
  • 3.
    "What should amodern, practical programming language look like?" History
  • 4.
    Design began inlate 2007. History system programming.
  • 5.
    10 November 2009:Go was released. (78c47c3) The Release
  • 6.
  • 8.
    - 개발속도 - 모듈화를위한 의존성 - 정적타입이지만 동적타입 언어의 속성도 가진 언어 - 가비지 컬렉션 (Garbage Collection) - 병렬처리 (Parallelism) The feature of Go
  • 9.
  • 10.
    Concurrency is notparallelism
  • 11.
  • 12.
  • 13.
    Communicating Sequential Processes Actor와다른점은 Actor 는 pid에게 전달을 하지만 Csp는 anonymous로 channel로 전달함
  • 14.
  • 15.
  • 16.
    • gc compiler •gccgo compiler gcc is required only if you plan to use cgo.
  • 18.
  • 21.
    Go 는 Object-Oriented언어인가? • 맞기도 하고 아니기도 하다. • http://golang.org/doc/faq#Is_Go_an_object-oriented_language • 아닌 이유 • 상속관계가 없다. No subclass • 맞는 이유 • object-oriented 스타일의 프로그래밍을 허용한다. interface제공. • object-oriented 스타일의 프로그래밍? • 상속은 제공하지 않으며 interface만 제공. • implements"라는 선언 필요없음. • 단순히 해당 인터페이스의 메소드를 구현하기만 하면 인터페이스 사용가능
  • 22.
    Go루틴(Goroutines) • OS 쓰레드보다경량화된 Go 쓰레드 • 같은 메모리 공간을 공유해서 다른 Goroutines을 병렬로 실행한다. • 스택에서 작은 메모리로 시작 필요에 따라 힙 메모리에 할당/해제 • 프로그래머는 쓰레드를 처리하지 않고 마찬가지로 OS도 Goroutine의 존재를 모른다. • OS관점에서는 Goroutine은 C program의 event-driven형식처럼 작동한다.
  • 23.
    Goroutines vs OSthreads Goroutines OS threads Memory consumption 4kb 1mb Setup and teardown costs pretty cheap high-priced Switching costs (saved/restored) Program Counter, Stack Pointer and DX. ALL registers, that is, 16 general purpose registers, PC (Program Counter), SP (Stack Pointer),
  • 24.
    Goroutines blocking • networkinput • sleeping • channel operations or • blocking on primitives in the sync package.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
    Go 언어는 메모리를관리해주는 가비지 컬렉터(Garbage Collector)가 실행 파일(runtime)안에 내장되어 있습니다. Garbage Collector
  • 30.
    Go isn’t Java:GC Related Go Differences
  • 31.
    Garbage Collector Google Confidentialand Proprietary GC 101 Scan Phase Heap Stacks/Registers Globals
  • 32.
    Garbage Collector Google Confidentialand Proprietary Mark Phase Stacks/Registers Globals Righteous Concurrent GC struggles with Evil Application changing pointers
  • 33.
    Google Confidential andProprietary Sweep Phase Stacks/Registers Globals Garbage Collector
  • 34.
    Google Confidential andProprietary GC Algorithm Phases Off Stack scan Mark Mark termination Sweep Off Correctness proofs in literature (see me) WBon STW GC disabled Pointer writes are just memory writes: *slot = ptr Collect pointers from globals and goroutine stacks Stacks scanned at preemption points Mark objects and follow pointers until pointer queue is empty Write barrier tracks pointer changes by mutator Rescan globals/changed stacks, finish marking, shrink stacks, … Literature contains non-STW algorithms: keeping it simple for now Reclaim unmarked objects as needed Adjust GC pacing for next cycle Rinse and repeat
  • 35.
    Garbage Collector Google Confidentialand Proprietary 1.4 Stop the World GCGC Application Application
  • 36.
    Garbage Collector Google Confidentialand Proprietary Application ApplicationApplication Assist GC Application Assist GC 1 ms 3 ms 1.5 Concurrent GC
  • 37.
  • 38.
    Garbage Collector
 JSON: IncreasingHeap Size == Better Performance
  • 39.
    Memory model • Go에서각 변수는 참조가 존재하는 한 계속 남아 있다. • 가능하면 Go 컴파일러는 변수를 함수의 스택 프레임(stack frame)에 있는 
 함수에 지역변수로 할당한다. • 컴파일러가 함수가 리턴되고 난 후에 변수가 참조되지 않는다는 것을 증명할 수 없다면 컴
 파일러는 dangling pointer 오류를 피하기 위해서 가비지 콜렉션이 되는 힙에 변수를 
 할당해야만 한다.
  • 41.
  • 42.
  • 43.