concept work in category akka

appears as: work, The work, works, work
Reactive Applications with Akka .NET

This is an excerpt from Manning's book Reactive Applications with Akka .NET.

Although Akka.NET itself and how it works might be new to many developers, its underlying principles have been in development for decades, in the form of the actor model. As part of the actor model, independent entities, known as actors, are responsible for performing work. You can have multiple different types of actors within a system, and each of these types can have multiple instances running in the system. Every actor runs independently of every other actor in the system, meaning that two running actors can’t directly interfere or interact with each other. Instead, each actor is supplied with a mailbox, which receives messages, and an address, which can be used to receive messages from other actors in the system. An actor sits idle and doesn’t do anything until a new message is received in the actor’s mailbox; at this point, the actor can process the message using its internal behavior. Its behavior is the brain of the actor and defines how it should respond to each message it receives. If an actor receives more than one message, the messages are queued up in the order in which they were received, and the actor processes each message sequentially. Each actor will only process a single message at a time, although multiple actors can process their respective messages at the same time. This allows you to create highly concurrent applications without having to concern yourself with the underlying multithreading infrastructure and code that’s typically required when developing concurrent applications. It’s important to note also that actors are completely isolated, meaning that any internal information or data owned by one actor isn’t accessible by anything other than that actor.

Rather than simply trying to work faster to free up resources for the next batch of work when it arrives, an alternative approach is to provide more resources and process work concurrently. This approach means you scale out resources rather than modify already provisioned resources. For example, if an online retailer sees an increased load, they make a second server available to serve a request, with clients being directed to whichever server is least busy. Although this won’t result in requests being processed any faster than they were previously, twice the amount of load will be handled. This approach, scaling out (refer back to figure 7.1), provides an easier means of scaling resources, and a greater ability to handle an increased load.

Akka in Action

This is an excerpt from Manning's book Akka in Action.

Can you use the common tools of today (threads and RPC) to satisfy these two goals? Scaling out with RPC and scaling up with low-level threading aren’t good ideas. RPC pretends that a call over the network is no different from a local method call. Every RPC call needs to block the current thread and wait for a response from the network for the local method call abstraction to work, which can be costly. This impedes the goal of using resources efficiently.

One of the immediate concerns with actor-based programming is how you model code that requires collaborators to work together when each unit of work is done in parallel. Collaboration implies some notion of process, and although there can be parallel processes, there will also be cases where it’s essential that certain steps happen after required prior steps have been completed. By implementing a few of the classic enterprise integration patterns (EIPs), we’ll show how Akka allows you to employ these design approaches while still making use of its inherent concurrency.

Figure 14.13. Deploying JobWorkers and broadcasting Work messages
Listing 14.15. Using the router to broadcast Work messages
class JobMaster extends Actor                    with ActorLogging                    with CreateWorkerRouter { #1   // inside the body of the JobMaster actor..   val router = createWorkerRouter #2   def receive = idle   def idle: Receive = {     case StartJob(jobName, text) =>       textParts = text.grouped(10).toVector       val cancel = system.scheduler.schedule(0 millis,                                              1000 millis,                                              router, #3                                              Work(jobName, self))       become(working(jobName, sender(), cancel))   }   // more code #1 - Mixes in CreateWorkerRouter trait #2 - Creates router #3 - Schedules a message to router !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[]"} !@%STYLE%@!