Akka Flashcards
Akka is made up of
Modules that are distributed as JAR files
What does the Akka concept of ‘let it crash?’ anticipate
There will be cases of individual handlers failing to carry out their tasks, and it is prepared to reroute that work to avoid a catastrophic failure.
What happens if the failure occurs up the chain?
Underlings can carry on until a new supervisor arrives. There is no broken chain, and most importantly, it is no longer the duty of the developer to find all the ways that chain might break catastrophically and provide specialized handling for each case
Actors are lightweight because
They run on top of dispatchers
How many threads fit in 1GB of memory and how many actors
4096
2.7 Million
How do you get an actor reference to an actor in the hierarchy?
You use the actor path
actors are a lot like ___________ without the configuration and ________ ________
installation overhead
message queues
message broker
Messages are simple data structures that …
can’t be changed after they’ve been created,
or in a single word, they’re immutable.
Actors can receive messages one at a time and execute some behaviour whenever a
message is received. Unlike queues, they can
also send messages
What are the points made in the reactive manifesto
Blocking I/O limits opportunities for parallelism, so nonblocking I/O is preferred.
Synchronous interaction limits opportunities for parallelism, so asynchronous interaction is preferred.
Polling reduces opportunity to use fewer resources, so an event-driven style is preferred.
If one node can bring down all other nodes, that’s a waste of resources. So you need isolation of errors (resilience) to avoid losing all your work.
What two goals should we aim for in attempting to make applications scalable?
Complexity must stay as low as possible.
Resources must be used as efficiently as possible while you scale the application
Scaling out with ____ and scaling up with ____ are not good ideas
RPC
Low level threading
Why is scaling out with RPC not a good idea?
Every RPC call needs to bloc the current thread and wait for a response from the network. Impeded the goal of using resources efficiently.
Why is using a combination of RPC and threading not a good idea?
You need to know exactly where you scale up or scale out. (Increase in complexity)
Spinning up thousands of servers is simple today, but
the same cannot be said for programming them
Actors are nothing new at all, in and of themselves. It’s … that make them unique
It is the way that actors are provided in Akka to scale applications both up and out on the JVM
This type of database is often called a journal
when changes are kept as a sequence of events
The technique of storing changes as a sequence of events is called
event sourcing
How can event sourcing be kept consistent across two servers?
sharding or partitioning
Most general purpose programming languages are written in sequence. A ________ ______ ____ is required to bridge the gap between sequential definition and parallel execution
concurrent programming model
Whereas parallelization is all about executing processes simultaneously, concurrency concerns itself with
defining processes that can function simultaneously, or can overlap in time, but don’t necessarily need to run simultaneously.
An actor is a lightweight process that has only four core operations:
create, send, become, and supervise
Any actor can be a supervisor but
only for actors that it creates itself
How are actors decoupled?
on three axes - namely
- Space / location
- Time
- Interface
What happens when an actor is decoupled in space
An actor gives no guarantee and has no expectation about where another actor is located
What happens when an actor is decoupled in time
An actor gives no guarantee and has no expectation about when its work will be done
What happens when an actor is decoupled from interface - that is it has no defined interface
The actor has no expectation about which messages other components can understand.
The first thing that every Akka application does is …
Create the Actor System
Which actors can the actor system create
The so called top-level actors
The actor system can create so called top-level actors, and it’s a common pattern to
Create only one top-level actor for all actors in the application. The Supervisor actor that monitors everything
An ActorSystem returns an address to create the top-level actor instead of the actor itself. This is called an
ActorRef
An ActorSystem returns an address to the created top-level actor instead of the actor itself. This address is called an ActorRef. The ActorRef can be used to send messages to the actor. This makes sense when you think about the fact that
the actor could be on another server
Sometimes you would like to look up an actor in the actor system this is where _____ _____ come in.
Actor Paths come in
You could compare the hierarchy of actors to a URL path structure. Every actor has a name. This name needs to be …
unique per level in the hierarchy: two sibling actors can’t have the same name
All actor references can be located directly by
an actor path (absolute or relative)
What does a dispatcher do?
pushes the messages in the mailbox through the actors
The type of dispatcher determines …
which threading model is used to push the messages through
All kinds of dispatchers can be configured in some way, and you can allocate a dispatcher to an
- actor
- a specific group of actors
- all of the actors in a system
When you send a message to an actor, all you are really doing is
leaving a message behind in its mailbox. Eventually a dispatcher will push it through the actor
Per the REST conventions, a GET whose URL ends with an entity type should return
a list of known instances of that entity
Why is
implicit val ec = system.dispatcher
needed in order to call
Http().bindAndHandle
bindAndHandle is asynchronous and requires an implicit ExecutionContext
what happens after
implicit val system = ActorSystem()
the actor system is immediately available
When you define an implicit val with execution context it does what?
determines which execution context will be used by Future(s) in scope of its definition
Dispatchers implement the ExecutionContext interface and can thus be
used to run Future invocations etc.
an asynchronous method returns a ______ before it is completed
future
How would you program an actor to respond to a message assuming there were three types of message namely Larry, Curly and Mo
def receive = { case Larry(punch) => case Curly() => case Mo(something) => }
actors created with the context of another actor are
its children and subject to the parent actor’s supervision
what does
Http().bindAndHandle(api, host, port) do?
binds the routes defined in the RestApi (api) to the HTTP server It is asynchronous so it returns a 'future' before it is completed
Services interfaces, as they grow, need
more sophisticated routing of requests
Actors exist in a supervision hierarchy - what does this mean
each actor has a supervisor and can have one or several child actors for which it is responsible
An actor can send and receive messages of any kind using the _______ method
receive
An actor can send and receive messages of any kind using the receive method, which is a so-called partial function that uses …
Scala’s pattern matching to figure out which case statement will deal with the incoming message.
What is a partial function?
A partial function is a function that does not provide an answer for every possible input value it can be given
Since the ’90s, nothing much has changed in how programming languages support networking, either.
Many technologies still essentially use ____________ to communicate over the network
RPC (remote procedure calls)
One doomsday scenario is where you’d need to pay increasingly more for more underutilized resources. Another nightmare scenario is
where the complexity of the application shoots through the roof when more resources are added.
Spinning up thousands of servers is simple today, but
the same cannot be said for programming them
It shouldn’t matter if we send a message locally on one server or remotely to another. So we need _______________________________ It will also need to ________________________________. This is
one of the things that _______ does for you.
- some service that takes care of sending the messages to actors on other servers if necessary.
- It will also need to keep track of where actors live and be able to provide references so other servers can communicate with the actors.
- Akka
This is the biggest impediment to building applications that can recover from failure and scale according to demand.
Coupling components in location, time, and interface is the biggest impediment to building applications that can recover from failure and scale according to demand.
The messages that an actor can receive or send back on a request are bundled together in
the actors’ companion object
If an actor is created using the system - as in
createBoxOffice = system.actorOf(BoxOffice.props, BoxOffice.name) how are the child actors created?
Using their context
CreateTicketSeller = context.actorOf(TicketSeller.props(name), name)
What does a materializer do?
makes actors execute a graph to produce results
A graph, in its simplest form, consists of
a source that provides elements, and a sink that consumes elements.