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"
[..]
The key in making great and growable systems is much more to design how its modules communicate rather than what their internal properties and behaviors should be.
[..]
-- Alan Kay
http://wiki.c2.com/?AlanKayOnMessaging
https://computinged.wordpress.com/2010/09/11/moti-asks-objects-never-well-hardly-ever/
foo = Foo()
bar = Bar()
try:
bar.do_thing(foo.get_inner_state())
except:
# What state is 'foo' in?
An Actor Can
actor Foo
var some_state: U64 = 0
be update(value: U64) =>
some_state = some_state + value
let new_actor = Foo.create()
new_actor.update(some_state)
hey sup
nm u
nm
Time
hey sup
nm u
nm
Time
hey :)
hi :)
hey sup
....
k nvm
Time
hey sup
Send Message
Await Response
Give up
Handle it
hey sup
hey sup
ERROR
hey sup
ERROR
...
Circuit Breakers
Time
Route message through CB
Time out
Return error
Return error immediately
Time
Do this 1 thing
Do this 1 thing
k done
Scaling To One User
Receive task
For every task, create new actor, assign it the task
Send completed tasks back
Do these 1000 thing
k done
Scaling To 1000 Users
Do this 1 thing
Time
Receive task
For every task, create new actor, assign it the task
Send completed tasks back
Pony
Erlang
actor Player
let name: String
let env: Env
new create(name': String, env': Env) =>
name = name'
env = env'
be ping(opponent: Player) =>
env.out.print("Sending ping from " + this.name)
opponent.ping(this)
actor Main
new create(env: Env) =>
let player1 = Player.create("player1", env)
let player2 = Player.create("player2", env)
let player3 = Player.create("player3", env)
player1.ping(player2)
player1.ping(player3)
Sending ping from player1
Sending ping from player3
Sending ping from player2
Sending ping from player1
Sending ping from player1
Sending ping from player3
Sending ping from player2
Sending ping from player1
Sending ping from player3
Sending ping from player1
Sending ping from player1
Sending ping from player2
Sending ping from player1
Supervisor
Â
Â
Worker
r.i.p
i got this
Asset Authentication App
Input Queue
Output Queue
C*
REST API
Persistors
Router
Behavior Generator
Log Converter
C*
Output
Queue
C*
REST API
Input Queue
Output Queue
Persistors
Router
Behavior Generator
Log Converter
C*
Router
C*
Persistors
Persistors
Router
Behavior Generator
C*
C*
actor Router
var generators = BehaviorGeneratorPool
be route_message(msg: Datatype) =>
for thing_to_persist in msg.persist_stuff() do
let persistor = Persistor.create()
persistor.persist(thing_to_persist)
end
generators.gen(msg)
Persistors
Router
Behavior Generator
C*
actor Persistor
let connection: CassandraConnection
new create() =>
connection = CassandraConnection.create("some cassandra url idk")
be persist(data: SomeDatatype) =>
# validation, transformation, whatever
connection.store(data)
Persistors
Router
Behavior Generator
C*
Persistors
Router
Behavior Generator
C*
C*
Akka
public class SimpleActor extends UntypedActor {
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
public SimpleActor() {
log.info("SimpleActor constructor");
}
@Override
public void onReceive(Object msg) throws Exception {
log.info("Received Command: " + msg);
if (msg instanceof Command) {
final String data = ((Command) msg).getData();
final Event event = new Event(data, UUID.randomUUID().toString());
// emmit an event somewhere...
} else if (msg.equals("echo")) {
log.info("ECHO!");
}
}
}
Companies Using Akka In Production
http://doc.akka.io/docs/akka/2.0.4/additional/companies-using-akka.html
We saw a perfect business reason for using Akka. It lets you concentrate on the business logic instead of the low level things. It’s easy to teach others and the business intent is clear just by reading the code. We didn’t chose Akka just for fun. It’s a business critical application that’s used in broadcasting.
Our Akka journey started as a prototyping project, but Akka has now become a crucial part of our system.
The Actor model has simplified a lot of concerns in the type of systems that we build and is now part of our reference architecture. With Akka we deliver systems that meet the most strict performance requirements of our clients in a near-realtime environment. We have found the Akka framework and it's support team invaluable.
Persistors
Router
Behavior Generator
C*
C*
REST API
Input Queue
Output Queue
Persistors
Router
Behavior Generator
Log Converter
C*
C*
REST API
C*
Input Queue
Router
Log Converter
Persistors
C*
REST API
Input Queue
Output Queue
Persistors
Router
Behavior Generator
Log Converter
C*