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

Save this PDF as:

Size: px
Start display at page:

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

## Transcription

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

2 Goals Cover the material presented in Chapter 5, of our concurrency textbook In particular, the material presented in Days 2 and 3 2

3 Fibonacci Calculator (I) Let s jump back into Elixir and the Actor model This example is taken from the excellent Programming Elixir book from Pragmatic Programmers We ll take a look at using Actors to calculate Fibonacci numbers 0, 1, 1, 2, 3, 5, 8, 13, Our example will calculate a set of Fibonacci numbers using a different number of actors; starting with one actor and proceeding up to ten actors running at once 3

4 Elixir Function Composition In order to understand the source code of the example, we must review Elixir s function composition operator, also known as the pipe operator If you had a series of statement like this a = f(x); b = g(a); c = h(b) You could also write it like this c = h(g(f(x))) In Elixir, you would write it like c = x > f > g > h x is piped into f, the result is piped into g, the result is piped into h The functions on the right hand side can have parameters x > f(y, z) is equivalent to calling f(x, y, z) the thing being piped becomes the first argument of the function on the right hand side 4

5 Fibonacci Calculator (II) To start our Fibonacci example, we first design two actors A solver: is able to calculate the nth Fibonacci number A scheduler: distributes calculation requests to a set of 1 or more solvers A solver will sit in loop and do the following It sends {:ready, pid} to the scheduler It will then receive a :fib message asking it to calculate a number When it is done, it will send an :answer message to the scheduler The solver will perform these actions until it receives a :shutdown message The scheduler will receive an array of integers that represent the Fibonacci numbers to calculate it will send out :fib messages to :ready solvers until all requests are done 5

6 Fibonacci Calculator (III) The solver 1 defmodule FibSolver do 2 3 def fib(scheduler) do 4 send(scheduler, {:ready, self}) 5 receive do 6 {:fib, n, client} -> 7 send(client, {:answer, n, fib_calc(n), self}) 8 fib(scheduler) 9 {:shutdown} -> exit(:normal) 10 end 11 end defp fib_calc(0) do 0 end 14 defp fib_calc(1) do 1 end 15 defp fib_calc(n) do fib_calc(n-1) + fib_calc(n-2) end 16 end 6

7 Fibonacci Calculator (IV): The Scheduler 1 defmodule Scheduler do 2 3 def run(num_processes, module, func, to_calculate) do 4 (1..num_processes) 5 > Enum.map(fn(_) -> spawn(module, func, [self]) end) 6 > schedule_processes(to_calculate, []) 7 end 8 9 defp schedule_processes(processes, queue, results) do 10 receive do 11 {:ready, pid} when length(queue) > 0 -> 12 [ next tail ] = queue 13 send(pid, {:fib, next, self}) 14 schedule_processes(processes, tail, results) {:ready, pid} -> 17 send(pid, {:shutdown}) 18 if length(processes) > 1 do 19 schedule_processes(list.delete(processes, pid), queue, results) 20 else 21 Enum.sort(results, fn ({n1, _}, {n2, _}) -> n1 <= n2 end) 22 end {:answer, number, result, _pid} -> 25 schedule_processes(processes, queue, [ {number, result} results]) 26 end 27 end 28 end 7

8 Fibonacci Calculator (V): Main Program to_process = [ 37, 37, 37, 37, 37, 37 ] Enum.each(1..10, fn (num_processes) -> 50 {time, result} = 51 :timer.tc(scheduler, :run, 52 [num_processes, FibSolver, :fib, to_process]) if num_processes == 1 do 55 IO.puts inspect result 56 IO.puts "\n # time (s)" 57 end 58 :io.format "~2B ~.2f~n", [num_processes, time/ ] 59 end) 8

9 Fibonacci Calculator (VI): Results On my 8-core machine, the results are: # time (s) <== almost 4 times as fast <== roughly 3.3 times as fast on average 9

10 Discussion Striking how simple the implementation of the FibSolver Actor is small piece of code with a defined message API program can then spin up as many of these actors as they want The scheduler is more complex BUT it implemented scheduling in a very generic way the function being calculated was completely abstracted away the logic simply took care of doling out work to all ready actors shutting down actors when there was no more work to be done With 11 active actors (10 solvers + 1 scheduler): Elixir has flexibility as to how those actors are distributed across the cores of the machine 10

11 Error Handling and Resilience Actors provide the ability to write fault-tolerant code We can assign a supervisor to a set of actors that detects when an actor has crashed and can do something about it such as restart the actor They way they do this is by linking the actors together (as we saw in Lecture 16) First: Process.flag(:trap_exit, true) Second: pid = spawn_link( ) Third: receive do {:EXIT, pid, reason} We re going to build up an example that demonstrates these concepts 11

12 An Actor to Test Links: LinkTest 1 defmodule LinkTest do 2 def loop do 3 receive do 4 {:exit_because, reason} -> exit(reason) 5 {:link_to, pid} -> Process.link(pid) 6 {:EXIT, pid, reason} -> IO.puts("#{inspect(pid)} exited because #{reason}") 7 end 8 loop 9 end def loop_system do 12 Process.flag(:trap_exit, true) 13 loop 14 end 15 end An actor that can link to other actors via :link_to; otherwise it can be told to die by sending it a :exit_because message If we want to receive :EXIT messages, we need to invoke this actor with the loop_system call. Otherwise, we can just call loop to see what happens when an actor exits for a non :normal reason 12

13 Example: Linked Actors; Non-Normal Exit Create two instances of the actor pid1 = spawn(&linktest.loop/0) pid2 = spawn(&linktest.loop/0) Link them (links are bidirectional) send(pid1, {:link_to, pid2}) Tell one to quit for a non-normal reason (it doesn t matter which actor) send(pid2, {:exit_because, :bad_thing}) The result? BOTH actors die; no :EXIT message received 13

14 Example: Linked Actors; Normal Exit Create two instances of the actor pid1 = spawn(&linktest.loop/0) pid2 = spawn(&linktest.loop/0) Link them (links are bidirectional) send(pid1, {:link_to, pid2}) Tell one to quit for a normal reason (it doesn t matter which actor) send(pid2, {:exit_because, :normal}) The result? Actor 2 dies; Actor 1 lives; still no :EXIT message received 14

15 Example: Linked System Actors; Non-Normal Exit Create two instances of the actor pid1 = spawn(&linktest.loop_system/0) pid2 = spawn(&linktest.loop/0) Link them (links are bidirectional) send(pid1, {:link_to, pid2}) Tell one to quit for a normal reason (it doesn t matter which actor) send(pid2, {:exit_because, :bad_thing}) The result? Actor 2 dies; Actor 1 lives; :EXIT message received and logged 15

16 Creating a Supervisor We now have enough knowledge to create an actor and its supervisor The textbook implements a simple cache actor and a supervisor that can detect when the cache goes down The cache actor can receive a request to store something in the cache receive a request to retrieve something in the cache receive a request to return the size of the cache (in bytes) The supervisor will create a cache actor and monitor its status If it goes down, it will restart the cache 16

17 Cache We can cause this actor to crash by sending nil for page in a :put message 1 defmodule Cache do 2 def loop(pages, size) do 3 receive do 4 {:put, url, page} -> 5 new_pages = Dict.put(pages, url, page) 6 new_size = size + byte_size(page) 7 loop(new_pages, new_size) 8 {:get, sender, ref, url} -> 9 send(sender, {:ok, ref, pages[url]}) 10 loop(pages, size) 11 {:size, sender, ref} -> 12 send(sender, {:ok, ref, size}) 13 loop(pages, size) 14 {:terminate} -> # Terminate request - don't recurse 15 end 16 end 17 end 17

18 Cache Helper Routines def start_link do 19 pid = spawn_link( MODULE, :loop, [HashDict.new, 0]) 20 Process.register(pid, :cache) 21 pid 22 end def put(url, page) do 25 send(:cache, {:put, url, page}) 26 end def get(url) do 29 ref = make_ref() 30 send(:cache, {:get, self(), ref, url}) 31 receive do 32 {:ok, ^ref, page} -> page 33 end 34 end def size do 37 ref = make_ref() 38 send(:cache, {:size, self(), ref}) 39 receive do 40 {:ok, ^ref, s} -> s 41 end 42 end def terminate do 45 send(:cache, {:terminate}) 46 end These functions provide an API to the Cache. We can call them and not worry about starting actors and sending messages. 18

19 Cache Supervisor DEMO 1 defmodule CacheSupervisor do 2 3 def start do 4 spawn( MODULE, :loop_system, []) 5 end 6 7 def loop do 8 pid = Cache.start_link 9 receive do 10 {:EXIT, ^pid, :normal} -> 11 IO.puts("Cache exited normally") 12 :ok 13 {:EXIT, ^pid, reason} -> 14 IO.puts("Cache failed with reason #{inspect reason} - restarting it") 15 loop 16 end 17 end def loop_system do 20 Process.flag(:trap_exit, true) 21 loop 22 end 23 end Start up a Cache. If it crashes, restart it; otherwise quit Make sure we call :trap_exit to receive :EXIT messages 19

20 Discussion (I) This example illustrates a generic approach to concurrent actor systems Keep the supervisors as small and as simple as possible So simple that they are easy to debug and get correct Have the actors that they supervise crash when things go wrong Let the supervisors detect those crashes and decide what to do This approach maximizes simplicity rather than adding lots of error checking code in the workers implement the success case and let all error cases cause a crash that gets handled by the supervisor => a nice separation of concerns 20

21 Discussion (II) This example is so generic that most of the work that we did manually has been implemented in a library called OTP Let s take a look at an OTP version of the Cache and CacheSupervisor A worker will make use of a library known as GenServer It can handle calls and casts the former return a result; the latter do not A supervisor will make use of a library known as Supervisor A supervisor has an init method that specifies a list of workers and a restart strategy We use the :one_for_one strategy to specify that crashed workers should simply be restarted 21

22 New Supervisor 1 defmodule CacheSupervisor do 2 use Supervisor 3 4 def start_link do 5 :supervisor.start_link( MODULE, []) 6 end 7 8 def init(_args) do 9 workers = [worker(cache, [])] 10 supervise(workers, strategy: :one_for_one) 11 end 12 end 22

23 New Cache 1 defmodule Cache do 2 use GenServer 3 4 def handle_cast({:put, url, page}, {pages, size}) do 5 new_pages = Dict.put(pages, url, page) 6 new_size = size + byte_size(page) 7 {:noreply, {new_pages, new_size}} 8 end 9 10 def handle_call({:get, url}, _from, {pages, size}) do 11 {:reply, pages[url], {pages, size}} 12 end def handle_call({:size}, _from, {pages, size}) do 15 {:reply, size, {pages, size}} 16 end end 23

24 Helper Functions for Cache def start_link do 19 :gen_server.start_link({:local, :cache}, MODULE, {HashDict.new, 0}, []) 20 end def put(url, page) do 23 :gen_server.cast(:cache, {:put, url, page}) 24 end def get(url) do 27 :gen_server.call(:cache, {:get, url}) 28 end def size do 31 :gen_server.call(:cache, {:size}) 32 end 33 24

25 Using the new version Start by creating the supervisor (which creates the Cache, its worker) CacheSupervisor.start_link Then just use the Cache Cache.size => 0 Cache.put foo, bar => :ok Cache.size => 3 Cache.put ohnoes, nil => error message; auto restart Cache.size => 0 Just like that, we ve reimplemented the previous example 25

26 Nodes and Distribution The Erlang virtual machine is used to execute Elixir programs In an analogous way that Coljure programs compile down to Java bytecodes and are executed by the Java Virtual Machine One cool feature of Erlang virtual machines is that they have the capability to act as nodes that can form clusters Elixir actors running on one node can easily route messages to actors running on other (possibly) distributed nodes To set this up in Elixir, you can launch iex and give it a node name For security reasons, you also give it a cookie ; only nodes with the same cookie can talk to one another iex --name --cookie jiriki < can be any string 26

27 Connecting Nodes Once you have launched a node, you need to tell it about the other nodes iex --name --cookie jiriki iex --name --cookie jiriki Checking status node1> Node.self => node2> Node.self => Connecting node1> => true Both nodes are now connected to each other node1> Node.list => node2> Node.list => 27

28 Sending Code Between Nodes Let s define a function node1> whoami = fn () -> IO.puts(Node.self) end And send it to another node to be executed node1> whoami) node1 REPL prints: Pause to think about what we just did and how easy it was We just defined a function sent it over to another machine as data that machine converted the data back to a function executed it sent back the result and our original machine then displayed the result 28

29 Sending Messages Between Nodes: Set-Up Let s launch our Counter actor on node2 node2> pid = spawn(counter, :loop, [42]) Now, let s register that process id and associate it with a global name node2> :global.register_name(:counter, pid) => :yes In this context, global means across all connected nodes So, now on node1, we can look that name up node1> pid = :global.whereis_name(:counter) => #PID< > Then we can send messages to it (next slide) 29

30 Sending Messages Between Nodes This version of counter expects a message of the form {:next, <caller_pid>, <unique_ref>} It then sends back a message of the form {:ok, <unique_ref>, count} So, to call this Actor from node1, we do node1> ref = make_ref node1> send(pid, {:next, self, ref}) node1> receive do {:ok, ^ref, count} -> count end Sure enough, we get back the result 42 30

31 Just scratched the surface With these building blocks, you can move on to create full-fledged distributed, concurrent programs Start a bunch of actors on one or more worker machines and register their pids via the :global registry Start a supervisor on another machine and have it dole out work to the actors using a message pattern similar to the Fibonacci example If any of the workers die, have the supervisor restart them automatically I highly recommend the Programming Elixir book if you re curious to see more complicated examples It shows an example that starts a server, has it handle requests, then modifies the code of the server, and HOT SWAPS that code into the running server => modifying servers without having to restart them! 31

32 Summary The Actor model is a powerful model for creating distributed, concurrent systems Any individual actor is a single-threaded program with state that changes in well defined ways Software design becomes message design and system design becomes balancing where actors live and how message load is distributed across them The one danger in Actor systems is deadlock; receive is a blocking call to avoid that, you can have receive timeout and have the Actor do something to recover The OTP library can be used to create Client-Server and Cluster-based applications with a minimal amount of code 32

33 Coming Up Next Lecture 19: Introduction to Software Design Lecture 20: The Design of Design, Part One 33

### The Actor Model. CSCI 5828: Foundations of Software Engineering Lecture 13 10/04/2016

The Actor Model CSCI 5828: Foundations of Software Engineering Lecture 13 10/04/2016 1 Goals Introduce the Actor Model of Concurrency isolation, message passing, message patterns Present examples from

### Favoring Isolated Mutability The Actor Model of Concurrency. CSCI 5828: Foundations of Software Engineering Lecture 24 04/11/2012

Favoring Isolated Mutability The Actor Model of Concurrency CSCI 5828: Foundations of Software Engineering Lecture 24 04/11/2012 1 Goals Review the material in Chapter 8 of the Concurrency textbook that

### Learning from Bad Examples. CSCI 5828: Foundations of Software Engineering Lecture 25 11/18/2014

Learning from Bad Examples CSCI 5828: Foundations of Software Engineering Lecture 25 11/18/2014 1 Goals Demonstrate techniques to design for shared mutability Build on an example where multiple threads

### Macros, and protocols, and metaprogramming - Oh My!

Macros, and protocols, and metaprogramming - Oh My! (aka "What is Elixir and why should you care?") jim mccoy, Facebook Infosec Tools mccoy@fb.com (jim.mccoy@gmail.com) Who? Currently build and maintain

### Erlang. Functional Concurrent Distributed Soft real-time OTP (fault-tolerance, hot code update ) Open. Check the source code of generic behaviours

Lecture 10 Erlang Erlang Functional Concurrent Distributed Soft real-time OTP (fault-tolerance, hot code update ) Open Check the source code of generic behaviours 2 Functional Haskell call-by-need (lazy)

### CPS506 - Comparative Programming Languages Elixir

CPS506 - Comparative Programming Languages Elixir Dr. Dave Mason Department of Computer Science Ryerson University c 2017 Dave Mason History Joe Armstrong worked at Ericson Erlang originally for lab development

### Message-passing concurrency in Erlang

Message-passing concurrency in Erlang Lecture 8 of TDA383/DIT390 (Concurrent Programming) Carlo A. Furia Chalmers University of Technology University of Gothenburg SP3 2016/2017 Today s menu Actors and

### Threads and Locks, Part 2. CSCI 5828: Foundations of Software Engineering Lecture 08 09/18/2014

Threads and Locks, Part 2 CSCI 5828: Foundations of Software Engineering Lecture 08 09/18/2014 1 Goals Cover the material presented in Chapter 2 of our concurrency textbook In particular, selected material

### Design Approaches for Concurrent Systems. CSCI 5828: Foundations of Software Engineering Lecture 08 02/09/2012

Design Approaches for Concurrent Systems CSCI 5828: Foundations of Software Engineering Lecture 08 02/09/2012 1 Goals Discuss material in Chapter 3 of our concurrency textbook Design Approaches for Concurrent

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

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

### Reminder from last time

Concurrent systems Lecture 5: Concurrency without shared data, composite operations and transactions, and serialisability DrRobert N. M. Watson 1 Reminder from last time Liveness properties Deadlock (requirements;

### INTERPRETERS 8. 1 Calculator COMPUTER SCIENCE 61A. November 3, 2016

INTERPRETERS 8 COMPUTER SCIENCE 61A November 3, 2016 1 Calculator We are beginning to dive into the realm of interpreting computer programs that is, writing programs that understand other programs. In

Erlang 101 Google Doc Erlang? with buzzwords Erlang is a functional concurrency-oriented language with extremely low-weight userspace "processes", share-nothing messagepassing semantics, built-in distribution,

### Starting the System & Basic Erlang Exercises

Starting the System & Basic Erlang Exercises These exercises will help you get accustomed with the Erlang development and run time environments. Once you have set up the Erlang mode for emacs, you will

### A Small Web Server. Programming II - Elixir Version. Johan Montelius. Spring Term 2018

A Small Web Server Programming II - Elixir Version Johan Montelius Spring Term 2018 Introduction Your task is to implement a small web server in Elixir. exercise is that you should be able to: The aim

### Grand Central Dispatch and NSOperation. CSCI 5828: Foundations of Software Engineering Lecture 28 12/03/2015

Grand Central Dispatch and NSOperation CSCI 5828: Foundations of Software Engineering Lecture 28 12/03/2015 1 Credit Where Credit Is Due Most of the examples in this lecture were inspired by example code

### WE ARE ALL BLESSED. Bruce Tate

WE ARE ALL BLESSED Bruce Tate Dave Thomas @redrapids @pragdave 1 DAVE'S STORY 2 3 4 https://upload.wikimedia.org/wikipedia/commons/0/0b/hand-operated_card_punch-2.jpg 5 https://upload.wikimedia.org/wikipedia/commons/e/e8/ibm_card_punch_029.jpg

### Elixir and Phoenix fast, concurrent and explicit Tobias pragtob.info

Elixir and Phoenix fast, concurrent and explicit Tobias Pfeiffer @PragTob pragtob.info Elixir and Phoenix fast, concurrent and explicit Tobias Pfeiffer @PragTob pragtob.info Platform defmodule MyMap do

### CS1 Lecture 5 Jan. 26, 2018

CS1 Lecture 5 Jan. 26, 2018 HW1 due Monday, 9:00am. Notes: Do not write all the code at once (for Q1 and 2) before starting to test. Take tiny steps. Write a few lines test... add a line or two test...

### Interpreters and Tail Calls Fall 2017 Discussion 8: November 1, 2017 Solutions. 1 Calculator. calc> (+ 2 2) 4

CS 61A Interpreters and Tail Calls Fall 2017 Discussion 8: November 1, 2017 Solutions 1 Calculator We are beginning to dive into the realm of interpreting computer programs that is, writing programs that

### Elixir and Phoenix fast, concurrent and explicit Tobias pragtob.info

Elixir and Phoenix fast, concurrent and explicit Tobias Pfeiffer @PragTob pragtob.info Elixir and Phoenix fast, concurrent and explicit Tobias Pfeiffer @PragTob pragtob.info Platform defmodule MyMap do

CS 1 Introduction to Computer Programming Lecture 24: December 5, 2012 Advanced topics, part 2 Last time Advanced topics, lecture 1 recursion first-class functions lambda expressions higher-order functions

### SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

SCHEME 7 COMPUTER SCIENCE 61A October 29, 2015 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

### Threads and Locks. CSCI 5828: Foundations of Software Engineering Lecture 09 09/22/2015

Threads and Locks CSCI 5828: Foundations of Software Engineering Lecture 09 09/22/2015 1 Goals Cover the material presented in Chapter 2, Day 1 of our concurrency textbook Creating threads Locks Memory

### Akka: Simpler Concurrency, Scalability & Fault-tolerance through Actors. Jonas Bonér Scalable Solutions

Akka: Simpler Concurrency, Scalability & Fault-tolerance through Actors Jonas Bonér Scalable Solutions jonas@jonasboner.com twitter: @jboner The problem It is way too hard to build: 1. correct highly concurrent

### Introduction to Asynchronous Programming Fall 2014

CS168 Computer Networks Fonseca Introduction to Asynchronous Programming Fall 2014 Contents 1 Introduction 1 2 The Models 1 3 The Motivation 3 4 Event-Driven Programming 4 5 select() to the rescue 5 1

### CSC 2405: Computer Systems II

CSC 2405: Computer Systems II Dr. Mirela Damian http://www.csc.villanova.edu/~mdamian/csc2405/ Spring 2016 Course Goals: Look under the hood Help you learn what happens under the hood of computer systems

### Beautiful Concurrency with Erlang

Beautiful Concurrency with Erlang Kevin Scaldeferri OSCON 23 July 2008 6 years at Yahoo, building large high-concurrency distributed systems Not an expert, don t use it professionally Dabbled, liked it,

### Erlang. Joe Armstrong

Erlang Joe Armstrong Though OOP came from many motivations, two were central. The large scale one was to find a better module scheme for complex systems involving hiding of details, and the small scale

### Week 2: The Clojure Language. Background Basic structure A few of the most useful facilities. A modernized Lisp. An insider's opinion

Week 2: The Clojure Language Background Basic structure A few of the most useful facilities A modernized Lisp Review of Lisp's origins and development Why did Lisp need to be modernized? Relationship to

### Distributed Systems. Lec 10: Distributed File Systems GFS. Slide acks: Sanjay Ghemawat, Howard Gobioff, and Shun-Tak Leung

Distributed Systems Lec 10: Distributed File Systems GFS Slide acks: Sanjay Ghemawat, Howard Gobioff, and Shun-Tak Leung 1 Distributed File Systems NFS AFS GFS Some themes in these classes: Workload-oriented

### S AMPLE CHAPTER. Erlang AND OTP IN ACTION. Martin Logan Eric Merritt Richard Carlsson FOREWORD BY ULF WIGER MANNING

S AMPLE CHAPTER Erlang AND OTP IN ACTION Martin Logan Eric Merritt Richard Carlsson FOREWORD BY ULF WIGER MANNING Erlang and OTP in Action by Martin Logan Eric Merritt Richard Carlsson Chapter 3 Copyright

### A process. the stack

A process Processes Johan Montelius What is a process?... a computation KTH 2017 a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other processes

### COSC441. Lecture 8 Introduction to Erlang

COSC441 Lecture 8 Introduction to Erlang Approach The reference book is Learn You Some Erlang for Great Good! by Fred Hébert. http://learnyousomeerlang.com lets you read it free on-line. What I am going

### simplevisor Documentation

simplevisor Documentation Release 1.2 Massimo Paladin June 27, 2016 Contents 1 Main Features 1 2 Installation 3 3 Configuration 5 4 simplevisor command 9 5 simplevisor-control command 13 6 Supervisor

### Lecture 4, 04/08/2015. Scribed by Eric Lax, Andreas Santucci, Charles Zheng.

CME 323: Distributed Algorithms and Optimization, Spring 2015 http://stanford.edu/~rezab/dao. Instructor: Reza Zadeh, Databricks and Stanford. Lecture 4, 04/08/2015. Scribed by Eric Lax, Andreas Santucci,

### CSE Lecture In Class Example Handout

CSE 30321 Lecture 07-09 In Class Example Handout Part A: A Simple, MIPS-based Procedure: Swap Procedure Example: Let s write the MIPS code for the following statement (and function call): if (A[i] > A

### Functions that return lists

342 Chapter 23 Functions that return lists If you did exercises 22.5.15 or 22.5.16, you ve already written some functions that return lists, but only in a very simple way: adding one new element to the

### 15-122: Principles of Imperative Computation, Fall 2015

15-122 Programming 5 Page 1 of 10 15-122: Principles of Imperative Computation, Fall 2015 Homework 5 Programming: Clac Due: Thursday, October 15, 2015 by 22:00 In this assignment, you will implement a

### STATS Data Analysis using Python. Lecture 8: Hadoop and the mrjob package Some slides adapted from C. Budak

STATS 700-002 Data Analysis using Python Lecture 8: Hadoop and the mrjob package Some slides adapted from C. Budak Recap Previous lecture: Hadoop/MapReduce framework in general Today s lecture: actually

### The Go Programming Language. Frank Roberts

The Go Programming Language Frank Roberts frank.roberts@uky.edu - C++ (1983), Java (1995), Python (1991): not modern - Java is 18 years old; how has computing changed in 10? - multi/many core - web programming

### GFS Overview. Design goals/priorities Design for big-data workloads Huge files, mostly appends, concurrency, huge bandwidth Design for failures

GFS Overview Design goals/priorities Design for big-data workloads Huge files, mostly appends, concurrency, huge bandwidth Design for failures Interface: non-posix New op: record appends (atomicity matters,

Your First Windows Form From now on, we re going to be creating Windows Forms Applications, rather than Console Applications. Windows Forms Applications make use of something called a Form. The Form is

### Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: Processes and Threads

Computer Science 322 Operating Systems Mount Holyoke College Spring 2008 Topic Notes: Processes and Threads What is a process? Our text defines it as an abstraction of a running program. Definitions from

### Chordy: a distributed hash table. Johan Montelius and Vladimir Vlassov. August 29, 2016

Introduction Chordy a distributed hash table Johan Montelius and Vladimir Vlassov August 29, 2016 In this assignment you will implement a distributed hash table following the Chord scheme. In order to

### CS61 Lecture II: Data Representation! with Ruth Fong, Stephen Turban and Evan Gastman! Abstract Machines vs. Real Machines!

CS61 Lecture II: Data Representation with Ruth Fong, Stephen Turban and Evan Gastman Abstract Machines vs. Real Machines Abstract machine refers to the meaning of a program in a high level language (i.e.

### Chapter 1 Getting Started

Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

### CIS 194: Homework 6. Due Monday, February 25. Fibonacci numbers

CIS 194: Homework 6 Due Monday, February 25 Files you should submit: Fibonacci.hs This week we learned about Haskell s lazy evaluation. This homework assignment will focus on one particular consequence

### CSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion

CSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion Review from Lectures 5 & 6 Arrays and pointers, Pointer arithmetic and dereferencing, Types of memory ( automatic, static,

COS 318: Operating Systems Processes and Threads Kai Li and Andy Bavier Computer Science Department Princeton University http://www.cs.princeton.edu/courses/archive/fall13/cos318 Today s Topics u Concurrency

### EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution

1. (40 points) Write the following subroutine in x86 assembly: Recall that: int f(int v1, int v2, int v3) { int x = v1 + v2; urn (x + v3) * (x v3); Subroutine arguments are passed on the stack, and can

### Lesson 4 Transcript: DB2 Architecture

Lesson 4 Transcript: DB2 Architecture Slide 1: Cover Welcome to Lesson 4 of the DB2 on campus series. Today we are going to talk about the DB2 architecture. My name is Raul Chong and I am the DB2 on Campus

### 15 212: Principles of Programming. Some Notes on Continuations

15 212: Principles of Programming Some Notes on Continuations Michael Erdmann Spring 2011 These notes provide a brief introduction to continuations as a programming technique. Continuations have a rich

### Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi.

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 18 Tries Today we are going to be talking about another data

### CIS 194: Homework 6. Due Wednesday, 4 March. Fibonacci numbers. It s all about being lazy.

CIS 194: Homework 6 Due Wednesday, 4 March It s all about being lazy. Fibonacci numbers The Fibonacci numbers F n are defined as the sequence of integers, beginning with 1 and 1, where every integer in

### Two Phase Commit Protocol. Distributed Systems. Remote Procedure Calls (RPC) Network & Distributed Operating Systems. Network OS.

A distributed system is... Distributed Systems "one on which I cannot get any work done because some machine I have never heard of has crashed". Loosely-coupled network connection could be different OSs,

### Replication. Feb 10, 2016 CPSC 416

Replication Feb 10, 2016 CPSC 416 How d we get here? Failures & single systems; fault tolerance techniques added redundancy (ECC memory, RAID, etc.) Conceptually, ECC & RAID both put a master in front

### CS 153 Design of Operating Systems Winter 2016

CS 153 Design of Operating Systems Winter 2016 Lecture 17: Paging Lecture Overview Recap: Today: Goal of virtual memory management: map 2^32 byte address space to physical memory Internal fragmentation

### GUI ScreenIO Client/Server Layer Job Timeout Facility

Client/Server Layer Job Timeout Facility T he Server daemon supports idle job termination; the ability of the server to terminate jobs after a configurable period of user inactivity. This document explains

### Background. Let s see what we prescribed.

Background Patient B s custom application had slowed down as their data grew. They d tried several different relief efforts over time, but performance issues kept popping up especially deadlocks. They

### W4118 Operating Systems. Junfeng Yang

W4118 Operating Systems Junfeng Yang What is a process? Outline Process dispatching Common process operations Inter-process Communication What is a process Program in execution virtual CPU Process: an

### Parallel Programming: Background Information

1 Parallel Programming: Background Information Mike Bailey mjb@cs.oregonstate.edu parallel.background.pptx Three Reasons to Study Parallel Programming 2 1. Increase performance: do more work in the same

### Compilers and computer architecture: A realistic compiler to MIPS

1 / 1 Compilers and computer architecture: A realistic compiler to MIPS Martin Berger November 2017 Recall the function of compilers 2 / 1 3 / 1 Recall the structure of compilers Source program Lexical

### Exam Questions 1Z0-895

Exam Questions 1Z0-895 Java Platform, Enterprise Edition 6 Enterprise JavaBeans Developer Certified Expert Exam https://www.2passeasy.com/dumps/1z0-895/ QUESTION NO: 1 A developer needs to deliver a large-scale

### G52CON: Concepts of Concurrency

G52CON: Concepts of Concurrency Lecture 11: Semaphores I" Brian Logan School of Computer Science bsl@cs.nott.ac.uk Outline of this lecture" problems with Peterson s algorithm semaphores implementing semaphores

### CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 4 C Pointers 2004-09-08 Lecturer PSOE Dan Garcia www.cs.berkeley.edu/~ddgarcia Cal flies over Air Force We re ranked 13 th in the US and

### Chapter 7:: Data Types. Mid-Term Test. Mid-Term Test (cont.) Administrative Notes

Chapter 7:: Data Types Programming Language Pragmatics Michael L. Scott Administrative Notes Mid-Term Test Thursday, July 27 2006 at 11:30am No lecture before or after the mid-term test You are responsible

### CS321 Languages and Compiler Design I. Winter 2012 Lecture 2

CS321 Languages and Compiler Design I Winter 2012 Lecture 2 1 A (RE-)INTRODUCTION TO JAVA FOR C++/C PROGRAMMERS Why Java? Developed by Sun Microsystems (now Oracle) beginning in 1995. Conceived as a better,

### Erlang. An introduction. Paolo Baldan Linguaggi e Modelli per il Global Computing AA 2016/2017

Erlang An introduction Paolo Baldan Linguaggi e Modelli per il Global Computing AA 2016/2017 Erlang, in a slogan Declarative (functional) language for concurrent and distributed systems Erlang = Functions

### If Statements, For Loops, Functions

Fundamentals of Programming If Statements, For Loops, Functions Table of Contents Hello World Types of Variables Integers and Floats String Boolean Relational Operators Lists Conditionals If and Else Statements

### Project 2: Part 1: RPC and Locks

Project 2: Part 1: RPC and Locks Due: 11:59PM Thursday, October 14, 2010 1 Introduction In this series of labs, you will implement a fully functional distributed file server with the Frangipani architecture

### Functions and Decomposition

Unit 4 Functions and Decomposition Learning Outcomes Design and implement functions to carry out a particular task. Begin to evaluate when it is necessary to split some work into functions. Locate the

### Recursion(int day){return Recursion(day += 1);} Comp Sci 1575 Data Structures. Recursive design. Convert loops to recursion

Recursion(int day){return Recursion(day += 1);} Comp Sci 1575 Data Structures Outline 1 2 Solution 2: calls 3 Implementation To create recursion, you must create recursion. How to a recursive algorithm

### Administrivia. Minute Essay From 4/11

Administrivia All homeworks graded. If you missed one, I m willing to accept it for partial credit (provided of course that you haven t looked at a sample solution!) through next Wednesday. I will grade

### Embedded Elixir. Elixir Taiwan Meetup July 25, 2016 Jake Morrison

Embedded Elixir Elixir Taiwan Meetup July 25, 2016 Jake Morrison What is Embedded Programming? Systems that interact with the physical world Resource constrained systems Machines controlled

### CSE 410 Final Exam 6/09/09. Suppose we have a memory and a direct-mapped cache with the following characteristics.

Question 1. (10 points) (Caches) Suppose we have a memory and a direct-mapped cache with the following characteristics. Memory is byte addressable Memory addresses are 16 bits (i.e., the total memory size

### GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial

A Walkthrough with Examples CMSC 212 - Spring 2009 Last modified March 22, 2009 What is gdb? GNU Debugger A debugger for several languages, including C and C++ It allows you to inspect what the program

### COSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26

COSC 2P95 Procedural Abstraction Week 3 Brock University Brock University (Week 3) Procedural Abstraction 1 / 26 Procedural Abstraction We ve already discussed how to arrange complex sets of actions (e.g.

### Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

CSC400 - Operating Systems 3. Process Concepts J. Sumey Overview Concurrency Processes & Process States Process Accounting Interrupts & Interrupt Processing Interprocess Communication CSC400 - Process

### Excerpt from "Art of Problem Solving Volume 1: the Basics" 2014 AoPS Inc.

Chapter 5 Using the Integers In spite of their being a rather restricted class of numbers, the integers have a lot of interesting properties and uses. Math which involves the properties of integers is

### CMSC 621 Case Study on Programming Languages

CMSC 621 Case Study on Programming Languages Naveen Bansal, Vineet Ahirkar, Shantanu Hirlekar Department of Computer Science and Electrical Engineering University of Maryland Baltimore County Maryland,

### Programming Assignment #4 Writing a simple parallel port device driver

Programming Assignment #4 Writing a simple parallel port device driver Value: (See the Grading section of the Syllabus.) Due Date and Time: (See the Course Calendar.) Summary: This is your second exercise

### CSE Lecture In Class Example Handout

CSE 30321 Lecture 07-08 In Class Example Handout Part A: J-Type Example: If you look in your book at the syntax for j (an unconditional jump instruction), you see something like: e.g. j addr would seemingly

### Intro. Scheme Basics. scm> 5 5. scm>

Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

### More C Pointer Dangers

CS61C L04 Introduction to C (pt 2) (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Must-see talk Thu 4-5pm @ Sibley by Turing Award winner Fran Allen: The Challenge of Multi-Cores: Think Sequential,

### Elixir and Phoenix. fast, concurrent and explicit. Tobias pragtob.info

Elixir and Phoenix fast, concurrent and explicit Tobias Pfeiffer @PragTob pragtob.info Elixir and Phoenix fast, concurrent and explicit Tobias Pfeiffer @PragTob pragtob.info defmodule MyMap do def map([],

### Term Definition Introduced in: This option, located within the View tab, provides a variety of options to choose when sorting and grouping Arrangement

60 Minutes of Outlook Secrets Term Definition Introduced in: This option, located within the View tab, provides a variety of options to choose when sorting and grouping Arrangement messages. Module 2 Assign

### ClearSpeed Visual Profiler

ClearSpeed Visual Profiler Copyright 2007 ClearSpeed Technology plc. All rights reserved. 12 November 2007 www.clearspeed.com 1 Profiling Application Code Why use a profiler? Program analysis tools are

### <Urban.Boquist. com> Rev PA

FP in industry - Erlang Urban Boquist Ericsson AB com> 1 Outline Who Am I Mobile Telecommunications Networks Packet Core Network GPRS & SGSN Use of Erlang in SGSN SGSN Design

### 6.001 Recitation 23: Register Machines and Stack Frames

6.001 Recitation 23: Register achines and Stack Frames RI: Gerald Dalley, dalleyg@mit.edu, 8 ay 2007 http://people.csail.mit.edu/dalleyg/6.001/sp2007/ iscellany apply: See the IT Scheme documentation for

### COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2016

COMP-202: Foundations of Programming Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2016 Learn about cutting-edge research over lunch with cool profs January 18-22, 2015 11:30

CS/Math 40: Introduction to Discrete Mathematics Fall 015 Instructors: Beck Hasti, Gautam Prakriya Reading 8 : Recursion 8.1 Recursion Recursion in computer science and mathematics refers to the idea of

### Blackfin Online Learning & Development

Presentation Title: Multimedia Starter Kit Presenter Name: George Stephan Chapter 1: Introduction Sub-chapter 1a: Overview Chapter 2: Blackfin Starter Kits Sub-chapter 2a: What is a Starter Kit? Sub-chapter

### My malloc: mylloc and mhysa. Johan Montelius HT2016

1 Introduction My malloc: mylloc and mhysa Johan Montelius HT2016 So this is an experiment where we will implement our own malloc. We will not implement the world s fastest allocator, but it will work

### Web Client And Server

Web Client And Server Project Part A Overview In this part of the project, you and your partner will build a simple web client and a succession of servers to which it can connect. The goal is to slowly

### Distributed Systems Theory 4. Remote Procedure Call. October 17, 2008

Distributed Systems Theory 4. Remote Procedure Call October 17, 2008 Client-server model vs. RPC Client-server: building everything around I/O all communication built in send/receive distributed computing

### Look at all these toys!

Look at all these toys! Help it s Ruby! All alone Is Ruby dying? Where do Rubyists go? Where do Rubyists go? Tobias Pfeiffer @PragTob pragtob.info 673 Responses First Rails Release Rails 1.0 Why did

### Lecture 19: Signatures, Structures, and Type Abstraction

15-150 Lecture 19: Signatures, Structures, and Type Abstraction Lecture by Dan Licata March 27, 2012 In these lectures, we will discuss the use of the ML module system for structuring large programs. Key