Difference between AKKA and Fork/Join Framework

758 views
Skip to first unread message

nicksj...@gmail.com

unread,
Jul 13, 2013, 3:58:51 PM7/13/13
to akka...@googlegroups.com
Hello All,

I have couple of queries associated with AKKA
1. Difference between AKKA and Fork/Join Framework?
2. Does Akka uses fork/join framework internally for creating actors?
3. What different types of design patterns are used in creating AKKA
4. What are the real world problems of Multi-threaded application which are solved by AKKA?
5. Is AKKA faster than Fork/Join Framework.


Thank you all in advance

Regards
Nicks

James Bellenger

unread,
Jul 13, 2013, 4:43:00 PM7/13/13
to akka...@googlegroups.com
Answers to some of these questions can be found in the Dispatchers section:


--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

nicksj...@gmail.com

unread,
Jul 14, 2013, 9:24:41 AM7/14/13
to akka...@googlegroups.com
Hello James,


1. I have read the documentation, but documentation says it uses Fork/Join Executor Framework and also usees Thread Pool Executor framework. Can you let me know which one is used in each Dispatcher ?
2. If they are using Thread Pool Executor then why did they built because the pitfalls of Thread Pool Executor causes the thread to go in waiting state or blocked when their is huge load on the system?
3. Can anybody show me flow diagram of AKKA. How messages are passed across the system what all internal messages are being called and which components are called ?
4. Does AKKA uses User Level Threads. Can you please give me a real world Java example which shows the use of User Level Threads and Kernel Level Threads.? 

I am really not getting enough information on all the above queries can somebody please answer this questions in detail

Thanks in adavance

Regards
Nicks

Rafał Krzewski

unread,
Jul 14, 2013, 11:43:00 AM7/14/13
to akka...@googlegroups.com
Hello Nicks,

Akka documentation is very detailed, and if you find that something is lacking from the documentation, I reccomend that you examine the source code. It uses very lucid, idiomatic Scala, and I personaly find it quite pleasing to read. There is also an aboundance of articles and blog posts about Akka design out there in the internet. They are not that hard to find.
I'm sorry to say that, but you demand that Akka developers should do your homework for you, and that's not very polite.

Regads,
Rafał

nicks javaj2ee

unread,
Jul 14, 2013, 6:45:39 PM7/14/13
to akka...@googlegroups.com
Hello Rafal,

Thank you for your email.
I am reading the Akka Documentation but above mentioned doubts are being raised after reading the documentation that is reason I have came up with the question. I can download the source code and look at it. I think I am doing my homework very carefully and then only asking these questions very specifically. I am not expecting Akka Developers to do for me. If you know the answer then please share the answer or give me the links to my answer. If that still sounds not being polite then I am sorry it.

Regards
Nikhil


You received this message because you are subscribed to a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/y55QHmZViY4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.

√iktor Ҡlang

unread,
Jul 15, 2013, 4:18:59 AM7/15/13
to Akka User List
Hi Nicks,


On Sun, Jul 14, 2013 at 3:24 PM, <nicksj...@gmail.com> wrote:
Hello James,


1. I have read the documentation, but documentation says it uses Fork/Join Executor Framework and also usees Thread Pool Executor framework. Can you let me know which one is used in each Dispatcher ?

All Dispatchers except CallingThreadDispatcher (used for testing) can use _any_ ExecutorService, Akka ships with Configurators for FJP and TPE but you can use whichever you want.
 
2. If they are using Thread Pool Executor then why did they built because the pitfalls of Thread Pool Executor causes the thread to go in waiting state or blocked when their is huge load on the system?

 
3. Can anybody show me flow diagram of AKKA. How messages are passed across the system what all internal messages are being called and which components are called ?

This was recently posted to this mailinglist, looking at the archives can also be helpful for you: https://groups.google.com/forum/#!topic/akka-user/34SZYJo4xrw
 
4. Does AKKA uses User Level Threads. Can you please give me a real world Java example which shows the use of User Level Threads and Kernel Level Threads.? 

Akka uses JVM threads (java.lang.Thread): http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html
 

I am really not getting enough information on all the above queries can somebody please answer this questions in detail 

Thanks in adavance

I hope that answers it all.

Cheers,



--
Viktor Klang
Director of Engineering

Twitter: @viktorklang

nicks javaj2ee

unread,
Jul 16, 2013, 7:09:42 AM7/16/13
to akka...@googlegroups.com
Hello Victor,

Thank you for your reply.

I am still reading the AKKA Documentation. I am searching for answer in the documentation and even on the internet but couldn'f find answer to my question mentioned below
1. Difference between Dispatcher and Router, their is no where the separation being mentioned.

2 I have wrote one to understand AKKA.
 POC Details 
Its a UDP Client Server 

UDPServer. java

package com.akka.UDP;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

import com.akka.project.Pi.Worker;



import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.actor.UntypedActor;
import akka.actor.UntypedActorFactory;
import akka.routing.RoundRobinRouter;

public class UDPServer {
public static void main(String args[]) throws Exception
     {
  DatagramSocket serverSocket = new DatagramSocket(10001);
  byte[] receiveData = new byte[1024];
  byte[] sendData = new byte[1024];
  System.out.println("################ SERVER STARTED ######################## ");
  while(true)
  {
    DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
    serverSocket.receive(receivePacket);
    String sentence = new String( receivePacket.getData());
    System.out.println("RECEIVED: " + sentence);
    if(receivePacket!=null && receivePacket.getData().length > 0){
    UDPServer server = new UDPServer();
    String message = new String(receivePacket.getData());
    server.processMessage(4, message);
     
    }
  }
     }
 
public void processMessage(final int numberOfWorkers, final String message){
final ActorSystem system = ActorSystem.create("UDPMessageProcessing");
ActorRef master = system.actorOf(new Props(new UntypedActorFactory() {
     public UntypedActor create() {
       return new Master(numberOfWorkers, message, system);
     }
   }), "master");
master.tell(message, master);
}
 
static class Master extends UntypedActor{
private final int numberOfWorker;
private String message;
private final ActorRef workerRouter;
 
public Master(int numberOfWorker, String message, ActorSystem system){
this.numberOfWorker = numberOfWorker;
this.message = message;
workerRouter = this.getContext().actorOf(new Props(Worker.class).withRouter(new RoundRobinRouter(numberOfWorker)));
}
@Override
public void onReceive(Object arg0) throws Exception {
if(arg0 instanceof String){
String message = (String)arg0;
System.out.println("############## MESSAGE RECEIEVED BY MASTER  - "+ getSender().toString());
workerRouter.tell(new Work(message), getSender());
}else if(arg0 instanceof Work){
System.out.println("############ GOT THE RESPONSE FROM WORKER AND PROCESSED MESSAGE --- " + ((Work)arg0).getMessage());
}
else{
getContext().stop(getSelf());
System.out.println("#### IS ALIVE   -- " + getSelf().isTerminated());
unhandled(arg0);
}
}
}
 
public static class Worker extends UntypedActor {
/* public Worker(){
System.out.println("########################## WORKER " +  getSender().toString()); 
}*/
@Override
public void onReceive(Object arg0) throws Exception {
if(arg0 instanceof Work){
Work work = (Work) arg0;
                          System.out.println("########################## WORKER " +  getSelf().toString()); 
       System.out.println("###################### WORKER RECEIVED MESSAGE  -- " + work.getMessage());
       getSender().tell(work, getSelf());
}
else{
getContext().stop(getSelf());
System.out.println("#### IS WORKER ALIVE   -- " + getSelf().isTerminated());
unhandled(arg0);
}
}
}
 
static class Work{
private String message;
public Work(String message){
this.message = message;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
 
 
}


UDP Client :
package com.akka.UDP;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class UDPClient {
public static void main(String args[]) throws Exception
  {
     BufferedReader inFromUser =
        new BufferedReader(new InputStreamReader(System.in));
     DatagramSocket clientSocket = new DatagramSocket();
     InetAddress IPAddress = InetAddress.getByName("localhost");
     byte[] sendData = null;
     byte[] receiveData = new byte[1024];
     String sentence = inFromUser.readLine();
     sendData = sentence.getBytes();
     for (int i=1 ; i<10;i++){
     sendData = new byte[1024];
     String message = "Message "+i;
     sendData = message.getBytes();
     DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 10001);
     clientSocket.send(sendPacket);
     sendData = null;
     }
     clientSocket.close();
  }

}

Above mentioned code is error free but I am unable to understand one thing which prints out when I run the application.
Whenever System.out.println("########################## WORKER " +  getSelf.toString());  this line is executed it always prints "UDPMessageProcessing/user/$a$a"
I am expecting it to print something like " "UDPMessageProcessing/user/$a$b"
" which shows each time a different routee is executing the process?
Can anyone please let me know what wrong I am doing in this ?

Thanks in advance.

Regards
Nicks





You received this message because you are subscribed to a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/y55QHmZViY4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.

Akka Team

unread,
Jul 16, 2013, 7:42:19 AM7/16/13
to Akka User List
Hi Nicks,


I am still reading the AKKA Documentation. I am searching for answer in the documentation and even on the internet but couldn'f find answer to my question mentioned below
1. Difference between Dispatcher and Router, their is no where the separation being mentioned.

Dispatchers and Routers are intermediate-advanced tools, you should first start with plain actors, at least in my opinion.
 

2 I have wrote one to understand AKKA.
 POC Details 
Its a UDP Client Server 

If you want to play around with example code for learning, this should be your first stop:
http://letitcrash.com/post/55083687752/2-2-spotlight-getting-started-with-typesafe-activator

The above blog post links to Activator templates (some of them are Scala only at this point, but the Hello Akka example is available in Java). Activator is a nice tool that gets you started easily with various libraries including Akka, Play, etc. You can download it from here: http://typesafe.com/platform/getstartd
 
public class UDPServer {
public static void main(String args[]) throws Exception
     {
  DatagramSocket serverSocket = new DatagramSocket(10001);

Akka has its own UDP IO which fits the actor model better, see here:
  http://doc.akka.io/docs/akka/2.2.0/java/io.html
  http://doc.akka.io/docs/akka/2.2.0/java/io-udp.html
 
    serverSocket.receive(receivePacket);

You should avoid blocking, if possible.
 
 
public void processMessage(final int numberOfWorkers, final String message){
final ActorSystem system = ActorSystem.create("UDPMessageProcessing");

You should not create a separate ActorSystem for every request. ActorSystem is a heavyweight object, you should create separate actors instead. This code is analogous to launching a separate Tomcat instance for every Http request ;)
 
Above mentioned code is error free but I am unable to understand one thing which prints out when I run the application.
Whenever System.out.println("########################## WORKER " +  getSelf.toString());  this line is executed it always prints "UDPMessageProcessing/user/$a$a"
I am expecting it to print something like " "UDPMessageProcessing/user/$a$b"
" which shows each time a different routee is executing the process?
Can anyone please let me know what wrong I am doing in this ?

Because you create a completely fresh system instance for every incoming message. You should keep one system instance around for the lifetime of your application.

-Endre



--
Akka Team
Typesafe - The software stack for applications that scale
Blog: letitcrash.com
Twitter: @akkateam
Reply all
Reply to author
Forward
0 new messages