More Related Content Similar to Erlang Workshop at Dyncon 2011 (20) Erlang Workshop at Dyncon 20112. Erlang, the Language
• Started out in the Ericsson software lab 1987 (!)
• Released as open source in 1998
• Gains Symmetric Multi Processing (SMP) support
in 2005
2000000
1500000
1000000 Requests/Month
500000
0
1998 2001 2003 2005 2007 2009
© 2011 Erlang Solutions Ltd.
3. Properties
Functional programming language, high
Declarative abstraction level, pattern matching and
concise readable programs
Either transparent or explicit concurrency,
Concurrency
light-weight processes and highly scalable
Response times in the order of milliseconds
Soft Real-Time
per-process garbage collection
© 2011 Erlang Solutions Ltd.
4. Properties
Simple and consistent error recovery,
Robustness supervision hierarchies and "program for
the correct case"
Explicit or transparent distribution
Distribution
Network-aware runtime system
Easily change code in a running system.
Hot code loading Enables non-stop operation Simplifies
testing
© 2011 Erlang Solutions Ltd.
5. Properties
"Ports" to the outside world behave as
External Interfaces
Erlang processes
Erlang runs on any UNIX, Windows,
Portability VxWorks. Supports heterogeneous
networks
Symmetric multiprocessing support. Takes
SMP Support
full advantage of multiple CPU architectures
© 2011 Erlang Solutions Ltd.
7. The Erlang Shell
$ erl
Erlang R14B01 (erts-5.8.2) [...]
Eshell V5.8.2 (abort with ^G)
1> 2 + 3.
5
2> [1, 2, 3] ++ [4, 5, 6].
[1,2,3,4,5,6]
© 2011 Erlang Solutions Ltd.
8. The Erlang Shell
3> A = test.
test
4> B = {“string”, A}.
{“string”,test}
5> {S, test} = B.
{“string”,test}
6> S.
© 2011 Erlang Solutions Ltd.
9. The Erlang Shell
7> [72,101,108,108,111,32,87,111,114,108,
100].
"Hello World"
8> [{person, "Joe", "Armstrong"}, {person,
"Robert", "Virding"}, {person, "Mike",
"Williams"}].
[{person, "Joe", "Armstrong"},
{person, "Robert", "Virding"},
{person, "Mike", "Williams"}]
© 2011 Erlang Solutions Ltd.
11. Modules & Functions
-module(demo). module name
-export([double/1]).
% This is a comment.
% Everything after '%' is ignored.
double(X) ->
times(X, 2).
times(X, N) ->
X * N.
https://gist.github.com/854366
© 2011 Erlang Solutions Ltd.
12. Modules & Functions
-module(demo). module name
-export([double/1]). exported functions
% This is a comment.
% Everything after '%' is ignored.
double(X) ->
times(X, 2).
times(X, N) ->
X * N.
https://gist.github.com/854366
© 2011 Erlang Solutions Ltd.
13. Modules & Functions
-module(demo). module name
-export([double/1]). exported functions
comment
% This is a comment.
% Everything after '%' is ignored.
double(X) ->
times(X, 2).
times(X, N) ->
X * N.
https://gist.github.com/854366
© 2011 Erlang Solutions Ltd.
14. Modules & Functions
-module(demo). module name
-export([double/1]). exported functions
comment
% This is a comment.
% Everything after '%' is ignored.
double(X) ->
function
times(X, 2).
times(X, N) ->
X * N.
https://gist.github.com/854366
© 2011 Erlang Solutions Ltd.
15. Modules & Functions
-module(demo). module name
-export([double/1]). exported functions
comment
% This is a comment.
% Everything after '%' is ignored.
double(X) ->
function
times(X, 2).
times(X, N) -> last expression is the
X * N. return value
https://gist.github.com/854366
© 2011 Erlang Solutions Ltd.
16. Modules & Functions
9> c(demo).
{ok,demo}
10> demo:double(21).
42
11> demo:times(3, 3).
** exception error: undefined function
demo:times/2
© 2011 Erlang Solutions Ltd.
19. Processes
Pid = spawn(M, F, A)
M:F(A)
receive
{msg, From} ->
From ! ok
end
© 2011 Erlang Solutions Ltd.
20. Processes
Pid = spawn(M, F, A)
M:F(A)
Pid ! {msg, self()}
receive
{msg, From} ->
From ! ok
end
© 2011 Erlang Solutions Ltd.
21. Processes
Pid = spawn(M, F, A)
M:F(A)
Pid ! {msg, self()}
receive
ok {msg, From} ->
From ! ok
end
© 2011 Erlang Solutions Ltd.
23. Processes
supervisor
© 2011 Erlang Solutions Ltd.
24. Processes
supervisor
worker
© 2011 Erlang Solutions Ltd.
25. Processes
supervisor
worker
© 2011 Erlang Solutions Ltd.
29. Processes
node@host
Application Application Application
1 2 3
© 2011 Erlang Solutions Ltd.
31. Distribution
cat
nodes() =
[]
© 2011 Erlang Solutions Ltd.
32. Distribution
cat
flea
nodes() =
[cat@home, flea@home]
© 2011 Erlang Solutions Ltd.
33. Distribution
cat dog
flea
nodes() = nodes() =
[cat@home, flea@home] []
© 2011 Erlang Solutions Ltd.
34. Distribution
cat dog
flea bird
nodes() = nodes() =
[cat@home, flea@home] [dog@work, bird@work]
© 2011 Erlang Solutions Ltd.
35. Distribution
cat dog
flea bird
nodes() =
[cat@home, flea@home, dog@work, bird@work]
© 2011 Erlang Solutions Ltd.
37. A Talking Virus
• A module that starts a process
• When that process detects a new node in the
cluster
- It will copy the module to that node
- And start a new process on that node
- Which will do the same to connecting nodes
• Source code: https://gist.github.com/854389
© 2011 Erlang Solutions Ltd.
38. A Talking Virus
$ erl -name somename -setcookie dyncon
...
Eshell V5.8.2 (abort with ^G)
(somename@somehost)1> nodes().
[]
(somename@somehost)2>
net_adm:ping(adam@192.168.161.166).
pong
© 2011 Erlang Solutions Ltd.
39. Resources
http://tryerlang.org
http://learnyousomeerlang.com
© 1999-2011 Erlang Solutions Ltd.
Editor's Notes \n \n \n \n \n Facebook (Chat), Amazon (SimpleDB), Klarna (E-Commerce billing), T-Mobile (SMS gateway), Yahoo! (Delicious), GitHub (RPC and Messaging), RabbitMQ (Enterprise messaging), CouchDB (NoSQL), Riak (NoSQL)\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n