Showing posts with label Akka. Show all posts
Showing posts with label Akka. Show all posts

Thursday, January 3, 2013

Akka Essentials Giveaway contest!


Year 2013 has begun and what better way to start then by participating in the contest organized by Packt Publishing.

The Prize


The prizes are 2 print copies and 2 ebooks of my new book Akka Essentials that was published couple of months back.

Akka Essentials will show you the current challenges with Java Scalability and concurrency model and how Akka’s Actor Model can help you design and build applications that are inherently scalable and fault-tolerant. Whether you are building new applications or want to refactor an existing application, you will learn the right techniques to build and scale up in no time.

This book is aimed at developers, architects who are building large distributed concurrent and scalable applications using Java/Scala.



What you will learn from Akka Essentials:
• Scale up and out your applications using dispatchers and remoting
• Build fault tolerance within your application
• Handle transactions within your application
• Unit test your Akka applications
• Integrate your Akka applications with existing enterprise systems using Zeromq
• Monitor the health of your Akka application

How to Win Akka Essentials

You can enter by writing a comment to this post explaining why you would like to have the book. The contest has already started and will end on January 31st 2013 at 11:59 PM GMT. Winners will be randomly chosen and notified by email, after termination of the contest. Please do not forget to leave your email id in the comment.

The contest is open to everybody in the world, however print copies are only available to residents of the US
and Europe.

Comments are moderated by me, so your comment will not appear immediately.

I wish all the contest participants good luck.

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

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
  • 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

Monday, March 26, 2012

Implementing Master Slave / Grid Computing Pattern in Akka

Master Slave pattern is a prime example of fault tolerance and parallel computation. The idea behind the pattern is to partition the work into identical sub tasks which are then delegated to Slaves. These slave node or instances will process the work task and send back the result to the master. The master will then compile the results received from all the slave nodes. Key here is that the Slave nodes are only aware on how to process the task and not aware of what happens to the output.

The Master Slave pattern is analogous to the Grid Computing pattern where a control node distributes the work to other nodes. Idea is to make use of the nodes on the network for their computing power. SETI@Home was one of the earliest pioneers in using this model.

I have build a similar example with difference being that worker nodes get started on Remote Nodes, Worker Nodes register with Master(WorkServer) and then subsequently start processing work packets. If there is no worker slave registered with Master(WorkServer), the master waits the workers to register. The workers can register at any time and will start getting work packets from there on.

Friday, March 2, 2012

What is Akka?

Before I delve into what is an Akka, let us take a step back to understand how the concept of concurrent programming has evolved in the application development world. The applications have evolved from being large monolithic procedures to a more object oriented model. With the advent of Java EE and Spring framework, the application design evolved into more of a process or task based design model. The EJBs or Pojo’s are designed to perform one single task. This model promoted the objects to be stateless (although state full session beans were allowed) in order to be able to handle the increasing load (aka scalable application). The overall business function request will get broken down to multiple beans (Ejbs or Pojos) which will process the information; the result from the beans will be aggregated and presented back to the requester. This model allowed the application to scale up.

Now, when the same model needed to be applied to the Java application that does not make use of EJBs or application server containers, the available choice of technology or technique was to use multi-threaded programming. Working with threads require a much higher level of programming skills, since dealing with state, locks , mutex etc is not easy skill. With Java EE 1.4 onwards, newer API in terms of ExecutionContext and Java 1.5 onwards concurrent data structure libraries (java.util.concurrent) were introduced. This allowed programmers to write programs that could be broken down into smaller tasks and run parallel on the underlying threads.

For an average java programmer, writing multi-threaded programs that could break a big process into smaller tasks and run those tasks in parallel to take advantage of the multiple cores is not so easy. Akka team abstracted this whole concept using an Actor model to another plane where writing programs that process tasks in parallel became slam dunk. The Akka abstraction model allowed programmers to write programs to take advantage of multiple cores and process hundreds of tasks in parallel. The Akka team borrowed concepts and techniques from ERlang to build “Let it Crash” fault tolerance model to allow applications to fail fast and recover from the failure as soon as possible.

Akka provides a scalable real time transaction processing library that allows your application to scale up, scale out and has fault tolerance.