210
Chapter 11
I
Where to go next
arr2
now contains
[2, 4, 6, 8, 10]
—every
element in
arr1
was
doubled! Doubling an element is pretty fast. But suppose you apply a
function that takes more time to process. Look at this pseudocode:
>>> arr1 = # A list of URLs
>>> arr2 = map(download_page, arr1)
Here
you have a list of URLs, and you want to download each page and
store the contents in
arr2
. This could take a
couple of seconds for each
URL. If you had 1,000 URLs, this might take a couple of hours!
Wouldn’t it be great if you had 100 machines, and
map
could
automatically spread out the work across all of them? Then you would
be downloading 100
pages at a time, and the work would go a lot faster!
This is the idea behind the “map” in MapReduce.
Dostları ilə paylaş: