Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 8 MapReduce for distributed computing

It made me happy when I heard about parallelStream() in Java 8, that processes on multiple cores and finally gives back the result within single JVM. No more lines of multithreading code. As far as I understand this is valid for single JVM only.

But what if I want to distribute the processing across different JVMs on a single host or even multiple hosts? Does Java 8 include any abstraction for simplifying it?

In a tutorial at dreamsyssoft.com a list of users

private static List<User> users = Arrays.asList(
    new User(1, "Steve", "Vai", 40),
    new User(4, "Joe", "Smith", 32),
    new User(3, "Steve", "Johnson", 57),
    new User(9, "Mike", "Stevens", 18),
    new User(10, "George", "Armstrong", 24),
    new User(2, "Jim", "Smith", 40),
    new User(8, "Chuck", "Schneider", 34),
    new User(5, "Jorje", "Gonzales", 22),
    new User(6, "Jane", "Michaels", 47),
    new User(7, "Kim", "Berlie", 60)
);

is processed to get their average age like this:

double average = users.parallelStream().map(u -> u.age).average().getAsDouble();

In this case it is processed on single host.

My question is: Can it be processed utilizing multiple hosts?

E.g. Host1 processes the list below and returns average1 for five users:

new User(1, "Steve", "Vai", 40),
new User(4, "Joe", "Smith", 32),
new User(3, "Steve", "Johnson", 57),
new User(9, "Mike", "Stevens", 18),
new User(10, "George", "Armstrong", 24),

Similarly Host2 processes the list below and returns average2 for remaining five users:

new User(2, "Jim", "Smith", 40),
new User(8, "Chuck", "Schneider", 34),
new User(5, "Jorje", "Gonzales", 22),
new User(6, "Jane", "Michaels", 47),
new User(7, "Kim", "Berlie", 60)

Finally Host3 computes final result like:

average = (average1 + average2)  / 2

Using distributed architecture it can be solved like remoting. Does Java 8 have some simpler way to solve the problem with some abstraction for it?

I know frameworks like Hadoop, Akka and Promises solve it. I am talking about pure Java 8. Can I get any docummentation and examples for parallelStream() for multiple hosts?

like image 645
abishkar bhattarai Avatar asked Dec 05 '13 09:12

abishkar bhattarai


People also ask

Is MapReduce distributed computing?

MapReduce is a programming model and an associated implementation for processing and generating big data sets with a parallel, distributed algorithm on a cluster.

What is distributed reducing map?

MapReduce is a processing technique and a program model for distributed computing based on java. The MapReduce algorithm contains two important tasks, namely Map and Reduce. Map takes a set of data and converts it into another set of data, where individual elements are broken down into tuples (key/value pairs).

What is the use of map and reduce in Java 8?

Map Reduce Example in Java 8 It is used to implement MapReduce type operations. Essentially we map a set of values then we reduce it with a function such as average or sum into a single number.

What is Java MapReduce?

MapReduce is a Java-based, distributed execution framework within the Apache Hadoop Ecosystem. It takes away the complexity of distributed programming by exposing two processing steps that developers implement: 1) Map and 2) Reduce. In the Mapping step, data is split between parallel processing tasks.


1 Answers

Here is the list of features scheduled for Java 8 as of September 2013.

As you can see, there is no feature dedicated to standardizing distributed computing over a cluster. The closest you have is JEP 107, which builds on the Fork/Join framework in JDK 7 to leverage multi-core CPU's. In Java 8, you will be able to use lambda expressions to perform bulk operations on collections in parallel by dividing the task among multiple processors.

Java 8 is also scheduled to feature JEP 103, which will also build on Java 7 Fork/Join to sort arrays in parallel. Meanwhile, since Fork/Join is clearly a big deal, it evolves further with JEP 155.

So there are no core Java 8 abstractions for distributed computing over a cluster--only over multiple cores. You will need to devise your own solution for real distributed computing using existing facilities.

As disappointing as that may be, I would point out that there are still wonderful open-source third party abstractions over Hadoop out there like Cascalog and Apache Spark. Spark in particular lets you perform operations on your data in a distributed way through the RDD abstraction, which makes it feel like your data is just in a fancy array.

But you will have to wait for such things in core Java.

like image 80
Vidya Avatar answered Oct 04 '22 11:10

Vidya