An introduction to Erlang & Elixir. Meetup October 28, Organized by Jean-François Cloutier Held at The Casco Bay Technology Hub, Portland, ME
|
|
- Karin McDonald
- 6 years ago
- Views:
Transcription
1 An introduction to Erlang Elixir Meetup October 28, 2014 Organized by Jean-François Cloutier Held at The Casco Bay Technology Hub, Portland, ME
2 Agenda Welcome! Why Erlang? Why Elixir? Getting Started Next Meetups 2
3 Why Erlang? 3
4 Telecom Web-scale apps 80s 90s telecom problems today's web-scale apps problems Scalability Ericsson AXD310 switch Vertical and horizontal High availability Fault tolerance Hot code updates Soft real-time Distribution System integration Erlang/OTP was developed at Ericsson Computer Science Laboratory By Joe Armstrong, Robert Virding, Mike Williams, Claes Wikstrom et al. 4
5 Erlang Needed to Solve Hard Telecom Problems 1980s Experimentations with 20+ languages Erlang is created based on Prolog, Lisp, Smalltalk 1990s Erlang released and used on projects BEAM Virtual Machine (Lightweight processes, scheduling...) OTP (Erlang's application framework, design principles,...) Massive telecom applications Open sourced Erlang User Conferences 2000s Multicore support added Good books (finally) 2010s Elixir developed (among other BEAM languages) By Ruby enthusiasts who want it all (productivity AND performance) Cleaner syntax, easy meta-programming 5
6 Nothing Succeeds Like Success From Wikipedia: In 1998 Ericsson announced the AXD301 switch, containing over a million lines of Erlang and reported to achieve a reliability of nine "9"s. Shortly thereafter, Ericsson Radio Systems banned the in-house use of Erlang for new products, citing a preference for non-proprietary languages. The ban caused Armstrong and others to leave Ericsson. The implementation was open-sourced at the end of the year. Ericsson eventually lifted the ban; it re-hired Armstrong in Lessons: Erlang/OTP brilliantly fulfilled extremely difficult requirements Overwhelming success won't shield you from clueless management 6
7 Erlang/OTP Erlang is a process-oriented language The world is concurrent and parallel, not object-oriented No shared states, only inherently fallible (distributed) messaging Functional immutability and transformations, vs. state mutations BEAM VM light-weight processes, multicore scheduling, process GC... OTP = Open Telecom Platform NOT telecom-specific! Concurrency design patterns Generic, extendable, message-oriented, server processes Supervisor trees for reliability Application and release packaging 7
8 Success Stories WhatsApp 500M users 32 engineers $19B acquisition Sqor 2 nd fastest growing US startup Basho's Riak NoSQL data store Replaced Oracle in England's NHS patient info and messaging infrastructure 50%+ of all cell data traffic worldwide Goes through an Erlang-coded switch EJabberd (XMPP), RabbitMQ (MOM), Heroku (Cloud hosting)... 8
9 Scalable Web Servers Clojure! synrc.com/apps/n2o/ Erlang-based Web servers are fast and they don't choke. 9
10 The Erlang/OTP System shop.oreilly.com/product/ do 10
11 Processes everywhere Function learnyousomeerlang.com Linked processes Monitored processes krondo.com Many, many, MANY processes (and nothing but) erlang.org Async (remote) messages No delivery guarantees whatsoever Messages queued in process mailboxes 11
12 Processes and State Variables are immutable Processes maintain and alter their state By executing tail-recursive functions with parameters (different parameters = new state) Processes don't share their state No shared memory Each process is GCed individually Processes only interact via async messages Processes send and receive messages Messages are self-contained and immutable A process can block on a receive Sync message = async send then block on receiving async reply message module(process_state). export([loop/2]). loop(n, Client) > loop(client, N, 0, []). loop(client, N, Count, Msgs) when Count < N > receive Msg > loop(client, N, Count+1, [Msg Msgs]) end; loop(client, _, Count, Msgs) > Log = lists:reverse(msgs), io:format("received ~p messages~n", [Count]), Client! {ok, Log}. 1> Pid = spawn(process_state, loop, [3, self()]). 2> Pid! "Hello". 3> Pid! 3. 4> Pid! bye. 5> flush(). Function definition rpc(pid, Request) > Pid! {self(), Request}, receive {Pid, Response} > Response end. Function executed in a process 12
13 Reliable systems are supervised Processes can supervise other processes Via monitoring Across redundant nodes Supervisors detect abnormal termination of supervised processes They then apply a number of restart strategies Supervisors can be supervised Supervisor trees Failure (and restarts) can roll up shop.oreilly.com/product/ do 90% of bugs in production are transient (Heisenbugs) Restarting is generally the most effective strategy Process failure should not contaminate the state of other processes Supervisors restart failed processes and their dependents Let It Crash! No defensive programming gar1t.com 13
14 Live Code Upgrades Erlang modules have versions Erlang can load a new module version (current) while the previous (old) is being executed When a module function is called (and the call is qualified with the module name), the new version is used (Of course, hot-upgrading a complex system is rarely this simple) module(m). export([loop/0]). loop() > receive code_switch > m:loop(); Msg > loop() end. 1> Pid = spawn(m, loop, []). Modify module m... 2> c(m). 3> Pid! code_switch. 14
15 OTP Servers Generic behaviours implemented with TBD specific extensions gen_server: basic client-serving process gen_fsm: finite-state machine process gen_event: event manager process supervisor: process manager process application: service wrapper process (start, stop) Extensively field-tested Robust - take care of corner cases, avoidable race conditions etc. OTP standardizes application coding 15
16 gen_server Functions called by client process module(mygenserver). behaviour(gen_server). export([init/1, handle_call/3, handle_cast/2, terminate/2]). export([start_link/0, sync_incr/0, async_incr/0, get_value/0, stop/0]). %% API %% start_link() > gen_server:start_link({local,?module},?module, 0, []). sync_incr() > gen_server:call(?module, incr). 20bits.com Functions called by gen_server process async_incr() > gen_server:cast(?module, incr). get_value() > gen_server:call(?module, get_value). stop() > gen_server:cast(?module, stop). %% CALLBACKS %% init(n) > State = N, {ok, State}. handle_call(get_value, _From, State) > {reply, State, State}; handle_call(incr, _From, State) > {reply, State, State + 1}. handle_cast(incr, State) > {noreply, State + 1}; handle_cast(stop, State) > {stop, normal, State}. terminate(normal, _State) > ok. Inter-process messages 16
17 ( Don't care for the Erlang syntax? Many like it just fine (I do) but others are turned off by it Parlez-vous Prolog? Elixir to the rescue! A BEAM language designed by Ruby enthusiasts with a strong aesthetic sense Full access to Erlang/OTP libraries PLUS... Easy meta-programming put to great use Lots of other goodies Pipelines (to express chained transformations the way they should be) Protocols (for polymorphism) Streams (for lazy enumeration) Tasks and Agents (to simplify concurrent programming) And more Do code in Elixir but make sure you know how to at least read Erlang 17
18 This is how good Elixir feels ) defmodule CheckDigit do Module import Enum """ Determine if a sequence of digits is valid, assuming the last digit is a Luhn checksum. ( iex> CheckDigit.valid? ' ' true """ def valid?(numbers) when is_list(numbers) do numbers > reverse > map((1?0)) Pipeline! > add_all > rem(10) == 0 end defp add_all(digits), do: _sum(digits, 0) Private functions Public function defp _sum([], sum), do: sum defp _sum([odd], sum), do: sum + odd defp _sum([odd, even tail], sum) when even < 5 do _sum(tail, sum + odd + even*2) end defp _sum([odd, even tail], sum) do _sum(tail, sum + odd + even*2 9) end end 18
19 gen_fsm (Back to Erlang) module(code_lock). behaviour(gen_fsm). export([start_link/1]). export([button/1]). export([init/1, locked/2, open/2]). Called by FSM clients start_link(code) > gen_fsm:start_link({local, code_lock}, code_lock, lists:reverse(code), []). button(digit) > gen_fsm:send_event(code_lock, {button, Digit}). init(code) > {ok, locked, {[], Code}}. Called by gen_fsm process locked({button, Digit}, {SoFar, Code}) > case [Digit SoFar] of Code > io:format("unlocked!~n"), {next_state, open, {[], Code}, 5000}; Incomplete when length(incomplete)<length(code) > {next_state, locked, {Incomplete, Code}}; _Wrong > {next_state, locked, {[], Code}} end. Inter-process messages theburningmonk.com open(timeout, State) > io:format("locked~n"), {next_state, locked, State}. 19
20 gen_event module(file_logger). behaviour(gen_event). Event handlers export([init/1, handle_event/2, terminate/2]). init([file]) > {ok, Fd} = file:open(file, [read,write]), {ok, Fd}. module(terminal_logger). behaviour(gen_event). export([init/1, handle_event/2, terminate/2]). init(_args) > {ok, []}. learnyousomeerlang.com handle_event(errormsg, State) > io:format("***error*** ~p~n", [ErrorMsg]), {ok, State}. handle_event(errormsg, Fd) > io:format(fd, "***Error*** ~p~n", [ErrorMsg]), {ok, Fd}. terminate(_args, Fd) > file:close(fd). 1> gen_event:start({local, error_man}). 2> gen_event:add_handler(error_man, terminal_logger, []). 3> gen_event:add_handler(error_man, file_logger, [ events.log ]). 4> gen_event:notify(error_man, no_reply). terminate(_args, _State) > ok. 20
21 supervisor module(ch_sup). behaviour(supervisor). export([start_link/0]). export([init/1]). start_link() > supervisor:start_link(ch_sup, []). Child restart strategy init(_args) > {ok, {{one_for_one, 1, 60}, [{ch3, {ch3, start_link, []}, permanent, brutal_kill, worker, [ch3]}]}}. Children specs learnyousomeerlang.com 21
22 application learnyousomeerlang.com Application callback module module(ch_app). behaviour(application). export([start/2, stop/1]). start(_type, _Args) > ch_sup:start_link(). stop(_state) > ok. Starts top supervisor Application resource file {application, ch_app, [{description, "Channel allocator"}, {vsn, "1"}, {modules, [ch_app, ch_sup, ch3]}, {registered, [ch3]}, {applications, [kernel, stdlib, sasl]}, {mod, {ch_app,[]}} ]}. 22
23 Erlang, the language Few data types Functions as data type Erlang is a concurrent FP language Pattern Matching Classification, extraction and construction all in one Modules Units of compilation, loading and upgrade Distributed processes Simple but not simplistic 23
24 Erlang Data Data Types Atoms, integers, floats, functions, PIDs, refs, ports... Data Structures Tuples Records (fixed-sized tuples with named element positions) Maps Lists String are lists of character integer codes (ugh?) Binaries 1> Squared = fun(x) > X*X end. #Fun<erl_eval > 2> Pid = spawn(fun() > apply(squared, [3]) end). <0.60.0> Tuple = { Allagash Curieux, 9, JF }. rd(beer_rating, { beer, rating=5, taster }). Record = #beer_rating{beer= Allagash Curieux, rating=9, taster= JF }. Taster = Rating#beer_rating.taster. Map = #{"k1" => 1, "k2" => 2}. NewMap = Map#{ k2 := 22, k3 => 3}. List = [72,101,108,108,111]. Hello == List. [1,2,3] == [1 [2 [3 [] ] ] ]. Binary = <<213,45,132,64,76,32,76,0,0>>. <<Pix1:24, Pix2:24, Pix3:24>> = Pixels. 24
25 Functions Erlang programs = functions contained in modules Multiple heads (built-in Case logic) Anonymous functions are closures Functions can operate on functions Comprehensions module(my_math). export([fact/1]). fact(n) when N>0 > % first clause head N * fact(n 1); % first clause body fact(0) > 1. my_math:fact(3). 6 N = 2. F = fun(x) > X*N end. lists:map(f,[1,2,3,4,5]). [2,4,6,8,10] % second clause head L = [1,2,a,3,b]. [{X,Y} X < L, integer(x), Y < L, atom(y)]. [{1,a},{1,b},{2,a},{2,b},{3,a},{3,b}] Processes are concurrent function executions Pid = spawn(fun() > X = my_math:fact(3), io:format("result: ~p~n",[x]) end). Result: 6 <0.95.0> 25
26 Matching = Swiss Army Knife Extraction Taking things apart 1> {"Miller Lite", Rating, _ } = {"Miller Lite", 1, "JF"}. {"Miller Lite",1,"JF"} 2> Rating. 1 Classification Does it match? 1> [A, B Rest] = [1, 2]. [1,2] 2> [A, B, C Rest] = [1, 2]. ** exception error: no match of right hand side value [1,2] reverse([]) > []; reverse([h T]) > reverse(t) ++ [H]. Function body selected by matching heads in order Construction Putting things together 1> List = [2,3,4]. [2,3,4] 2> NewList = [1 List]. [1,2,3,4] 26
27 Modules Modules group functions and record definitions One module per file of same name (.erl) Modules export public functions They also import functions from other modules Modules are the unit of compilation, loading and live upgrade %%% An echo server. It works fine as long as you don't %%% interrupt it. If you interrupt it, it doesn't release the %%% socket, so there's some more work to do. module(echo). export([start/1,server/1,handle_messages/1]). start(port) > spawn(?module,server,[port]). server(port) > {ok, Socket} = gen_tcp:listen(port,[{packet,line}]), listen(socket). listen(socket) > {ok, Active_socket} = gen_tcp:accept(socket), Handler = spawn(?module,handle_messages,[active_socket]), ok = gen_tcp:controlling_process(active_socket, Handler), listen(socket). handle_messages(socket) > receive {tcp,error,closed} > done; {tcp,socket,data} > gen_tcp:send(socket,data), echo:handle_messages(socket); _Other > unexpected end. 27
28 Node: dilbert Node: pointy P O R T L A N D Distributed Erlang Erlang node = a BEAM running under a name Nodes connect securely to each other If same cookie (transmitted in the clear) jf@ukemi:~$ erl sname dilbert... (dilbert@ukemi)1> node(). dilbert@ukemi (dilbert@ukemi)2> nodes(). [pointy@ukemi] (dilbert@ukemi)3> register(shell, self()). true (dilbert@ukemi)4> receive {hello, from, Pid} > Pid! {hey, from, self()} end. {hey,from,<0.38.0>} Initiated via a ping Assumes secure intranet Processes can be spawned on other nodes Messages can be sent across nodes 2 4 jf@ukemi:~$ erl sname pointy... (pointy@ukemi)1> node(). pointy@ukemi (pointy@ukemi)2> net_kernel:connect_node(dilbert@ukemi). true (pointy@ukemi)3> nodes(). [dilbert@ukemi] (pointy@ukemi)4> {shell, dilbert@ukemi}! {hello, from, self()}. {hello,from,<0.40.0>} And replies transmitted back, of course 5 (pointy@ukemi)5> flush(). Shell got {hey,from,< >} ok 28
29 Why Erlang/OTP matters BEAM VM Myriad of ultra-light-weight processes are a more direct representation of our concurrent world No shared state, data immutability => reliability and efficient memory usage Scales vertically: Excellent use of computing resources on multicore systems Scales horizontally: Processes can be distributed across nodes OTP Meant for highly-available server apps Proven, soft-real-time server architecture that scales way up Developers code the application-specific APIs and callbacks Functional High productivity (fewer lines of code that do more) Computation as chained transformations on immutable data vs class hierarchies that specify how to encapsulate state within behavior 29
30 Why Elixir? 30
31 Because... Elixir is a modern, functional programming language designed for high availability and concurrency. It has Ruby-like syntax married to the power and reliability of the Erlang VM. If you wanted to get into functional programming but were put off by the academic feel, now s the time to jump in. Dave Thomas Plus Elixir gives direct access to all of OTP and all Erlang libraries. 31
32 Same semantics, different feel Erlang Elixir module(hello_module). export([some_fun/0, some_fun/1]). % A "Hello world" function some_fun() > io:format('~s~n', ['Hello world!']). % This one works only with lists some_fun(list) when is_list(list) > io:format('~s~n', List). % Non exported functions are private priv() > secret_info. defmodule HelloModule do # A "Hello world" function def some_fun do IO.puts "Hello world!" end # This one works only with lists def some_fun(list) when is_list(list) do IO.inspect list end # A private function defp priv do :secret_info end end 32
33 Tasty Elixir nuggets Streams in a pipeline iex> _000 > Stream.map((1 * 3)) > Stream.filter((rem(1,2))==0) > Enum.sum iex> for <<c < " hello world ">>, c!=?\s, into: "", do: <<c>> "helloworld" iex> {:ok, agent} = Agent.start_link fn > [] end {:ok, #PID<0.57.0>} iex> Agent.update(agent, fn list > ["eggs" list] end) :ok iex> Agent.get(agent, fn list > list end) ["eggs"] iex> Agent.stop(agent) Transforming a binary using a comprehension Agents are stateful processes with a simple update/get API iex> worker = Task.async(Fib, :of, [20]) iex> result = Task.await(worker) iex> IO.puts "The result is #{result}" Tasks are simple stateless processes for sync or async concurrent execution 33
34 More Elixir fun: map-reduce defmodule Parallel do def pmap(collection, fun) do me = self collection > Enum.map(fn (elem) > spawn_link fn > (me < { self, fun.(elem) }) end end) > Enum.map(fn (pid) > receive do { ^pid, result } > result end end) end end Applying a function to a each elements of a list concurrently Collecting the results, preserving order iex> c parallel.ex iex> Parallel.pmap , (1 * 1) Yes, 1 million processes executed in just a few seconds 34
35 Getting Started 35
36 Inspirational videos Erlang: The Movie Erlang The Movie II: The Sequel 36
37 Recommended resources 37
38 Next Meetups 38
39 Ideas for future topics The Joy of Elixir Elixir tools and development workflow Focus on functional programming OTP design principles Extending Elixir with Macros and Protocols Erlang/Elixir Web Frameworks (WebMachine, Phoenix) Erlang databases (DETS, Mnesia, Riak) Elixir apps in the cloud Debugging OTP applications Show and tells? 39
40 Thanks all! See you in a month. 40
Erlang 101. Google Doc
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,
More informationMacros, 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
More informationOrganized by Jean-François Cloutier Held at Big Room Studios, Portland, ME. Holy Elixir, Batman! Meetup June 16, 2015
Organized by Jean-François Cloutier Held at Big Room Studios, Portland, ME Holy Elixir, Batman! Meetup June 16, 2015 A Sampling of Elixir's Superhero Powers Second Order Functions Pipes Pattern Matching
More informationOTP Design Principles. version 5.6
version 5.6 Typeset in L A TEX from SGML source using the DocBuilder-0.9.7 Document System. Contents 1 1 1.1 Overview........................................... 1 1.1.1 Supervision Trees...................................
More informationProgramming Language Impact on the Development of Distributed Systems
Programming Language Impact on the Development of Distributed Systems Steve Vinoski Architect, Basho Technologies Cambridge, MA USA vinoski@ieee.org @stevevinoski http://steve.vinoski.net/ Co-Authors Debasish
More informationThe Actor Model, Part Two. CSCI 5828: Foundations of Software Engineering Lecture 18 10/23/2014
The Actor Model, Part Two CSCI 5828: Foundations of Software Engineering Lecture 18 10/23/2014 1 Goals Cover the material presented in Chapter 5, of our concurrency textbook In particular, the material
More informationErlang. Joe Armstrong.
Erlang Joe Armstrong joe.armstrong@ericsson.com 1 Who is Joe? Inventor of Erlang, UBF, Open Floppy Grid Chief designer of OTP Founder of the company Bluetail Currently Software Architect Ericsson Current
More informationErlang. 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
More informationErlang: distributed programming
Erlang: distributed May 11, 2012 1 / 21 Fault tolerance in Erlang links, exit signals, system process in Erlang OTP Open Telecom Platform 2 / 21 General idea Links Exit signals System processes Summary
More informationErlang. Functional Concurrent Distributed Soft real-time OTP (fault-tolerance, hot code update ) Open. Check the source code of generic behaviours
Lecture 9 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)
More informationFRANCESCO CESARINI. presents ERLANG/OTP. Francesco Cesarini Erlang
FRANCESCO CESARINI presents Francesco Cesarini Erlang Solutions ERLANG/OTP @FrancescoC francesco@erlang-solutions.com www.erlang-solutions.com WHAT IS SCALABILITY? WHAT IS (MASSIVE) CONCURRENCY? WHAT
More informationRobust Erlang (PFP Lecture 11) John Hughes
Robust Erlang (PFP Lecture 11) John Hughes Genesis of Erlang Problem: telephony systems in the late 1980s Digital More and more complex Highly concurrent Hard to get right Approach: a group at Ericsson
More informationCPS506 - 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
More informationconcurrent programming XXL
concurrent programming XXL Industrial Use of Erlang Introduction Karol Ostrovský (karol.ostrovsky@gmail.com) Motivation Machine Ericsson Blade System 3 sub-racks 14 blades 2 routers 12 compute nodes 6
More informationErlang. 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)
More informationWE 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
More informationAn Introduction to Erlang
Erlang Solutions Ltd An Introduction to Erlang From behind the trenches GOTO Amsterdam Amsterdam, May 25 th 2012 Francesco Cesarini Founder, Technical Director @FrancescoC francesco@erlang-solutions.com
More informationThe 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
More informationPhoenix Is Not Your Application. Lance Halvorsen ElixirConf EU 2016
Phoenix Is Not Your Application Lance Halvorsen ElixirConf EU 2016 Phoenix is one of your applications. Our Language Gives Us Away We Say I'm building a Phoenix app. Or a Rails app. Or an Ember app. Or
More informationErlang and Concurrency. André Pang Rising Sun Research
Erlang and Concurrency André Pang Rising Sun Research Games. Unreal 3 engine. Amazing graphics. (Unreal 3 video demo.) 2004/2005? Still state-of-the-art. What does that game have to do with this talk?
More informationImplementing Riak in Erlang: Benefits and Challenges
Implementing Riak in Erlang: Benefits and Challenges Steve Vinoski Basho Technologies Cambridge, MA USA http://basho.com @stevevinoski vinoski@ieee.org http://steve.vinoski.net/ Erlang Erlang Started in
More informationDISTRIBUTED SYSTEMS [COMP9243] Lecture 1.5: Erlang INTRODUCTION TO ERLANG BASICS: SEQUENTIAL PROGRAMMING 2. Slide 1
DISTRIBUTED SYSTEMS [COMP9243] THE ERLANG ENVIRONMENT Slide 1 Lecture 1.5: Erlang ➀ Introduction ➁ Basics: Sequential programming ➂ Concurrent programming Slide 3 unix% erl 1> 1 + 2. 3 2> c(demo). {ok,demo}
More informationLFE - a lisp on the Erlang VM
Robert Virding Principle Language Expert at Erlang Solutions Ltd. LFE - a lisp on the Erlang VM What LFE isn t It isn t an implementation of Scheme It isn t an implementation of Common Lisp It isn t an
More informationProgramming Paradigms
PP 2017/18 Unit 15 Concurrent Programming with Erlang 1/32 Programming Paradigms Unit 15 Concurrent Programming with Erlang J. Gamper Free University of Bozen-Bolzano Faculty of Computer Science IDSE PP
More informationAn Introduction to Erlang
An Introduction to Erlang Part 2 - Concurrency Richard Carlsson Processes P1 fib(0) -> 1; fib(1) -> 1; fib(n) when N > 0 -> fib(n-1) + fib(n-2). Whenever an Erlang program is running, the code is executed
More informationKent Academic Repository
Kent Academic Repository Full text document (pdf) Citation for published version Cesarini, Francesco and Thompson, Simon (2010) Erlang Behaviours: Programming With Process Design Patterns. In: Central
More informationErlang: An Overview. Part 2 Concurrency and Distribution. Thanks to Richard Carlsson for most of the slides in this part
Erlang: An Overview Part 2 Concurrency and Distribution Thanks to Richard Carlsson for most of the slides in this part Processes P1 fib(0) -> 1; fib(1) -> 1; fib(n) when N > 0 -> fib(n-1) + fib(n-2). Whenever
More informationAn Introduction to Erlang
Erlang Solutions Ltd An Introduction to Erlang From behind the trenches Erlang Factory Lite Zurich, April 23 rd 2012 Francesco Cesarini Founder, Technical Director @FrancescoC francesco@erlang-solutions.com
More informationMessage-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
More informationERLANG EVOLVES FOR MULTI-CORE AND CLOUD ENVIRONMENTS
ERLANG EVOLVES FOR MULTI-CORE AND CLOUD ENVIRONMENTS Torben Hoffmann Erlang Solutions Ltd. @LeHoff http://musings-of-an-erlang-priest.blogspot.dk/ 1 Agenda Erlang fundamentals Challenges 2 2 Warning 1:
More informationScripting with Luerl
Scripting with Luerl Luerl Luerl is an implementation of standard Lua written in Erlang/OTP. Lua is a powerful, efficient, lightweight, embeddable scripting language common in games, machine learning,
More informationAll you need is fun. Cons T Åhs Keeper of The Code
All you need is fun Cons T Åhs Keeper of The Code cons@klarna.com Cons T Åhs Keeper of The Code at klarna Architecture - The Big Picture Development - getting ideas to work Code Quality - care about the
More informationThe do s and don ts of error handling. Joe Armstrong
The do s and don ts of error handling Joe Armstrong A system is fault tolerant if it continues working even if something is wrong Work like this is never finished it s always in-progress Hardware can fail
More informationIntroduction to Erlang. Franck Petit / Sebastien Tixeuil
Introduction to Erlang Franck Petit / Sebastien Tixeuil Firstname.Lastname@lip6.fr Hello World % starts a comment. ends a declaration Every function must be in a module one module per source file source
More information<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
More informationMessage Passing. Advanced Operating Systems Tutorial 7
Message Passing Advanced Operating Systems Tutorial 7 Tutorial Outline Review of Lectured Material Discussion: Erlang and message passing 2 Review of Lectured Material Message passing systems Limitations
More informationAn Introduction to Erlang
Erlang Solutions Ltd An Introduction to Erlang From behind the trenches GOTO Copenhagen May 13 th, 2011 Francesco Cesarini Founder, Technical Director @FrancescoC francesco@erlang-solutions.com So Here
More informationErlang 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
More informationRobotics with Elixir
Meetup organized by Jean-François Cloutier Held at Big Room Studios, Portland, ME, USA Robotics with Elixir Part 1 Ghost in the Machine September 15, 2015 Lego Mindstorms The Greatest Toy Ever! And it
More informationScaling Erlang to 10,000 cores.!!! Simon Thompson, University of Kent
Scaling Erlang to 10,000 cores!!! Simon Thompson, University of Kent Multicore and many-core The inexorable rise in core numbers growing exponentially just as processors used to.! These are becoming the
More informationPrinciples of Programming Languages (E)
Principles of Programming Languages (E) Matteo Pradella December 1, 2017 Matteo Pradella Principles of Programming Languages (E) December 1, 2017 1 / 49 Erlang: Overview 1 Sequential programming 2 Concurrent
More informationA 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
More informationMapReduce in Erlang. Tom Van Cutsem
MapReduce in Erlang Tom Van Cutsem 1 Context Masters course on Multicore Programming Focus on concurrent, parallel and... functional programming Didactic implementation of Google s MapReduce algorithm
More informationRADU POPESCU IMPROVING THE WRITE SCALABILITY OF THE CERNVM FILE SYSTEM WITH ERLANG/OTP
RADU POPESCU IMPROVING THE WRITE SCALABILITY OF THE CERNVM FILE SYSTEM WITH ERLANG/OTP THE EUROPEAN ORGANISATION FOR PARTICLE PHYSICS RESEARCH (CERN) 2 THE LARGE HADRON COLLIDER THE LARGE HADRON COLLIDER
More informationCOSC441. 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
More informationElixir 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
More informationAdvanced Functional Programming, 1DL Lecture 2, Cons T Åhs
Advanced Functional Programming, 1DL450 2012 Lecture 2, 2012-11-01 Cons T Åhs Higher order functions hof() -> F = fun(x) -> X * X + 1 end, L = lists:map(f, [1, 2, 3], G = fun([]) -> nil; ([_ _]) -> cons
More informationStarting 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
More informationElixir 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
More informationErlang in the battlefield. Łukasz Kubica Telco BSS R&D Department Cracow Erlang Factory Lite, 2013
Erlang in the battlefield Łukasz Kubica Telco BSS R&D Department Cracow Erlang Factory Lite, 2013 Agenda Introduction to the SCM Erlang vm and upgrades Tracing Mnesia Final thoughts Questions 2 The Session
More informationBeautiful 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,
More informationRudy: a small web server. Johan Montelius. October 2, 2016
Rudy: a small web server Johan Montelius October 2, 2016 Introduction Your task is to implement a small web server in Erlang. The aim of this exercise is that you should be able to: describe the procedures
More informationErlang. The Good the Bad and the Ugly. Joe Armstrong
Erlang The Good the Bad and the Ugly Joe Armstrong Confusing things Things that we got wrong Removing things Wrong Assumptions Stuff that's not bad Things without names Missing Functionality Syntactic
More informationScenes From the Language Struggle in Toronto, Ontario. Mike Nolta
Scenes From the Language Struggle in Toronto, Ontario Mike Nolta Ch-Ch-Changes OpenMP & MPI are fine for now, but we need language support for parallelism. Corbato s Law: The number of lines of code a
More informationAn Introduction to Erlang. Richard Carlsson
An Introduction to Erlang Richard Carlsson Erlang Buzzwords Functional (strict) Single-assignment Dynamically typed Concurrent Distributed Message passing Soft real-time Fault tolerant No sharing Automatic
More informationECT: an Object Oriented Extension to Erlang
ECT: an Object Oriented Extension to Erlang Gábor Fehér Budapest University of Technology and Economics feherga@gmail.com András 'Georgy' Békés Ericsson Hungary andras.gyorgy.bekes@ericsson.com Erlang
More informationAn Introduction to Erlang
An Introduction to Erlang Alejandro Gómez Londoño Universidad EAFIT 8th March, 2013 What s Erlang? Erlang is a concurrent functional programming language, designed for writing concurrent programs that
More informationErlang and VoltDB TechPlanet 2012 H. Diedrich
TechPlanet 2012 H. Diedrich http://www.eonblast.com twitter @hdiedrich 1 Your Host Henning Diedrich Founder, CEO CTO Freshworks CTO, Producer at Newtracks Team Lead, Producer at Bigpoint OS Maintainer
More informationScaling Up from 1000 to 10 Nodes
Scaling Up from 1000 to 10 Nodes Anton Lavrik Alert Logic, Inc. 1 Alert Logic vs Twitter: daily numbers (2012) Alert Logic Twitter Events received 11.5B 0.5B Volume received 5TB 70GB Logs produced? 100TB
More informationThe Little Elixir & OTP Guidebook by Tan Wei Hao
SAMPLE CHAPTER The Little Elixir & OTP Guidebook by Tan Wei Hao Chapter 9 Copyright 2016 Manning Publications brief contents PART 1 GETTING STARTED WITH ELIXIR AND OTP...1 1 Introduction 3 2 A whirlwind
More informationErlectricity. Tom Preston-Werner. github.com/mojombo/erlectricity
Erlectricity Tom Preston-Werner github.com/mojombo/erlectricity 1 github 2 3 4 5 6 7 8 Like an Erlang Process that runs Ruby Erlang VM 9 Like an Erlang Process that runs Ruby Erlang VM 9 Like an Erlang
More informationErlang. 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
More informationProgramming Paradigms Written Exam (6 CPs)
Programming Paradigms Written Exam (6 CPs) 31.01.2018 First name Student number Last name Signature Instructions for Students Write your name and student number on the exam sheet and on every solution
More informationAkka: Simpler Concurrency, Scalability & Fault-tolerance through Actors. Jonas Bonér Viktor Klang
Akka: Simpler Concurrency, Scalability & Fault-tolerance through Actors Jonas Bonér Viktor Klang We believe that... Writing correct concurrent applications is too hard Scaling out applications is too hard
More informationConcurrency: what, why, how
Concurrency: what, why, how May 28, 2009 1 / 33 Lecture about everything and nothing Explain basic idea (pseudo) vs. Give reasons for using Present briefly different classifications approaches models and
More informationParallel Programming in Erlang (PFP Lecture 10) John Hughes
Parallel Programming in Erlang (PFP Lecture 10) John Hughes What is Erlang? Haskell Erlang - Types - Lazyness - Purity + Concurrency + Syntax If you know Haskell, Erlang is easy to learn! QuickSort again
More informationBuilding a video conference (WebRTC) controller with Elixir. Or how Elixir was introduced into VoiSmart
Building a video conference (WebRTC) controller with Elixir Or how Elixir was introduced into VoiSmart Hello! Who: Matteo Brancaleoni Where: VoiSmart www.voismart.it As: Software Engineer Where #2: GH:
More informationStatic rules of variable scoping in Erlang
Proceedings of the 7 th International Conference on Applied Informatics Eger, Hungary, January 28 31, 2007. Vol. 2. pp. 137 145. Static rules of variable scoping in Erlang László Lövei, Zoltán Horváth,
More informationThe Little Elixir & OTP Guidebook by Tan Wei Hao
SAMPLE CHAPTER The Little Elixir & OTP Guidebook by Tan Wei Hao Chapter 1 Copyright 2016 Manning Publications brief contents PART 1 GETTING STARTED WITH ELIXIR AND OTP...1 1 Introduction 3 2 A whirlwind
More information20 Years of Commercial Functional Programming
20 Years of Commercial Functional Programming Ulf Wiger Senior Software Architect Ericsson AB 2004-07-01 1 History of Erlang How to design SW for future telecoms systems? 1995: Several new projects 1998:
More informationLecture 5: Erlang 1/31/12
Principles of Concurrency and Parallelism Lecture 5: Erlang 1/31/12 Example Suppose we have N threads (or processes, tasks) that form a ring Each thread communicates with its neighbor forwarding a message
More informationBUILDING A SCALABLE MOBILE GAME BACKEND IN ELIXIR. Petri Kero CTO / Ministry of Games
BUILDING A SCALABLE MOBILE GAME BACKEND IN ELIXIR Petri Kero CTO / Ministry of Games MOBILE GAME BACKEND CHALLENGES Lots of concurrent users Complex interactions between players Persistent world with frequent
More informationFunctional Programming In Real Life
Functional Programming In Real Life Dr. Erik Stenman CTO Kreditor Europe AB Creative Payment Solutions Introduction I will talk about KREDITOR, a company that bet it's future on Erlang, a functional programming
More informationProgramming Paradigms Written Exam (6 CPs)
Programming Paradigms Written Exam (6 CPs) 06.07.2016 First name Student number Last name Signature Instructions for Students Write your name and student number on the exam sheet and on every solution
More informationS 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
More informationLecture 9. Part I. Overview of Message Passing. Communication Coupling. Decoupling Blackboard. Decoupling Broadcast. Linda and Erlang.
Lecture 9 Part I Linda and Erlang Linda Overview of Message Passing Communication Coupling One process sends a message Another process awaits for a message We will consider two dimensions of this approach:
More informationiex(1)> defmodule RepeatN do def repeat_n(function, count) do ...(1)> end repeat_n(function, count - 1) {:module, RepeatN,...}
The other day iex(1)> iex(1)> defmodule RepeatN do...(1)> def repeat_n(_function, 0) do...(1)> # noop...(1)>...(1)> def repeat_n(function, 1) do...(1)> function.()...(1)>...(1)> def repeat_n(function,
More informationAuthor: Paul Zenden. Hot-or-Not Elixir with José Valim
Author: Paul Zenden Hot-or-Not Elixir with José Valim > > elixir with {:ok, : José Valim }
More informationIt is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis
Chapter 14 Functional Programming Programming Languages 2nd edition Tucker and Noonan It is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis
More informationCloudI Integration Framework. Chicago Erlang User Group May 27, 2015
CloudI Integration Framework Chicago Erlang User Group May 27, 2015 Speaker Bio Bruce Kissinger is an Architect with Impact Software LLC. Linkedin: https://www.linkedin.com/pub/bruce-kissinger/1/6b1/38
More informationExperiments in OTP-Compliant Dataflow Programming
Experiments in OTP-Compliant Dataflow Programming Introducing Erlang Services Platform (Erlang/SP) San Francisco Erlang Factory, March 21, 2013 Jay Nelson Twitter: @duomark Email: Jay@duomark.com Manycore
More informationDEMYSTIFYING BIG DATA WITH RIAK USE CASES. Martin Schneider Basho Technologies!
DEMYSTIFYING BIG DATA WITH RIAK USE CASES Martin Schneider Basho Technologies! Agenda Defining Big Data in Regards to Riak A Series of Trade-Offs Use Cases Q & A About Basho & Riak Basho Technologies is
More informationThe Actor Model. Towards Better Concurrency. By: Dror Bereznitsky
The Actor Model Towards Better Concurrency By: Dror Bereznitsky 1 Warning: Code Examples 2 Agenda Agenda The end of Moore law? Shared state concurrency Message passing concurrency Actors on the JVM More
More informationErlang: An Overview. Part 1 Sequential Erlang. Thanks to Richard Carlsson for the original version of many slides in this part
Erlang: An Overview Part 1 Sequential Erlang Thanks to Richard Carlsson for the original version of many slides in this part Erlang buzzwords Functional (strict) Single-assignment Dynamically typed Concurrent
More informationLarge Systems: Design + Implementation: Communication Coordination Replication. Image (c) Facebook
Large Systems: Design + Implementation: Image (c) Facebook Communication Coordination Replication Credits Slides largely based on Distributed Systems, 3rd Edition Maarten van Steen Andrew S. Tanenbaum
More informationPolling Sucks. So what should we do instead?
Polling Sucks So what should we do instead? Should we use XMPP? What about AMQP? What about plain old HTTP push? Should it be peerto-peer? Intermediated? Disintermediated? 1 Messaging The answer is banal:
More informationREdis: Implementing Redis in Erlang. A step-by-step walkthrough
R: Implementing Redis in Erlang A step-by-step walkthrough 1 2 : Implementing Redis in Erlang A step-by-step walkthrough 2 My Background Microsoft Visual Studio Visto Corporation Founded Inaka Moved to
More informationLecture 8. Linda and Erlang
Lecture 8 Linda and Erlang Part I Linda 2 Overview of Message Passing One process sends a message Another process awaits for a message We will consider two dimensions of this approach: What form of synchronisation
More informationFunctional Programming. Introduction To Cool
Functional Programming Introduction To Cool #1 Cunning Plan ML Functional Programming Fold Sorting Cool Overview Syntax Objects Methods Types #2 This is my final day... as your... companion... through
More informationErlang functional programming in a concurrent world
KTH ROYAL INSTITUTE OF TECHNOLOGY Erlang functional programming in a concurrent world Johan Montelius and Vladimir Vlassov Erlang Concurrent Oriented Programming processes have state communicate using
More informationErlang functional programming in a concurrent world Johan Montelius and Vladimir Vlassov
KTH ROYAL INSTITUTE OF TECHNOLOGY Erlang functional programming in a concurrent world Johan Montelius and Vladimir Vlassov Erlang Concurrent Oriented Programming processes have state communicate using
More informationIntroduction. version 5.0
Introduction version 5.0 Typeset in L A TEX from SGML source using the DOCBUILDER 3.0 Document System. Contents 1 Introduction 1 1.1 Introduction.......................................... 2 Erlang and
More informationCS558 Programming Languages
CS558 Programming Languages Winter 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Values and Types We divide the universe of values according to types A type is a set of values and
More informationLet s make release upgrades great again!
Let s make release upgrades great again! Who am i? Luis Rascão Work @ Miniclip Erlang Ing since 2014 Miniclip (paid this trip for me) Mobile games company Started out with mostly Flash games Now focused
More informationAMQP and Beyond. Messaging by Extending RabbitMQ. Tony Garnock-Jones
AMQP and Beyond Messaging by Extending RabbitMQ Tony Garnock-Jones Why messaging? Database is to Filesystem as Messaging is to Network Messaging abstracts away from the details of
More informationProgramming Distributed Systems
Peter Zeller, Annette Bieniusa Programming Distributed Systems Summer Term 2018 1/ 37 Programming Distributed Systems Introduction to Erlang Peter Zeller, Annette Bieniusa AG Softech FB Informatik TU Kaiserslautern
More informationProgramming Paradigms Written Exam (6 CPs)
Programming Paradigms Written Exam (6 CPs) 19.09.2018 First name Student number Last name Signature Instructions for Students Write your name and student number on the exam sheet and on every solution
More informationCPL 2016, week 10. Clojure functional core. Oleg Batrashev. April 11, Institute of Computer Science, Tartu, Estonia
CPL 2016, week 10 Clojure functional core Oleg Batrashev Institute of Computer Science, Tartu, Estonia April 11, 2016 Overview Today Clojure language core Next weeks Immutable data structures Clojure simple
More informationErlang Erl Download or Read Online ebook erlang erl in PDF Format From The Best User Guide Database
Erlang Erl Free PDF ebook Download: Erlang Erl Download or Read Online ebook erlang erl in PDF Format From The Best User Guide Database This is a kick start tutorial to get you started with Erlang. Everything
More informationDistributed Systems COMP 212. Revision 2 Othon Michail
Distributed Systems COMP 212 Revision 2 Othon Michail Synchronisation 2/55 How would Lamport s algorithm synchronise the clocks in the following scenario? 3/55 How would Lamport s algorithm synchronise
More information