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.

Related Whitepaper:

Functional Programming in Java: Harnessing the Power of Java 8 Lambda Expressions

Get ready to program in a whole new way!

Functional Programming in Java will help you quickly get on top of the new, essential Java 8 language features and the functional style that will change and improve your code. This short, targeted book will help you make the paradigm shift from the old imperative way to a less error-prone, more elegant, and concise coding style that’s also a breeze to parallelize. You’ll explore the syntax and semantics of lambda expressions, method and constructor references, and functional interfaces. You’ll design and write applications better using the new standards in Java 8 and the JDK.

Get it Now!  

Leave a Reply

× 5 = twenty five

Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
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.

Sign up for our Newsletter

20,709 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books