Home » Java » Enterprise Java » Processing 10 million messages with Akka

About Munish Gupta

Munish Gupta
Munish K Gupta is a senior architect working in a leading IT services company. His experience is in building Online Portals, SaaS Platforms, CRM Solutions and Transaction Processing Systems. He is author of the book - Akka Essentials.

Processing 10 million messages with Akka

Akka Actors promise concurrency. What better way to simulate that and see if how much time it takes to process 10 million messages using commodity hardware and software without any low level tunings.I wrote the entire 10 million messages processing in Java and the overall results astonished me.

When I ran the program on my iMac machine with an intel i5 – 4 core, 4 Gb RAM machine and JVM heap at 1024Mb, the program processed 10 million machines in 23 secs. I ran the program multiple times and the average time was in the range of 25 secs. So the through put I received was almost in the range of 400K messages per second which is phenomenal.

The below picture explains the flow used to simulate the load generation scenario.

Caveat: Each message sends a response after 1 second which is not the right simulation for a real world scenario. The message processing will consume some resources on the heap and gc activity which are not accounted for, in this scenario.

The program uses overall direction from the post Akka actors : 10 millions messages processed (1s / message) in 75 seconds ! although without any messages throttling.

The code base for the program is available at the following location – https://github.com/write2munish/Akka-Essentials

The ApplicationManagerSystem creates the actors and pumps in the traffic to the WorkerActor

  private ActorSystem system;
  private final ActorRef router;
  private final static int no_of_msgs = 10 * 1000000;
  public ApplicationManagerSystem() {
   final int no_of_workers = 10;
   system = ActorSystem.create('LoadGeneratorApp');
   final ActorRef appManager = system.actorOf(
     new Props(new UntypedActorFactory() {
      public UntypedActor create() {
       return new JobControllerActor(no_of_msgs);
     }), 'jobController');
   router = system.actorOf(new Props(new UntypedActorFactory() {
    public UntypedActor create() {
     return new WorkerActor(appManager);
   }).withRouter(new RoundRobinRouter(no_of_workers)));
  private void generateLoad() {
   for (int i = no_of_msgs; i >= 0; i--) {
    router.tell('Job Id ' + i + '# send');
   System.out.println('All jobs sent successfully');

Once the messages are received by the WorkerActor, the responses are scheduled to be send after 1000 milli secs


 public class WorkerActor extends UntypedActor {
  private ActorRef jobController;
  public void onReceive(Object message) throws Exception {
    using scheduler to send the reply after 1000 milliseconds
     .scheduleOnce(Duration.create(1000, TimeUnit.MILLISECONDS),
       jobController, 'Done');
  public WorkerActor(ActorRef inJobController) {
   jobController = inJobController;

The response messages from the WorkerActor are send across to the JobControllerActor, that collects all the responses.

 public class JobControllerActor extends UntypedActor {
  int count = 0;
  long startedTime = System.currentTimeMillis();
  int no_of_msgs = 0;
  public void onReceive(Object message) throws Exception {
   if (message instanceof String) {
    if (((String) message).compareTo('Done') == 0) {
     if (count == no_of_msgs) {
      long now = System.currentTimeMillis();
      System.out.println('All messages processed in '
        + (now - startedTime)  1000 + ' seconds');
      System.out.println('Total Number of messages processed '
        + count);

Reference: Tutorial: Hibernate, JPA & Spring MVC – Part 2 from our JCG partner Munish K Gupta at the Akka Essentials blog.

(0 rating, 0 votes)
You need to be a registered member to rate this.
1 Comment Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
Andreas Haufler
7 years ago

Sorry, but I fail to see why this is so great or even an Akka achievement? Actors are a nice concept for distributed and highly concurrent systems. Still their concept is a perfect match for Erlang but only a more or less good one for Java at its design practices. However, it is anything but fast in itself. Just pumping 10.000.000 objects through a JVM can be way faster. Even the short program I wrote, using Sirius Async (http://sirius-lib.net) does this in 11s (on my laptop): https://gist.github.com/andyHa/77f7be2ce87ae06ca03f Using the all famous disruptor and off heap memory, this could be way… Read more »