Chapter 9. Performance

Performance tuning an Akka application begins as it would with any application: first you isolate the areas of the application that have the highest cost in terms of time, and then you strive to reduce that cost.

Given that we always have a limited amount of time to apply to tuning, it makes good sense to begin with the greatest cost. Of course, it is difficult to know what this is without measurement. Therefore, as you would with any application, your first step in tuning Akka is generally to measure what takes a long time.

Many excellent performance and latency measurement tools exist for the Java Virtual Machine (JVM), and you can apply any of them to an Akka application. For instance, you can use the Gatling tool to measure the performance of an Akka application with an HTTP interface in the same way as any non-Akka application, and you can apply ScalaMeter to specific code segments.

In addition to the usual statistics on number of requests served, latency, and so on, there are a few special statistics unique to Akka that might be helpful.

Given that a slow consumer in an Akka application can become a serious runtime issue, you might need to measure mailbox size to ensure that any actor (or group of actors) isn’t growing its mailbox beyond reasonable bounds.

The time that it takes each message to be processed by a given actor is also very useful—when used in conjunction with information about the frequency of a message, it can help you narrow down ...

Get Applied Akka Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.