Design Pattern - Adding Instrumentation and other metrics collection to Akka Actors without polluting the business logic
Showing posts with label Actors. Show all posts
Showing posts with label Actors. Show all posts
Monday, November 18, 2013
Wednesday, January 2, 2013
Software Transactional Memory (STM)
The Actor Model is based on the premise of small independent processes working in isolation and where the state can be updated only via message passing. The actors hold the state within themselves, but the asynchronous message passing means there is no guarantee that a stable view of the state can be provided to the calling components. For transactional systems like banking where account deposit and withdrawal need to be atomic, this is a bad fit with an Actor Model.So, if your Akka applications need to be implementing a shared state model and providing a consensual, stable view of the state across the calling components, Software Transactional Memory (STM) provides the answer.
STM provides a concurrency-control mechanism for managing access to shared memory. STM makes use of two concepts – optimism and transactions to manage the shared concurrency control.
STM provides a concurrency-control mechanism for managing access to shared memory. STM makes use of two concepts – optimism and transactions to manage the shared concurrency control.
- Optimism means that we run multiple atomic blocks in parallel, assuming there will be no errors. When we are done, we check for any problems. If no problems are found, we update the state variables in the atomic block. If we find problems then we roll back and retry. Optimistic concurrency typically provides better scalability options than any other alternate approaches.
- Secondly, STM is modeled on similar lines of database transaction handling. In the case of STM, the Java heap is the transactional data set with begin/commit and rollback constructs. As the objects hold the state in memory, the transaction only implements the following characteristics – atomicity, consistency, and isolation.
Friday, December 28, 2012
Adding Turbchargers to JEE Apps
One of the key roles, I play is evangelizing Akka within my local community. As part of the discussions, the question/doubt usually in people's mind is how can Akka provide better scalability and concurrency against a well written Java/JEE application. Since the underlying hardware/JVM remains the same, how can the actor model ooze out more power than the traditional JEE applications. In order to showcase the skeptics we decided to do small test where we take an existing JEE Web application, remodel the business logic to make use of the actor model and run tests against the same.
DayTrader Application
DayTrader is a benchmark application built around the paradigm of an online stock trading system. The application allows users to login, view their portfolio, lookup stock quotes, and buy or sell stock shares. DayTrader not only serves as an excellent application for functional testing, but it also provides a standard set of workloads for characterizing and measuring application server and component level performance.
DayTrader is built on a core set of Java EE technologies that includes Java Servlets and JavaServer Pages (JSPs) for the presentation layer and Java database connectivity (JDBC), Java Message Service (JMS), Enterprise JavaBeans (EJBs) and Message-Driven Beans (MDBs) for the back-end business logic and persistence layer.
More information about DayTrader is available here.
DayTrader Application
DayTrader is a benchmark application built around the paradigm of an online stock trading system. The application allows users to login, view their portfolio, lookup stock quotes, and buy or sell stock shares. DayTrader not only serves as an excellent application for functional testing, but it also provides a standard set of workloads for characterizing and measuring application server and component level performance.
DayTrader is built on a core set of Java EE technologies that includes Java Servlets and JavaServer Pages (JSPs) for the presentation layer and Java database connectivity (JDBC), Java Message Service (JMS), Enterprise JavaBeans (EJBs) and Message-Driven Beans (MDBs) for the back-end business logic and persistence layer.
More information about DayTrader is available here.
Tuesday, May 8, 2012
Using TestKit with Java
Unit testing toolkit is provided via TestKit in Akka. The scala side of unit testing is well covered. For java, TestKit provides limited constructs. The various examples implemented by Ray Roestenburg have been ported to Java world, with couple of more scenario's added. This can be good starting point for Java programmers to start unit testing their actors.
Let’s check out some testing code which tests out the following different set of actors
Let’s check out some testing code which tests out the following different set of actors
- Echo Actor – responds back with whatever is passed to the actor
- Forwarding Actor – forwards the message to another actor
- Sequencing Actor – replies back in a series of messages but assuming we are interested in one
- Filtering Actor – replies back for certain messages and ignores the others
- Boom Actor – throws an exception when a message is send
- Supervisor Actor – manages an another worker actor, and based on the exception thrown by the worker actor, applies the appropriate supervisor strategy
Thursday, March 15, 2012
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.
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.
Wednesday, March 14, 2012
Word Count MapReduce with Akka
In my ongoing workings with Akka, i recently wrote an Word count map reduce example. This example implements the Map Reduce model, which is very good fit for a scale out design approach.
Flow
Flow
- The client system (FileReadActor) reads a text file and sends each line of text as a message to the ClientActor.
- The ClientActor has the reference to the RemoteActor ( WCMapReduceActor ) and the message is passed on to the remote actor
- The server (WCMapReduceActor) gets the message. The Actor uses the PriorityMailBox to decide the priority of the message and filters the queue accordingly. In this case, the PriorityMailBox is used to segregate the message between the mapreduce requests and getting the list of results (DISPLAY_LIST)message from the aggregate actor.
- The WCMapReduceActor sends across the messages to the MapActor (uses RoundRobinRouter dispatcher) for mapping the words
- After mapping the words, the message is send across to the ReduceActor(uses RoundRobinRouter dispatcher) for reducing the words
- The reduced result(s) are send to the Aggregate Actor that does an in-memory aggregation of the result
Subscribe to:
Posts (Atom)