44
Why (not) Erlang Motiejus Jakštys @mo_kelione All drawings acquired from http://learnyousomeerlang.com/ 1/27

Slides

Embed Size (px)

Citation preview

Why (not) ErlangMotiejus Jakštys @mo_kelione

All drawings acquired from http://learnyousomeerlang.com/

1/27

About me

no cultural meaning whatsoever

• PreErl: Linux, Python, C++• Started Erlang on 2011• Spil since 2012 May• Backend• Special care

I correctnessI reliability

2/27

This is about:1. Little bit of semantics (fault tolerance and distribution)2. Erlang comparison with different languages3. Strengths and weaknesses

3/27

NOT about:1. Syntax2. Libraries

Read a tutorial: http://learnyousomeerlang.com/

4/27

NOT about:1. Syntax2. Libraries

Read a tutorial: http://learnyousomeerlang.com/

4/27

Intro

IntroHigh-level properties / goals

SemanticsSmall processesNo shared stateLet it crashDistribution

ComparisonPythonJavaHaskell

Learning Erlang5/27

Intro High-level properties / goals

Telephone switches in late 1980s• Massively scalable• High availability• Soft real-time

AXD301 reported 9.99999999% (nine nines) availability 1

1Joe Armstrong: http://pragprog.com/articles/erlang6/27

Intro High-level properties / goals

Telephone switches in late 1980s• Massively scalable• High availability• Soft real-time

AXD301 reported 9.99999999% (nine nines) availability 1

1Joe Armstrong: http://pragprog.com/articles/erlang6/27

Intro High-level properties / goals

0.6 seconds per 20 years

7/27

Semantics

IntroHigh-level properties / goals

SemanticsSmall processesNo shared stateLet it crashDistribution

ComparisonPythonJavaHaskell

Learning Erlang8/27

Semantics Small processes

• Quick to create: 660K proc/sec

• Memory footprint:Standard ∼ 300 words / process (2.4KB)Hibernated even less

9/27

Semantics Small processes

• Quick to create: 660K proc/sec• Memory footprint:

Standard ∼ 300 words / process (2.4KB)Hibernated even less

9/27

Semantics Small processes

• Process per user session• Process per DB transaction• Process per anything

Let’s try

10/27

Semantics Small processes

• Process per user session• Process per DB transaction• Process per anything

Let’s try

10/27

Semantics No shared state

• Only message passing• No shared memory 2

• Immutable data structures (no variables)

2almost11/27

Semantics No shared state

Consequences:

• Only critical sectionsavoid deadlocks

• Easier garbage collectionmark & sweep, no cycles!

12/27

Semantics No shared state

Consequences:• Only critical sections

avoid deadlocks

• Easier garbage collectionmark & sweep, no cycles!

12/27

Semantics Let it crash

13/27

Semantics Let it crash

13/27

Semantics Let it crash

13/27

Semantics Distribution

Distribution is easy.

Pid ! Message.

For both local and remote PIDs.

14/27

Semantics Distribution

Distribution is easy.

Pid ! Message.

For both local and remote PIDs.

14/27

Semantics Distribution

Distribution is easy.

Pid ! Message.

For both local and remote PIDs.

14/27

Semantics Distribution

Show time

15/27

Comparison

IntroHigh-level properties / goals

SemanticsSmall processesNo shared stateLet it crashDistribution

ComparisonPythonJavaHaskell

Learning Erlang16/27

Comparison Python

Python works for:• Systems programming• Classical web development• Scripting (amount of libraries and ease to include)• UI

17/27

Comparison Python

Python not really• Distributed, scalable• Protocol implementations• Computational performance• Live system debugging

18/27

Comparison Java

Java works for:• Computational performance

if you do not do allocations, eg. use freelists

• Processing XML and creating SOAP web services

I am serious

19/27

Comparison Java

Java works for:• Computational performance

if you do not do allocations, eg. use freelists

• Processing XML and creating SOAP web servicesI am serious

19/27

Comparison Java

Java not really:• Latency is unpredictable• Failure isolation• Encapsulation because of statically typed OO

You wanted a banana but what you got was a gorilla holding thebanana and the entire jungle - Joe Armstrong

20/27

Comparison Haskell

Good for:• High-level computationally expensive code

• State machines, parsers. VERY concise syntax• Being academic in CS• Compiles to single binary• UI (gtk2hs) is beautiful

Concepts like Java, but 10x less code

• Nothing beats pure functional reusability

21/27

Comparison Haskell

Good for:• High-level computationally expensive code• State machines, parsers. VERY concise syntax

• Being academic in CS• Compiles to single binary• UI (gtk2hs) is beautiful

Concepts like Java, but 10x less code

• Nothing beats pure functional reusability

21/27

Comparison Haskell

Good for:• High-level computationally expensive code• State machines, parsers. VERY concise syntax• Being academic in CS

• Compiles to single binary• UI (gtk2hs) is beautiful

Concepts like Java, but 10x less code

• Nothing beats pure functional reusability

21/27

Comparison Haskell

Good for:• High-level computationally expensive code• State machines, parsers. VERY concise syntax• Being academic in CS• Compiles to single binary

• UI (gtk2hs) is beautifulConcepts like Java, but 10x less code

• Nothing beats pure functional reusability

21/27

Comparison Haskell

Good for:• High-level computationally expensive code• State machines, parsers. VERY concise syntax• Being academic in CS• Compiles to single binary• UI (gtk2hs) is beautiful

Concepts like Java, but 10x less code

• Nothing beats pure functional reusability

21/27

Comparison Haskell

Good for:• High-level computationally expensive code• State machines, parsers. VERY concise syntax• Being academic in CS• Compiles to single binary• UI (gtk2hs) is beautiful

Concepts like Java, but 10x less code

• Nothing beats pure functional reusability

21/27

Comparison Haskell

Haskell not really:• Distribution (not production ready)• Concurrent code, either:

I pthreads-likeI or not prod ready

• Failure isolation

22/27

Learning Erlang

IntroHigh-level properties / goals

SemanticsSmall processesNo shared stateLet it crashDistribution

ComparisonPythonJavaHaskell

Learning Erlang23/27

Learning Erlang

Not difficult.

C++ is wayyyy more complex - Joe Armstrong

24/27

Learning Erlang

Not difficult.C++ is wayyyy more complex - Joe Armstrong

24/27

Learning Erlang

Learning resources

• Free on-line book• EBook• Dead-tree format

25/27

Learning Erlang

Learning resources

• Free on-line book• EBook• Dead-tree format

25/27

Learning Erlang

9 circles of Erl

26/27

Learning Erlang

QA

27/27