About 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.

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 two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Leave a Reply

7 + = fifteen

Java Code Geeks and all content copyright © 2010-2015, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below: