Erlang and Go (CS262a, Berkeley Fall 2016) Philipp Moritz

Similar documents
Introduzione a Go e RPC in Go

The Awesomeness of Go. Igor Lankin DevFest Karlsruhe, Nov 2016

Erlang 101. Google Doc

Erlang. Joe Armstrong.

Message Passing. Advanced Operating Systems Tutorial 7

Erlang. Joe Armstrong

The Go Programming Language. Frank Roberts

Go Tutorial. To do. A brief, gentle intro to Go. Next Networking. q Today

Programming Paradigms

Go Tutorial. Arjun Roy CSE 223B, Spring 2017

Chapter 1 INTRODUCTION SYS-ED/ COMPUTER EDUCATION TECHNIQUES, INC.

The do s and don ts of error handling. Joe Armstrong

Lecture Overview Methods and Interfaces Methods review Interfaces Example: using the sort interface Anonymous fields in structs

Quick Review of Object-Oriented Programming in Go

Go Forth and Code. Jonathan Gertig. CSC 415: Programing Languages. Dr. Lyle

The Actor Model, Part Two. CSCI 5828: Foundations of Software Engineering Lecture 18 10/23/2014

Erlang and Concurrency. André Pang Rising Sun Research

Go Cheat Sheet. Operators. Go in a Nutshell. Declarations. Basic Syntax. Hello World. Functions. Comparison. Arithmetic. Credits

Reminder from last time

Last Time: Objects and Abstraction. If it walks like a circle, swims like a circle, and quacks like a circle...!

Using the Go Programming Language in Practice

Motivations History Principles Language Gommunity Success stories Conclusion. Let s Go! A brief introduction to Google s new language.

Go Language September 2016

Scripting with Luerl

EASILY DEPLOY AND SCALE KUBERNETES WITH RANCHER

Swift 5, ABI Stability and

Inter-process communication (IPC)

Understanding and Evaluating Kubernetes. Haseeb Tariq Anubhavnidhi Archie Abhashkumar

Important DevOps Technologies (3+2+3days) for Deployment

Timers 1 / 46. Jiffies. Potent and Evil Magic

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Semaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; }

Last Class Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications

Applying Componentbased. Engineering in On-board Software


All you need is fun. Cons T Åhs Keeper of The Code

Operating Systems (ECS 150) Spring 2011

CMSC421: Principles of Operating Systems

Chapter 3 Processes. Process Concept. Process Concept. Process Concept (Cont.) Process Concept (Cont.) Process Concept (Cont.)

Lecture 8: February 19

New Parallel Programming Languages for Optimization Research

go get my/vulnerabilities Green threads are not eco friendly threads

OpenACC Course. Office Hour #2 Q&A

Last 2 Classes: Introduction to Operating Systems & C++ tutorial. Today: OS and Computer Architecture

Operating System Structure

CS 520 Theory and Practice of Software Engineering Fall 2018

Go on NetBSD (and pkgsrc!) A modern systems programming language 23 March Benny Siegert Google Switzerland; The NetBSD Foundation

Introduction to pthreads

Multi-core Programming: Introduction

Making Cloud Easy: Components of a Distributed. Design Considerations and First. Operating System for Cloud

9/17/12! Ion Stoica CS162 UCB Fall 2012!


M/s. Managing distributed workloads. Language Reference Manual. Miranda Li (mjl2206) Benjamin Hanser (bwh2124) Mengdi Lin (ml3567)

Chapter 1 GETTING STARTED. SYS-ED/ Computer Education Techniques, Inc.

Let s Go! Akim D le, Etienne Renault, Roland Levillain. June 8, TYLA Let s Go! June 8, / 58

Utilizing Linux Kernel Components in K42 K42 Team modified October 2001

Go Circuit: Distributing the Go Language and Runtime. Petar Maymounkov

Characterising Resource Management Performance in Kubernetes. Appendices.

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Computer Systems Engineering: Spring Quiz I Solutions

Last class: Today: Thread Background. Thread Systems

4. Functional Programming Language-Oriented Programming

To Everyone... iii To Educators... v To Students... vi Acknowledgments... vii Final Words... ix References... x. 1 ADialogueontheBook 1

CS 261 Fall Mike Lam, Professor. Threads

Grid Computing with Voyager

Building Microservices with the 12 Factor App Pattern

6.828: OS/Language Co-design. Adam Belay

CS 5460/6460 Operating Systems

Managing Openstack in a cloud-native way

How Rust views tradeoffs. Steve Klabnik

CSCI-1680 RPC and Data Representation. Rodrigo Fonseca

DS 2009: middleware. David Evans

CSE 544 Principles of Database Management Systems

CS 326: Operating Systems. Process Execution. Lecture 5

developed ~2007 by Robert Griesemer, Rob Pike, Ken Thompson open source

Operating System Structure

Beyond 1001 Dedicated Data Service Instances

Systems software design. Processes, threads and operating system resources

The Go Programming Language. Part 3

Kernels & Processes The Structure of the Operating System

Cloud Native Applications. 主讲人 :Capital One 首席工程师 Kevin Hoffman

Steps for project success. git status. Milestones. Deliverables. Homework 1 submitted Homework 2 will be posted October 26.

Motivation. Threads. Multithreaded Server Architecture. Thread of execution. Chapter 4

Building loosely coupled and scalable systems using Event-Driven Architecture. Jonas Bonér Patrik Nordwall Andreas Källberg

Administration CS 412/413. Why build a compiler? Compilers. Architectural independence. Source-to-source translator

André Pang. Concurrency and Erlang

Programming Language Impact on the Development of Distributed Systems

Process Description and Control

Towards a Resilient Operating System for Wireless Sensor Networks

PROJECT 6: PINTOS FILE SYSTEM. CS124 Operating Systems Winter , Lecture 25

Chapter 6: Process Synchronization

Introduction Storage Processing Monitoring Review. Scaling at Showyou. Operations. September 26, 2011

Don t let data Go astray

Question: How can we compare two objects of a given class to see if they are the same? Is it legal to do: Rectangle r(0,0,3,3);,, Rectangle s(0,0,4,4)

Main Points of the Computer Organization and System Software Module

CS 318 Principles of Operating Systems

Special Topics: Programming Languages

CSCI-1680 RPC and Data Representation. Rodrigo Fonseca

Lecture Topics. Announcements. Today: Operating System Overview (Stallings, chapter , ) Next: Processes (Stallings, chapter

Our First Programs. Programs. Hello World 10/7/2013

Discussion CSE 224. Week 4

Transcription:

Erlang and Go (CS262a, Berkeley Fall 2016) Philipp Moritz

The Problem Distributed computation is hard! State Hard to do recovery, dependency on order of execution Concurrency and Synchronization Hard to reason about, deadlocks Fault handling Error origin and handling in different parts of the system Complexity of coupled components Makes it hard to develop software in large teams This lecture is about languages/tools that make it easier to write distributed programs

Erlang Developed at Ericson as a proprietary language to improve development of telephony applications High availability of nine 9 s (30 ms downtime per year) 1986: initial version in Prolog 1992: BEAM (High performance VM) since 1998: Open source named after Agner Krarup Erlang, mathematician and inventor of queuing theory

Erlang: Requirements Designed for telecommunication systems Hard requirements: High degree of concurrency Distributed Soft real-time capabilities 100% availability Soft requirements: Hot swapping code

Erlang: Philosophy Requirements Decision 100% availability

Erlang: Philosophy Requirements 100% availability Decision strong fault recovery hierarchy of tasks for recovery isolation between tasks dynamic code upgrade

Erlang: Philosophy Requirements 100% availability portability (e.g. to embedded devices) Decision strong fault recovery hierarchy of tasks for recovery isolation between tasks dynamic code upgrade

Erlang: Philosophy Requirements 100% availability portability (e.g. to embedded devices) Decision strong fault recovery hierarchy of tasks for recovery isolation between tasks dynamic code upgrade agnostic to OS green processes doesn t use OS services

Erlang: Philosophy Requirements 100% availability portability (e.g. to embedded devices) high concurrency soft real-time Decision strong fault recovery hierarchy of tasks for recovery isolation between tasks dynamic code upgrade agnostic to OS green processes doesn t use OS services

Erlang: Philosophy Requirements 100% availability portability (e.g. to embedded devices) high concurrency soft real-time Decision strong fault recovery hierarchy of tasks for recovery isolation between tasks dynamic code upgrade agnostic to OS green processes doesn t use OS services very lightweight processes, communicate via channels share nothing asynchronous calls

Design Tradeoffs Performance Erlang is a safe language (cf. SPIN) fast IPC (same address space) isolation via language semantics Security/Isolation Concurrency Decoupling components with Share nothing semantics Maintainability

Erlang: Error handling Crash early Let some other process do the error recovery Do not program defensively If you cannot handle the error, don t try to recover

Erlang: Concurrency Distributed actor model (asynchronous message passing) Exposed via spawning processes and asynchronous message passing between them % invoke web:start_server(port, MaxConns) ServerProcess = spawn(web, start_server, [Port, MaxConns]), % invoke web:start_server on machine RemoteNode RemoteProcess = spawn(remotenode, web, start_server, [Port, MaxConns]), % Send a message to ServerProcess (asynchronously). ServerProcess! {pause, 10}, % Receive messages sent to this process receive a_message -> do_something; {data, DataContent} -> handle(datacontent); {hello, Text} -> io:format(...); {goodbye, Text} -> io:format(...) end.

Erlang: Example Server client example

Erlang: Implementation Green processes (can launch millions of them) mapped to OS threads Support priorities Preemptive scheduler (every ~2000 function calls) native C code needs to be instrumented to pass control to VM IO threads to handle blocking IO robust and well tested has been used in critical infrastructure by multiple companies minimal dependence on OS https://github.com/erlang/otp https://hamidreza-s.github.io/erlang/scheduling/real-time/preemptive/migration/20 16/02/09/erlang-scheduler-details.html

Does Erlang achieve its goals?

Erlang: Impact Highly commercially successful in telecom industry Ericson Nortel T-Mobile WhatsApp Facebook chat (200 Mio users) Elixir RabbitMQ

Go: History Started as an experiment at Google to design a language that would solve challenges that come up in large scale software development First appeared 2009, first stable release in 2011 Rob Pike, co-creator of Go

Go: Motivation Developing large software components with large team is hard Slow builds Dependencies and libraries Complex languages, everybody uses a different subset Developing distributed software is even harder Concurrency not natively supported by many existing languages

Influence from Plan 9 Plan 9 from Bell Labs: Everything is a file Special C dialect: No recursive #includes Unicode Distributed (byte oriented protocol 9P to exchange data between nodes) Compiler infrastructure shared

Standardization and Tooling One way to do things (cf. Python) Standardized tooling: go get: Package manager integrated with the language and github go fmt: Put code into a standard format go test: Unit testing and microbenchmarks go vet: Static analysis and linting go fix: Automatically update APIs and language constructs Statically linked binaries

Simplicity Few concepts that are orthogonal and composable: Concurrency Goroutines (execution) Channels (communication) Select (coordination) Object oriented programming Interfaces (contracts) structs (data) functions (code) No Templates/Generics (instead: interface {}) No exceptions One type of loop https://talks.golang.org/2015/simplicity-is-complicated.slide

Go Concurrency Goroutines are lightweight threads that share the same address space Communication happens over channels More permissive than Erlangs: Can pass pointers over channels func sum(s []int, c chan int) { sum := 0 for _, v := range s { sum += v } c <- sum // send sum to c } func main() { s := []int{7, 2, 8, -9, 4, 0} } c := make(chan int) go sum(s[:len(s)/2], c) go sum(s[len(s)/2:], c) x, y := <-c, <-c // receive from c fmt.println(x, y, x+y)

Go Interfaces type geometry interface { area() float64 perim() float64 } type rect struct { width, height float64 } func (r rect) area() float64 { return r.width * r.height } func (r rect) perim() float64 { return 2*r.width + 2*r.height } type circle struct { radius float64 } func (c circle) area() float64 { return math.pi * c.radius * c.radius } func (c circle) perim() float64 { return 2 * math.pi * c.radius }

Go Interfaces interface {} Reader implements Read Writer implements Write Stringer implements String Formatter implements Format There are lots of interfaces in the standard library and in external libraries http://sweetohm.net/article/go-interfaces.en.html

Discussion: Does Go achieve its goals?

Go success stories Docker Kubernetes etcd Google: components of youtube.com and also dl.google.com Many companies are using it for distributed applications: Uber Dropbox Netflix