concept service in category akka

This is an excerpt from Manning's book Reactive Applications with Akka .NET.
Over the past several decades, computers and the internet have moved from a position of relative obscurity to being central to many aspects of modern life. We now rely on the internet for all manner of day-to-day tasks, including shopping and keeping in contact with friends and family. The proliferation of computers and devices capable of accessing the internet has increased pressure on software developers to create applications that are able to withstand this near-exponential growth: we must develop applications that can meet the demands of a modern populace dependent on technology. Demands range in scope from providing instantly available information to users, to services that are resilient to issues they might encounter from increased usage or an increased likelihood of failure, which may be caused by factors entirely outside of our control. When this is twinned with the demands of a rapidly evolving company trying to beat the competition to find gaps in an ever-changing marketplace, applications must not only satisfy demands imposed by users but also be sufficiently malleable that they can be rapidly adapted and modified to fill those gaps.
For example, in the world of e-commerce, more and more retailers are providing products and services through online stores. Online shopping has grown, with more consumers opting to use the internet for the majority of their shopping. This has led to a situation in which online retailers are in direct competition with each other. Although this level of competition benefits consumers who can access readily available products with competitive pricing, it puts a huge amount of pressure on retailers to ensure that their online user experience (UX) is near-perfect; otherwise, customers can easily transfer their business to competitors. Research indicates that when consumers encounter errors and excessive page-loading times, they move to competitors with friendlier websites.

This is an excerpt from Manning's book Reactive Design Patterns.
The previous two sections introduced reasons for distributing the system across several machines, computing centers, or possibly even continents, matching the scope and reliability requirements of the application. The foremost purpose of this exercise is to build an email service for end users, though, and for them the only metric that counts is whether the service does what they need when they need it. In other words, the application must respond quickly to any request a user makes.
A failure is an unexpected event within a service that prevents it from continuing to function normally. A failure will generally prevent responses to the current, and possibly all following, client requests. This is in contrast with an error, which is an expected and coded-for condition—for example an error discovered during input validation—that will be communicated to the client as part of the normal processing of the message. Failures are unexpected and will require intervention before the system can resume at the same level of operation. This does not mean that failures are always fatal, rather that some capacity of the system will be reduced following a failure. Errors are an expected part of normal operations, are dealt with immediately and the system will continue to operate at the same capacity following an error.
With test cases being written in an asynchronous fashion, you can revisit the latency percentile verification from another angle. The framework could allow the user to describe the desired response characteristics in addition to the test code and then automatically verify those by running the code multiple times in parallel. Doing so sequentially would be prohibitively expensive in many cases—you would not voluntarily have tested 10,000 iterations of the EchoService in the sequential version in listing 11.5—and, as discussed, it also would not be a realistic measurement. Going back to the SLA test of the echo service in listing 11.7, the test framework would replace the custom ParallelSLATester Actor that was used to communicate with the service under test.
Listing 11.16. Using a request–response factory to generate test traffic
async { val echo = echoService() val gauge = new LatencyTestSupport(system) val latenciesFuture = gauge.measure(count = 10000, maxParallelism = 500) { i => val message = s"test$i" SingleResult((echo ? (Request(message, _))), Response(message)) } val latencies = await(latenciesFuture, 20.seconds) latencies.failureCount should be(0) latencies.quantile(0.99) should be < 10.milliseconds }This is possible because the interaction between the test and the service is of a specific kind: you are performing a load test for a request–response protocol. In this case, you only need a factory for request–response pairs that you can use to generate the traffic as needed, and the shape of the traffic is controlled by the parameters to the measure() method. The asynchronous result of this measurement is an object that contains the actual collections of results and errors that the 10,000 individual tests produced. These data can then easily be analyzed in order to assert that the latency profile fulfills the service-level requirements.
Another issue can arise with testing asynchronous services: due to the inherent freedom of when to reply to a request, we can imagine services that reply only after a certain time has passed or that trigger the periodic execution of some action. All such use cases can be modeled as external services that arrange for messages to be sent at the right times so that other services can depend on them for their scheduling needs.
The difference between testing the timing behavior of a service versus using timeouts for verifying its correctness is illustrated in figure 11.1. If you want to assert that the correct answer is received, you choose a timeout that bounds the maximal waiting time such that normally the test succeeds even if the execution is delayed much longer than would be expected during production use. Testing a service for its timing shifts the aspect of time from a largely ignored bystander role into the center of focus: you now need to put more stringent limits on what to accept as valid behavior, and you may need to establish lower bounds as well.
In the previous listing, requests are fired one by one, so the service will not experience any load during this procedure. The obtained latency values will therefore reflect the performance under ideal conditions; it is likely that under nominal production conditions, the timings will be worse. In order to simulate a higher incoming request rate—corresponding to multiple simultaneous uses of the same service instance—you need to parallelize the test procedure, as shown in figure 11.2. The easiest way to do this is to use Futures.

This is an excerpt from Manning's book Akka in Action.
The database is really getting hammered at this point. We find out that the automated polling of the database together with the Mentions component are causing performance problems with the database. We separate out the Mentions component as a service and give it its own database, which contains the notifications table and a copy of the users table, kept up to date with a database synchronization job, as shown in figure 1.7.
The Supervisor decides what should happen when components fail in the system. It could, for example, decide that the chat application continues when the Mentions component and Notify actor have crashed, since they’re not critical components. The Supervisor gets notified with special messages that indicate which actor has crashed, and for what reason. The Supervisor can decide to restart an actor or take the actor out of service.
Any actor can be a supervisor, but only for actors that it creates itself. In figure 1.19 the TeamFinder actor supervises the two connectors for looking up contacts. In this case it could decide to take the OutlookContacts actor out of service because it failed too often. The TeamFinder will then continue looking up contacts from Google only.
Listing 10.8. Setup of the environment for the ReliableProxySample test
import scala.concurrent.duration._ import concurrent.Await import akka.contrib.pattern.ReliableProxy import akka.remote.testconductor.Direction class ReliableProxySample extends MultiNodeSpec(ReliableProxySampleConfig) with STMultiNodeSpec with ImplicitSender { import ReliableProxySampleConfig._ def initialParticipants = roles.size "A MultiNodeSample" must { "wait for all nodes to enter a barrier" in { enterBarrier("startup") } "send to and receive from a remote node" in { runOn(client) { enterBarrier("deployed") val pathToEcho = node(server) / "user" / "echo" val echo = system.actorSelection(pathToEcho) #1 val proxy = system.actorOf( Props(new ReliableProxy(pathToEcho, 500.millis)), "proxy") #2 ... Do the actual test } runOn(server) { system.actorOf(Props(new Actor { #3 def receive = { case msg:AnyRef => { sender ! msg } } }), "echo") enterBarrier("deployed") } enterBarrier("finished") } } } #1 - Creates direct reference to echo service #2 - Creates ReliableProxy tunnel #3 - Implements echo service !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[]"} !@%STYLE%@!

This is an excerpt from Manning's book Reactive Web Applications: With Play, Akka, and Reactive Streams.
Sometimes, it may not be possible to scale a service out, such as when communicating with a legacy application (for example, a mainframe system in a banking environment). In this case, we may need a different approach for dealing with load bursts to protect the legacy service from overload and avoid cascading failures.
Services that return future results are a bit more tricky to test than plain old synchronous results. Luckily most testing libraries have accepted that futures are here to stay and have included a few useful helpers. In the following examples we’ll look at how you can test futures with the specs2 library (http://etorreborre.github.io/specs2/), which is bundled by default with Play.