10. Why Go?
• Problem 1: System Scale
• designed to scale to 10⁶⁺ machines
• everyday jobs run on 1000s of machines
• jobs coordinate, interact with others in the system
• lots going on at once
• Solution: great support for concurrency
• Problem 2: Engineering Scale
• 5000+ developers across 40+ offices
• 20+ changes per minute
• 50% of code base changes every month
• 50 million test cases executed per day
• single code tree
• Solution: design the language for large code bases
11. Who uses Go at Google?
• Hundreds of projects. Thousands of Go programmers. Millions of lines of Go code.
• Public examples:
• Flywheel: SPDY proxy for Chrome on mobile devices
• dl.google.com: Download server for Chrome, ChromeOS, Android SDK, Earth, etc.
• Vitess: YouTube MySQL balancer
• Seesaw: Linux Virtual Server (LVS) based load balancer
• Lingo: Logs analysis in Go, migrated from Sawzall
• The target is networked servers, but Go is a great general-purpose language.
13. 2016 Skills On the Rise
http://www.payscale.com/data-packages/job-skills?utm_content=bufferf478a&utm_medium=social&utm_source=linkedin.com&utm_campaign=buffer
14. • 빠른 개발속도
• 모듈화를 위한 의존성
• 정적타입이지만 동적타입 언어의 속성도 가진 언어
• 가비지 컬렉션 (Garbage Collection) // No VM
• 쉬운 병렬처리 (Parallelism)
• 빠른 컴파일 속도
• 소스코드 UTF-8
The feature of Go
15. • No classes
• No inheritance
• No constructors
• No final
• No exceptions
• No annotations
• No user-defined generics
Not the feature of Go
16. Go 는 Object-Oriented 언어인가?
• 맞기도 하고 아니기도 하다.
• http://golang.org/doc/faq#Is_Go_an_object-oriented_language
• 아닌 이유
• 상속관계가 없다. No subclass
• 맞는 이유
• object-oriented 스타일의 프로그래밍을 허용한다. interface제공.
• object-oriented 스타일의 프로그래밍?
• 상속은 제공하지 않으며 interface만 제공.
• implements"라는 선언 필요없음.
• 단순히 해당 인터페이스의 메소드를 구현하기만 하면 인터페이스 사용가능
20. Fast compilation times
• 빠른 컴파일 속도는 Go의 설계 목표중 하나였다.
• 문법이 compiler가 분석하기 용이하게 설계되었고 symbol table없이 구문분석이 가
• Go는 각각의 파일에서 선언한 패키지를 사용하지 않으면 에러가 발생하므로
종속성 트리를 계산하는게 효율적이다.
• Go는 templates과 선언파일(ex .h) 이없다.
• 패키지들이 선형종속성이므로 병렬 컴파일 가능.
21. • gc compiler
• gccgo compiler
gcc is required only if you plan to use cgo.
34. Go루틴(Goroutines)
• OS 쓰레드보다 경량화된 Go 쓰레드
• 같은 메모리 공간을 공유해서 다른 Goroutines을 병렬로 실행한다.
• 스택에서 작은 메모리로 시작 필요에 따라 힙 메모리에 할당/해제
• 프로그래머는 쓰레드를 처리하지 않고 마찬가지로 OS도 Goroutine의 존재를 모른
• OS관점에서는 Goroutine은 C program의 event-driven형식처럼 작동한다.
35. Goroutines vs OS threads
Goroutines OS threads
Memory consumption 2kb 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),
segment registers, 16 XMM
registers, FP coprocessor state,
16 AVX registers, all MSRs etc.Goroutine stack size was decreased from 8kB to 2kB in Go 1.4.
36. Goroutines blocking
• network input
• sleeping
• channel operations or
• blocking on primitives in the sync package.
• call function (case by case)
53. Five things that make Go fast
• Values
• Inlining
• Escape Analysis
• Goroutines
• segmented/copying stacks.
http://dave.cheney.net/2014/06/07/five-things-that-make-go-fast
54. Escape analysis
• Funtion안에 변수가 레퍼런스 타입으로 선언되었는지에 따라 영향받음.
• 만약 레퍼런스 타입이 아니라면 변수는 스택에 안전하게 저장할 수 있다
• 스택에 저장되어있는 값은 할당과 해제 할 필요없다.
http://dave.cheney.net/2014/06/07/five-things-that-make-go-fast
57. Memory model
• Go에서 각 변수는 참조가 존재하는 한 계속 남아 있다.
• 가능하면 Go 컴파일러는 변수를 함수의 스택 프레임(stack frame)에 있는
함수에 지역변수로 할당한다.
• 컴파일러가 함수가 리턴되고 난 후에 변수가 참조되지 않는다는 것을 증명할
수 없다면 컴파일러는 dangling pointer 오류를 피하기 위해서 가비지 콜렉션
이 되는 힙에 변수를
할당해야만 한다.