ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalCOMP3139Map Reduce
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    COMP3139

    Parallel & Distributed Computing

    Progress0 / 33 done
    Topics33
    1Introduction to Parallel and Distributed Systems2Why Use Parallel and Distributed Systems?3Speedup and Amdahl's Law
    4Multi Processors (Shared Memory)5Networks of Workstations (Distributed Memory)6Clusters (Latest Variation)
    7Threads and Shared Memory8Processes and Message Passing9Distributed Shared Memory (DSM)10Distributed Shared Data (DSD)11Parallel Algorithms12Concurrency and Synchronization13Data and Work Partitioning14Common Parallelization Strategies15Granularity16Load Balancing
    17Parallel Search18Parallel Sorting19Shared-Memory Programming20Threads in Shared-Memory Programming21P Threads22Locks and Semaphores23Distributed-Memory Programming24Message Passing25Map Reduce26Distributed-Memory Programming with PI27Google's Map Reduce28Hadoop29Other Parallel Programming Systems30Tread Marks31Distributed Shared Memory
    32Scoped Behavior and Abstract Data Types
    33Process Templates
    9 min read
    Topic 25 of 33
    Topic Study Note Illustration
    25

    Map Reduce

    MapReduce is a powerful programming model for processing large-scale data across distributed systems. It was popularized by Google and is widely used in frameworks like Hadoop for...

    MapReduce

    MapReduce is a powerful programming model for processing large-scale data across distributed systems. It was popularized by Google and is widely used in frameworks like Hadoop for big data processing. The model is designed to handle vast amounts of data by breaking the problem into smaller, manageable tasks that can be executed in parallel across a large number of machines (nodes).

    The basic idea of MapReduce is to divide a task into two main phases: Map and Reduce, which can be executed in parallel across many machines in a distributed system. This approach allows developers to focus on the logic of their program while abstracting away the complexities of parallelism and distribution.


    The MapReduce Model

    1. Map Phase:

      • In the Map phase, the input data is divided into chunks, and each chunk is processed by a "mapper" function.
      • The mapper takes an input pair (key-value), processes it, and outputs a set of intermediate key-value pairs.
      • Each mapper runs independently and in parallel on different chunks of the input data.
    2. Shuffle and Sort Phase:

      • After the Map phase, the system performs a shuffle and sort step, where the key-value pairs generated by the mappers are grouped by their key.
      • This step ensures that all values associated with the same key end up in the same place (the same reducer).
    3. Reduce Phase:

      • In the Reduce phase, each reducer processes the intermediate key-value pairs generated in the shuffle and sort phase.
      • The reducer receives a key and a list of all values associated with that key. It aggregates, filters, or performs some other operation on the values to produce a final output.
    4. Final Output:

      • The output from the reduce phase is the final result of the MapReduce job, which can then be stored or used for further processing.

    Key Concepts in MapReduce

    1. Input Data:
      The input data is typically a large dataset that needs to be processed. The data is usually stored across multiple machines in a distributed system (like HDFS in Hadoop). The input is divided into chunks, and each chunk is processed by a separate mapper.

    2. Map Function:

      • The Map function takes an input pair (key, value) and produces a set of intermediate key-value pairs.
      • For example, if you're counting the frequency of words in a text file, the key could be a word, and the value could be the count (usually 1).

      Example of a Map Function (Word Count):

      def map_function(key, value):
          for word in value.split():
              yield word, 1  # Emit word as key and 1 as the value
      
    3. Shuffle and Sort:

      • This step involves sorting and grouping the intermediate key-value pairs by their key. The system automatically handles this step.
      • After the map phase, the system needs to ensure that all occurrences of the same key are sent to the same reducer, which is why sorting and shuffling are important.
    4. Reduce Function:

      • The Reduce function takes a key and a list of values associated with that key. The reducer processes this list and generates the final output for that key.
      • In a word count example, the reducer will sum up the values (the word counts) for each key (word).

      Example of a Reduce Function (Word Count):

      def reduce_function(key, values):
          total_count = sum(values)  # Sum the counts for each word
          return key, total_count
      
    5. Output:
      The final output of the reduce phase is typically written to disk or returned for further processing. In Hadoop, for example, the output can be stored in the HDFS.


    Example: Word Count Using MapReduce

    Let's take the classic word count example where we want to count the number of occurrences of each word in a large text file.

    1. Map Phase:

    The map function takes each line of the text as input. It splits the line into words and emits each word with a value of 1 (indicating that one occurrence of the word has been found).

    def map_function(key, value):  # key: line number, value: line text
        for word in value.split():
            yield word, 1  # Emit each word with a count of 1
    

    2. Shuffle and Sort Phase:

    This phase groups the intermediate key-value pairs produced by the mappers. All pairs with the same key (word) are grouped together and sent to the same reducer. For example, the key-value pair ("apple", 1) might appear multiple times, once for each occurrence of "apple" in the input data.

    3. Reduce Phase:

    The reduce function takes the list of values associated with each key (i.e., the list of counts for each word) and reduces them by summing them up.

    def reduce_function(key, values):
        total_count = sum(values)  # Sum the counts for each word
        return key, total_count
    

    Final Output:

    The output of the MapReduce job will be a list of words and their counts, for example:

    ("apple", 5)
    ("banana", 3)
    ("cherry", 10)
    

    Advantages of MapReduce

    1. Scalability:
      MapReduce can process huge amounts of data by distributing the work across many machines in a cluster. It is designed to scale horizontally, meaning it can handle datasets ranging from gigabytes to petabytes.

    2. Fault Tolerance:
      MapReduce is highly fault-tolerant. If a node fails during the computation, the system can automatically restart the failed task on another node without any loss of data.

    3. Simplicity:
      The MapReduce model abstracts away the complexities of parallelism and distribution, making it easier for developers to write programs that can run on large clusters.

    4. Parallelism:
      MapReduce enables parallel processing of data. Each map operation is independent of the others, and each reduce operation can also be run in parallel across many machines. This parallelism leads to massive performance gains on large datasets.

    5. Flexibility:
      While the two core operations in MapReduce are Map and Reduce, developers can use custom operations to fit specific problems. This flexibility allows MapReduce to be applied to a wide range of problems beyond just word counting, such as sorting, indexing, and data mining.


    Challenges of MapReduce

    1. Performance Overhead:
      The shuffle and sort phase can introduce performance bottlenecks, especially when there is a large amount of intermediate data being exchanged between mappers and reducers.

    2. Complexity for Certain Tasks:
      While the MapReduce model is powerful, certain types of algorithms (like those involving complex data dependencies or iterative processes) are not well suited for MapReduce and might require a different paradigm.

    3. Limited Control over Parallelism:
      MapReduce abstracts away most of the control over parallelism, which might not be ideal for some applications that require fine-grained control over task execution.

    4. I/O Overhead:
      Since MapReduce often involves large-scale data transfer between nodes (especially during the shuffle phase), the amount of I/O involved can slow down performance if not optimized.


    MapReduce Frameworks

    Several frameworks have been developed to implement the MapReduce model efficiently. The two most well-known are:

    1. Hadoop:
      Apache Hadoop is an open-source framework that allows for the distributed processing of large datasets. It is the most popular implementation of the MapReduce programming model and includes tools like HDFS (Hadoop Distributed File System) for storing data and YARN (Yet Another Resource Negotiator) for managing resources.

    2. Spark:
      Apache Spark is another distributed data processing framework that builds on the MapReduce model but allows for more complex operations. It provides in-memory processing and is often faster than Hadoop's MapReduce for certain tasks. Spark can run on top of Hadoop, utilizing HDFS for storage, or it can run on other systems like Amazon S3.


    Example of MapReduce in Hadoop

    Here’s a simplified outline of how you would run the word count example in Hadoop:

    1. Map Function:
      The map function emits a pair of (word, 1) for each word found in the input text.

    2. Shuffle and Sort:
      The Hadoop framework automatically groups the intermediate pairs by key (word) and sorts them.

    3. Reduce Function:
      The reduce function receives each word and a list of counts, and sums them to produce the total count for each word.

    4. Execution:
      You would write the map and reduce functions in Java (or another supported language), submit the job to Hadoop, and it would automatically distribute the computation across multiple nodes.


    Conclusion

    MapReduce is a powerful tool for processing large datasets across distributed systems. It simplifies the process of writing parallel applications by dividing the problem into two core steps—map and reduce—allowing for easy parallelization of tasks like data analysis, word counting, and log processing. Though it offers significant advantages in scalability and fault tolerance, it also comes with challenges related to performance overhead and limited flexibility for certain types of problems. MapReduce remains a fundamental concept in big data processing and is widely used through frameworks

    ← Previous topic 24
    Message Passing
    Next topic 26 →
    Distributed-Memory Programming with PI

    Past Papers

    Open this section to view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    9mremaining
    1.5kwords
    Intermediatelevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Parallel & Distributed Computing