I’m writing a MapReduce job that may end up with a huge number of values in the reducer. I am concerned about all of these values being loaded into memory at once.
Does the underlying implementation of the Iterable<VALUEIN> values load values into memory as they are needed? Hadoop: The Definitive Guide seems to suggest this is the case, but doesn’t give a “definitive” answer.
The reducer output will be far more massive than the values input, but I believe the output is written to disk as needed.
You’re reading the book correctly. The reducer does not store all values in memory. Instead, when looping through the Iterable value list, each Object instance is re-used, so it only keeps one instance around at a given time.
For example in the follow code, the objs ArrayList will have the expected size after the loop but every element will be the same b/c the Text val instance is re-used every iteration.
(If for some reason you did want to take further action on each val, you should make a deep copy and then store it.)
Of course even a single value could be larger than memory. In this case it’s recommended to the developer to take steps to pare the data down in the preceding Mapper so that the value is not so large.
UPDATE: See pages 199-200 of Hadoop The Definitive Guide 2nd Edition.