Objects, Anomalies, and Actors: The Next Revolution
Steve Vinoski
Architect, Basho Technologies
QCon San Francisco 2011 18 Nov 2011 @stevevinoski http://steve.vinoski.net/ vinoski@ieee.org
1
Objects, Anomalies, and Actors: The Next Revolution Steve Vinoski - - PowerPoint PPT Presentation
Objects, Anomalies, and Actors: The Next Revolution Steve Vinoski Architect, Basho Technologies QCon San Francisco 2011 18 Nov 2011 @stevevinoski http://steve.vinoski.net/ vinoski@ieee.org 1 This is actually Kresten Krab Thorups
Objects, Anomalies, and Actors: The Next Revolution
Steve Vinoski
Architect, Basho Technologies
QCon San Francisco 2011 18 Nov 2011 @stevevinoski http://steve.vinoski.net/ vinoski@ieee.org
1he couldn’t attend the conference
behind the QCon and GOTO conferences
interpretation of his material
and inserted some of my own
23
3Increased Complexity
4
Program Structure Increased Complexity
4
Program Structure Component Reuse Increased Complexity
4
Program Structure Component Reuse Domain Modeling Increased Complexity
4
Simula Smalltalk Java Objective-C C# C++
Ruby
5
5Simula Smalltalk Java Objective-C C# C++ Ruby OOA&D UML
Patterns DDD
6
6Program Structure Component Reuse Domain Modeling Increased Complexity
7
Internet
78
More Complexity Infrastructure made of Software
8Infrastructure made of Software More Complexity
9
9Infrastructure made of Software Fault Tolerance, Availability, QoS More Complexity
9
9Infrastructure made of Software Fault Tolerance, Availability, QoS Integration, Coordination More Complexity
9
9Infrastructure made of Software Fault Tolerance, Availability, QoS Integration, Coordination Cloud, Multi-Core More Complexity
9
9Infrastructure made of Software Fault Tolerance, Availability, QoS Integration, Coordination Cloud, Multi-Core More Complexity
W e ’ r e s t r u g g l i n g t
a n d l e t h e s e w i t h a n
j e c t m i n d s e t !
9
9Fault Tolerance, Availability, QoS Integration, Coordination Cloud, Multi-Core Time for a new revolution?
10
10Thomas Kuhn The Structure of Scientific Revolutions
11
11paradigm paradigm
12
12paradigm paradigm
12
12paradigm paradigm
normal science
12
12paradigm paradigm
normal science
anomalies
12
12paradigm paradigm
normal science CRISIS
anomalies
12
12paradigm paradigm
normal science CRISIS
anomalies
12
revolutionary science
12paradigm paradigm
normal science normal science CRISIS
anomalies
12
revolutionary science
12Fault Tolerance, Availability, QoS Integration, Coordination Cloud, Multi-Core What is the right paradigm to cope with these?
13
13Fault Tolerance, Availability, QoS Integration, Coordination Cloud, Multi-Core Functional, Data-Parallel Erlang, Actor Models Parallel Compilers What is the right paradigm to cope with these?
13
13Fault Tolerance, Availability, QoS Integration, Coordination Cloud, Multi-Core Functional, Data-Parallel Erlang, Actor Models Parallel Compilers What is the right paradigm to cope with these?
13
R a l p h J
n s
’ s b l
“ E r l a n g , t h e N e x t J a v a ” . . . E r l a n g i s g
n g t
e a v e r y i m p
t a n t l a n g u a g e . . . I t s m a i n a d v a n t a g e i s t h a t i t i s p e r f e c t l y s u i t e d f
t h e m u l t i
e , w e b s e r v i c e s f u t u r e . I n f a c t , i t i s t h e O N L Y m a t u r e , r
k
i d l a n g u a g e t h a t i s s u i t a b l e f
w r i t i n g h i g h l y s c a l a b l e s y s t e m s t
u n
m u l t i c
e m a c h i n e s .
13Objects Actors
14
14Objects Actors
14
14Objects anomalies Actors
14
14Objects anomalies Actors
14
If Actor-Programming is the new Paradigm, What are the anomalies we should see now?
1415
1510 1 1 8 7 6
implementation interface
16
16m e t h
m e t h
m e t h
m e t h
data
Encapsulation
17m e t h
m e t h
m e t h
m e t h
data
e t h
m e t h
m e t h
m e t h
data
e t h
m e t h
m e t h
m e t h
data
m e t h
m e t h
m e t h
m e t h
data
e t h
m e t h
m e t h
m e t h
data
e t h
m e t h
m e t h
m e t h
data
m e t h
m e t h
m e t h
m e t h
data
e t h
m e t h
m e t h
m e t h
data
e t h
m e t h
m e t h
m e t h
data
m e t h
m e t h
m e t h
m e t h
data
e t h
m e t h
m e t h
m e t h
data
e t h
m e t h
m e t h
m e t h
data
m e t h
m e t h
m e t h
m e t h
data
e t h
m e t h
m e t h
m e t h
data
e t h
m e t h
m e t h
m e t h
data
m e t h
m e t h
m e t h
m e t h
data
e t h
m e t h
m e t h
m e t h
data
e t h
m e t h
m e t h
m e t h
data
Anomaly
1819
m e t h19
m e t h19
m e t hm e t h
m e t h
m e t h
m e t h
data
Active Object + State Machine
20
20m e t h
m e t h
m e t h
m e t h
data
Active Object + State Machine
20
20m e t h
m e t h
m e t h
m e t h
data
21
Active Object + State Machine
21m e t h
m e t h
m e t h
m e t h
data
21
Active Object + State Machine
21empty full(X) box
22
22empty full(X) {‘put’,X} box
22
22empty full(X) {‘put’,X} {‘take’,From} / send(From, X) box
22
22empty full(X) {‘put’,X} {‘take’,From} / send(From, X) box
box() ➞ empty(). empty() ➞ receive {‘put’, X} ➞ full(X) end. full(X) ➞ receive {‘take’, From} ➞ From ! X, empty() end.
23
23box() ➞ empty(). empty() ➞ receive {‘put’, X} ➞ full(X) end. full(X) ➞ receive {‘take’, From} ➞ From ! X, empty() end.
empty full(X) {‘put’,X} {‘take’,From} / send(From, X) box {‘peek’,From} / send(From,{‘ok’, X})
24
24box() ➞ empty(). empty() ➞ receive {‘put’, X} ➞ full(X) end. full(X) ➞ receive {‘take’, From} ➞ From ! X, empty(); {‘peek’, From} ➞ From ! {‘ok’, X}, full(X) end.
25
empty full(X) {‘put’,X} {‘take’,From} / send(From, X) box {‘peek’,From} / send(From,{‘ok’, X})
25box() ➞ empty(). empty() ➞ receive {‘put’, X} ➞ full(X) end. full(X) ➞ receive {‘take’, From} ➞ From ! X, empty(); {‘peek’, From} ➞ From ! {‘ok’, X}, full(X) end.
25
empty full(X) {‘put’,X} {‘take’,From} / send(From, X) box {‘peek’,From} / send(From,{‘ok’, X})
2526
box() ➞ empty(). empty() ➞ receive {‘put’, X} ➞ full(X) end. full(X) ➞ receive {‘take’, From} ➞ From ! X, empty(); {‘peek’, From} ➞ From ! {‘ok’, X}, full(X) end.
26Box = spawn(fun box/0),
26
box() ➞ empty(). empty() ➞ receive {‘put’, X} ➞ full(X) end. full(X) ➞ receive {‘take’, From} ➞ From ! X, empty(); {‘peek’, From} ➞ From ! {‘ok’, X}, full(X) end.
26Box = spawn(fun box/0), Box ! {‘put’, 27},
26
box() ➞ empty(). empty() ➞ receive {‘put’, X} ➞ full(X) end. full(X) ➞ receive {‘take’, From} ➞ From ! X, empty(); {‘peek’, From} ➞ From ! {‘ok’, X}, full(X) end.
26Box = spawn(fun box/0), Box ! {‘put’, 27}, Box ! {‘take’, self()}, receive Value ➞ print(Value) end
26
box() ➞ empty(). empty() ➞ receive {‘put’, X} ➞ full(X) end. full(X) ➞ receive {‘take’, From} ➞ From ! X, empty(); {‘peek’, From} ➞ From ! {‘ok’, X}, full(X) end.
26Objects Interface Fixed API Actors Protocol API changes with internal state
27
27Objects Interface Fixed API Actors Protocol API changes with internal state
27
Anomaly
2728
2828
... each Smalltalk object is a recursion on the entire possibilities of the computer. Thus its semantics are a bit like having thousands and thousands of computers all hooked together by a very fast network. Alan Kay, Early History of Smalltalk
2828
Just a gentle reminder ... Smalltalk is NOT only its syntax or the class library, it is not even about classes. I'm sorry that I long ago coined the term "objects" for this topic because it gets many people to focus on the lesser idea. The big idea is "messaging" -- that is what the kernel of Smalltalk/Squeak is all about... Alan Kay, October 1998
2829
2929
Use Objects!
... heard in the ‘90s
2929
Use Objects! 100.000’s of objects, are you crazy?
... heard in the ‘90s
2929
Use Actors! 100.000’s of processes, silly you!
... heard yesterday
29“What if the OOP parts of other languages (Java, C++, Ruby, etc.) had the same behavior as their concurrency support? What if you were limited to only creating 500 objects total for an application because any more would make the app unstable and almost certainly crash it in hard-to-debug ways? What if these objects behaved differently on different platforms?”
Joe Armstrong, creator of Erlang
as quoted in http://weblog.hypotheticalabs.com/?p=217
30■ Functional languages disallow effects ■ Many object-oriented styles encourage side effects. ■ Actors confine effects
31
m e t h
m e t h
m e t h
m e t h
data
From C++ to Java Garbage Collection From Java to Erlang State Containment
32
32■ Threaded programs are error prone (we already knew that). ■ Good thread design requires global knowledge.
33
33■ Threaded programs are error prone (we already knew that). ■ Good thread design requires global knowledge.
Anomaly
33
33spawn
34
m e t hlink
35
m e t hlink
35
host host
m e t h36
m e t h
m e t h
m e t h
m e t h
data
36■ Write code with lots of assertions
36
m e t h
m e t h
m e t h
m e t h
data
36■ Write code with lots of assertions ■ Let a meta-level do fault handling
36
m e t h
m e t h
m e t h
m e t h
data
36■ Write code with lots of assertions ■ Let a meta-level do fault handling ■ Defensive code is a symptom of a weak platform (segfaults, memory leaks, ...)
36
m e t h
m e t h
m e t h
m e t h
data
36■ Write code with lots of assertions ■ Let a meta-level do fault handling ■ Defensive code is a symptom of a weak platform (segfaults, memory leaks, ...)
Anomaly
36
m e t h
m e t h
m e t h
m e t h
data
36Martin Fowler’s First Law of Distributed Objects Design
Steve Vinoski: RPC and its Offspring: Convenient, Yet Fundamentally Flawed rpc
37
Starbucks doesn’t use transactions
37Martin Fowler’s First Law of Distributed Objects Design
Steve Vinoski: RPC and its Offspring: Convenient, Yet Fundamentally Flawed rpc
Anomaly
37
Starbucks doesn’t use transactions
3738
38■ Any abstraction (hiding code) is problematic to distribute, persist, etc.
38
38■ Any abstraction (hiding code) is problematic to distribute, persist, etc. ■ You want to distribute/persist simple data (as in sql databases, document stores)
38
38■ Any abstraction (hiding code) is problematic to distribute, persist, etc. ■ You want to distribute/persist simple data (as in sql databases, document stores) ■ JSON’s popularity is a testament to this anomaly.
38
38■ Any abstraction (hiding code) is problematic to distribute, persist, etc. ■ You want to distribute/persist simple data (as in sql databases, document stores) ■ JSON’s popularity is a testament to this anomaly.
Anomaly
38
3839
39■ Tuple, List, Record, Number, String, Binary
39
39■ Tuple, List, Record, Number, String, Binary ■ Pattern matching is polymorphism for values
39
39■ Tuple, List, Record, Number, String, Binary ■ Pattern matching is polymorphism for values ■ Erlang data stores (like Mnesia) just store values, not bytes or objects.
39
39■ Tuple, List, Record, Number, String, Binary ■ Pattern matching is polymorphism for values ■ Erlang data stores (like Mnesia) just store values, not bytes or objects. ■ Too much of my Java programs are boilerplate code.
39
39■ Thread & Locks ■ Interfaces with Fixed API ■ Defensive Code ■ RPC/RMI ■ Boilerplate code for persistence
40
40■ Processes w/ state containment ■ Protocols ■ Let it Fail ■ Async Messaging ■ Send & store simple Data
41
4142
4243
Making reliable distributed control systems in the presence of errors
4343
Making reliable distributed control systems in the presence of errors
4343
Making reliable distributed control systems in the presence of errors
■ The “secret weapon” for Ericsson’s market leading, real-time telephony systems.
4343
Making reliable distributed control systems in the presence of errors
■ The “secret weapon” for Ericsson’s market leading, real-time telephony systems. ■ 20+ years of experience to learn from.
4344
Open Telecommunications Platform ■ Embedded Distributed Systems ■ High Availability ■ In-Production Upgrades
4445
45Don’ t dissect a frog, Build One!
Nicolas Negroponte
45
45Your favorite OS BEAM Emulator Your Erlang Program Platform Framework
BEAM
BIFs
46
46Your favorite OS BEAM Emulator Your Erlang Program Platform Framework
BEAM
BIFs
46
46Java Virtual Machine Your favorite OS ERJANG
JVM
BIFs
47
Your Erlang Program Platform Framework
BEAM
47Kresten Krab Thorup Erlang Person of the Year, 2010
48■ Servers ■ Event Handlers ■ Finite State Machine ■ Supervisors ■ Networking: TCP , HTTP
49
49programming Erlang processes
message
itself to handle the next message
50
50Essence of OTP Behaviors
loop(State) -> NewState = receive % handle messages here, % messages may affect State end, loop(NewState).
51
51loop(State) -> receive % handle messages here, % messages may affect State end, loop(NewState).
52
Essence of OTP Behaviors
52loop(State) -> receive % handle messages here, % messages may affect State end, loop(NewState).
53
Essence of OTP Behaviors
53loop(State) -> NState = receive % handle messages here, % messages may affect State end, loop(NewState).
54
Essence of OTP Behaviors
54loop(State) -> NState = receive % handle messages here, % messages may affect State end, loop(NState).
55
Essence of OTP Behaviors
55loop(State) -> NState = receive % handle messages here, % messages may affect State end, loop(NState).
56
Essence of OTP Behaviors
56loop(Callbacks, State) -> NState = receive Msg -> Callbacks:handle(Msg, State) end, loop(Callbacks, NState).
57
Essence of OTP Behaviors
57loop(Callbacks, State) -> NState = receive M1 -> Callbacks:handle1(M1,State); M2 -> Callbacks:handle2(M2,State); M3 -> Callbacks:handle3(M3,State) end, loop(Callbacks, NState).
58
Essence of OTP Behaviors
58loop(Callbacks, State) -> {Next, NState} = receive M1 -> Callbacks:handle_m1(M1,State); M2 -> Callbacks:handle_m2(M2,State); M3 -> Callbacks:handle_m3(M3,State) end, case Next of stop -> ok; _ -> loop(Callbacks, NState) end.
59
Essence of OTP Behaviors
59more sophisticated
assume specific callback functions, checked by the compiler
60
6061
6162
real problems that need to be solved to realize the potential of cloud computing
6262
real problems that need to be solved to realize the potential of cloud computing
6262
real problems that need to be solved to realize the potential of cloud computing
6262
real problems that need to be solved to realize the potential of cloud computing
6262
real problems that need to be solved to realize the potential of cloud computing
6262
real problems that need to be solved to realize the potential of cloud computing
6263
6363
6364
6464
Async Messaging
6464
Async Messaging State [Fault] Containment
6464
Async Messaging State [Fault] Containment Fault Monitoring
6465
6566
6666
6667
6768
69
6970
7070
70packet decoders (HTTP, FCGI, CDR)
70
70packet decoders (HTTP, FCGI, CDR)
70
70packet decoders (HTTP, FCGI, CDR)
70
70packet decoders (HTTP, FCGI, CDR)
using gen_server or gen_fsm
70
70servers directly in the erl shell
Erlang apart from netcat, perl, etc. in this regard
71
71amazing features
every day
72
72heard about Erlang? It’s true
coordination
tracing
prototypes”
github.com
available at erlang.org
73
73Erlangers to buy into
something bad. Always.
doesn’t always fly
not so new) always want to try to handle the errors instead
74
74early adopter customers
something goes wrong
the crash/recovery
can debug and repair live systems
75
75code upgrade, hot code loading
memory) and Disk ets (persistent)
management system
76
76Smalltalk
77
77Smalltalk
77
Java, Internet
7778
Java
7878
Multicore, Cloud Java
7878
Multicore, Cloud Java
■ Thread & Locks ■ Interfaces with Fixed API ■ Defensive Code ■ RPC/RMI ■ Boilerplate code for persistence
7878
Multicore, Cloud Java
■ Thread & Locks ■ Interfaces with Fixed API ■ Defensive Code ■ RPC/RMI ■ Boilerplate code for persistence
Anomalies
7878
Multicore, Cloud Java
■ Processes w/ state containment ■ Protocols ■ Let it Fail ■ Async Messaging ■ Send & store simple Data
Multicore, Cloud, Actors
Also: http://learnyousomeerlang.com/
79
79