Here is my first blog post, where I described how to design actor based apps with a simple yet representative example. Anyone interested in Scala or Akka feel free to check it out.
For my case, i recently re-implemented an old Go code of an event gateway rest API with Scala + Akka HTTP. The reason is that we are a data engineering team, and none of us are familiar with Golang stack. We re-code it to improve maintainability.
The logic is extremely simple, the HTTP server just listens for POST requests, extract the payload in raw bytes and forward to Kafka.
Previously, with the Go (Gin) version, with 1 Core, we are able to reach 2.5K RPS. Now, with the Akka HTTP version, we could not go higher than 1.1K RPS.
The Akka HTTP version is 10.2.7.
Initially, we thought It could be the Kafka producer that slows the server down, but it wasn't, without the Kafka producer, RPS did not improve.
Is this a valid outcome? That we have to accept that Go(Gin) is >2x faster than Akka HTTP?
We are prototyping moving our services over to akka. Most things have been fine, but recently during load testing we've found that akka http is extremely CPU intensive. Even with fairly moderate amounts of load on the service we see ~90% normalized CPU usage is spent in akka.http.scaladsl.server.PathMatcher.
Our route is fairly simple:
pathPrefix("redacted" / Segment) { id =>
path("path1") {
put {
}
} ~
path("path2") {
put {
entity(as[String]) { raw =>
}
}
} ~
path("path3") {
put {
} ~
delete {
}
} ~
put {
parameter('parameter1.as[Boolean].?) { param =>
entity(as[String]) { raw =>
}
}
} ~
get {
} ~
delete {
}
}
CPU samples dont show any single blocker, just generally everything in pattern matching is slow. https://imgur.com/a/HGDWtIr
Hi everyone ! We wanted to share something we’ve been working on at Scalac - a 4-part series called "Building with Akka" The idea: show how to build a Customer Registry Application using Akka, covering: Setting up the project Modeling the domain Implementing views & APIs And finally, deployment We just published Part 4 (deployment!), but if you’re interested, you can start from the beginning and follow the whole process. Here’s the link if you want to check it out: https://scalac.io/blog/akka-platform-intro/
Akka and Kafka belong in two distinct technology camps that have only circumstantial similarities. Kafka is an event streaming platform, loosely residing in the Message-Oriented Middleware (MoM) space. Akka is an Actor Model — a mechanism for concurrent computation based on the concepts of agents, immutability, and message passing. The similarities are in the ‘message’ part. (Before anyone jumps in, there is no suggestion that the uses of Kafka are somehow limited to messaging; however, this is one of the prominent use cases.)
Kafka
Architecturally, Kafka is a lower-level construct that assists in the shipping and retention of events within a distributed application landscape. It embodies the ‘dump-pipes, smart endpoints’ metaphor, essentially acting as a highly-scalable persistent transport, which enables parallelism at the consumer level through the use of partially-ordered topics, comprising totally-ordered partitions. Kafka is not a programming model, and is completely application agnostic. In other words, you can implement Kafka producers and consumers in a variety of languages, providing you can obtain a c lient library written in that language. (And most languages do have a Kafka library.) The contracts between producers and consumers in the Kafka world are very rudimentary: producers deposit records onto an append-only topic, while consumers read records in a non-destructive manner that resembles a cursor. (Consuming a message does not delete it from the topic.)
Akka
Akka is a high-level application framework that obviates the need for traditional lock-based concurrency control primitives by employing the concept of actors — active entities that may be either durable or ephemeral, depending on the application context. Under the hood, an actor model maintains a set of inboxes (inbound message queues) and a scheduler for efficiently multiplexing a relatively small number of OS-level threads onto a much larger (possibly in the order millions) number of actors. Actors may form a range of topologies (hierarchical, pipeline or ad hoc) and communicate by passing messages. Although multiple actors may be operating concurrently, any given actor may only operate on one message at any given time. And it will remove the message when it has finished processing it. Providing an actor has sole ownership of some contentious resource, an actor model like Akka eliminates the need for exclusive and shared locks, by ensuring that only one process can operate (read from or write to) any given resource. Furthermore, an actor model is bound to a specific programming language.
¿Por qué no los dos?
Granted, the similarities between Kafka and Akka are superficial. However, Kafka may be used as the underlying transport for a distributed actor model. Generally, one does not cross-shop between the two; they are not exclusive — both may be used freely within an application for different roles.
In summary:
Both employ messages as an operating concept; although in Kafka, they are called ‘records’.
In both technologies, messages are ordered. Additionally, Kafka supports a further level of sharding where messages in a topic may follow a partial order. (Some records may appear mutually ordered, while others may be arbitrarily ordered.)
Kafka records are generally consumer-agnostic, in that they don’t target specific consumers, largely decoupling the producer and consumer ecosystems. Akka messages tend to target specific actors; however, they may also follow a broadcast topology.
Kafka records are not removed when consumed. An Akka message will be removed after an actor has dealt with it.
Records in Kafka are persistent. Akka's messages are normally transient; however, they can be made durable with Akka Persistence.
Kafka is designed for use in distributed systems. Akka operates within the confines of a single process. It may be applied in a distributed context when using a cluster; this effectively aggregates multiple actor systems into a single actor address space.
There are a lot of diagrams describing of what CQRS and ES mean. As usual there is a lack of complete examples enlightning what are the major "mosaic pieces" are and how to combine them altogether. In this demo I tried to create the complete distributed system of entities (Posts) that accept commands, persist events, change self-state and then replay those events in the EventListener to form the read sql view. You may wish to use it as a skeleton for your subj. architecture-based app. Any comments, suggestions and PRs are very welcome!