Docsity

Large Scale Algorithms, Study notes of Advanced Algorithms

Toggle sidebar
bg1
Large-Scale Algorithms
Large-scale algorithms are designed to solve gigantic, complex problems that cannot be
handled by a single computer or processor. These algorithms are characterized by their need for
multiple execution engines (like multiple processors, GPUs, or distributed systems) due to the
massive scale of data and processing requirements. Let’s break this down step by step.
Key Characteristics of Large-Scale Algorithms
1. Handles Huge Amounts of Data and Processing:
○ Large-scale algorithms are built to process terabytes or petabytes of data and
perform millions or billions of computations.
○ They use an available pool of resources (like multiple CPUs, GPUs, or distributed
systems) to handle these tasks efficiently.
2. Scalability:
○ As the problem becomes more complex or the data grows, the algorithm can
handle the increased load by adding more resources (e.g., more servers, GPUs, or
nodes in a cluster).
Terminologies in Large-Scale Algorithms
1. Latency
● Definition: The total time taken to perform a single computation from start to finish.
● Example: If a computation starts at time t₁ and ends at t₂, the latency is t₂ - t₁.
● Importance: Low latency is critical for real-time applications like video streaming or
online gaming.
2. Throughput
● Definition: The number of computations that can be performed simultaneously.
● Example: If 4 computations (C₁, C₂, C₃, C₄) can run at the same time, the throughput is 4.
● Importance: High throughput is essential for processing large datasets quickly.
3. Network Bisection Bandwidth
● Definition: The bandwidth (data transfer rate) between two equal parts of a network.
● Importance: In distributed systems, high network bisection bandwidth ensures fast
communication between nodes, which is crucial for parallel processing.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13

Partial preview of the text

Download Large Scale Algorithms and more Study notes Advanced Algorithms in PDF only on Docsity!

Large-Scale Algorithms

Large-scale algorithms are designed to solve gigantic, complex problems that cannot be handled by a single computer or processor. These algorithms are characterized by their need for multiple execution engines (like multiple processors, GPUs, or distributed systems) due to the massive scale of data and processing requirements. Let’s break this down step by step.

Key Characteristics of Large-Scale Algorithms

  1. Handles Huge Amounts of Data and Processing: ○ Large-scale algorithms are built to process terabytes or petabytes of data and perform millions or billions of computations. ○ They use an available pool of resources (like multiple CPUs, GPUs, or distributed systems) to handle these tasks efficiently.
  2. Scalability: ○ As the problem becomes more complex or the data grows, the algorithm can handle the increased load by adding more resources (e.g., more servers, GPUs, or nodes in a cluster).

Terminologies in Large-Scale Algorithms

  1. Latency

● Definition: The total time taken to perform a single computation from start to finish. ● Example: If a computation starts at time t₁ and ends at t₂ , the latency is t₂ - t₁. ● Importance: Low latency is critical for real-time applications like video streaming or online gaming.

  1. Throughput ● Definition: The number of computations that can be performed simultaneously. ● Example: If 4 computations (C₁, C₂, C₃, C₄) can run at the same time, the throughput is 4. ● Importance: High throughput is essential for processing large datasets quickly.
  2. Network Bisection Bandwidth ● Definition: The bandwidth (data transfer rate) between two equal parts of a network. ● Importance: In distributed systems, high network bisection bandwidth ensures fast communication between nodes, which is crucial for parallel processing.
  1. Elasticity

● Definition: The ability of the system to dynamically provision more resources (like servers or storage) when the workload increases. ● Example: Cloud platforms like AWS or Azure can automatically add more servers during peak traffic. ● Importance: Elasticity ensures that the system can handle sudden spikes in demand without crashing.

Amdahl's Law: Understanding Parallel Processing

Amdahl's Law helps us understand the limits of parallel processing. It states that not all parts of a computation can be parallelized. Some parts are inherently sequential and must run one after the other.

Example:

● Suppose a process P takes 11 seconds to run on a single node. ○ P₁ (Sequential Part): Takes 2 seconds (e.g., scanning files). ○ P₂ (Parallelizable Part): Takes 9 seconds (e.g., processing files). If we use 3 nodes to parallelize P₂ , the time for P₂ reduces to 3 seconds. However, P₁ remains 2 seconds because it cannot be parallelized. So, the total time for P becomes 2 + 3 = 5 seconds.

Amdahl's Formula:

● b: Fraction of the process that can be parallelized (e.g., 9/11 = 81.81%). ● s: Speedup factor (e.g., 3 nodes).

Challenges in Parallel Processing (GBL)

  1. Task Granularity ● Definition: Dividing a large job into smaller tasks for parallel execution. ● Challenge: If tasks are too large, parallelism is underutilized. If tasks are too small, overhead increases. ● Solution: Find the optimal number of tasks to balance parallelism and overhead.

Introducing CUDA: Parallel Processing on GPUs

What is CUDA?

● CUDA (Compute Unified Device Architecture) is a platform developed by NVIDIA for parallel computing on GPUs. ● GPUs are designed for data-parallel tasks (e.g., processing millions of pixels in an image).

Why Use GPUs? ● GPUs have thousands of cores (compared to a CPU's few cores), making them ideal for parallel tasks. ● Example: Processing a 1920x1200 image (2.3 million pixels) can be done in constant time by mapping each pixel to a GPU thread.

Applications of CUDA:

● Machine Learning: Preparing data and training models. ● Scientific Simulations: Weather forecasting, DNA analysis. ● Multimedia Processing: Video and image analysis.

Cluster Computing: Distributed Parallel Processing

What is Cluster Computing?

● A cluster is a group of computers (nodes) connected over a high-speed network. ● Large-scale algorithms are divided into tasks and distributed across the cluster.

Apache Spark:

● A popular framework for cluster computing. ● Data is divided into Resilient Distributed Datasets (RDDs) , which are processed in parallel across nodes. ● Example: Analyzing terabytes of log data or training machine learning models on large datasets.

Hybrid Strategy: Combining GPUs and Distributed Computing

How It Works:

  1. Divide Data: Split the data into multiple partitions.
  2. Distribute Tasks: Assign each partition to a node in the cluster.
  3. Use GPUs: On each node, use the GPU to process the data in parallel.

Example:

● A cloud platform like AWS allows you to provision GPU-enabled virtual machines. You can use these machines to run large-scale algorithms by combining distributed computing (across nodes) and GPU processing (within each node).

What is Hadoop?

Hadoop is like a super-smart system designed to store and process huge amounts of data (like gigabytes, terabytes, or even petabytes). It’s open-source, meaning anyone can use and modify it for free. Hadoop is especially useful for big data applications, where traditional systems struggle to handle the volume, speed, and variety of data. Hadoop works by distributing data and tasks across many computers (called a cluster ) instead of relying on a single machine. This makes it faster, more reliable, and cost-effective.

Key Components of Hadoop

Hadoop has four main parts that work together:

  1. HDFS (Hadoop Distributed File System) – For storing data.
  2. MapReduce – For processing data.
  3. YARN (Yet Another Resource Negotiator) – For managing resources.
  4. Hadoop Common – Shared utilities and libraries. Let’s dive into each one.
  5. HDFS (Hadoop Distributed File System)

HDFS is like a giant, super-reliable storage system for big data. It splits large files into smaller chunks (called blocks ) and stores them across multiple machines in a cluster. This way, even if one machine fails, your data is still safe.

How HDFS Works: ● NameNode (Master): Think of this as the "boss" of the storage system. It keeps track of where all the data blocks are stored but doesn’t store the actual data itself. It’s like a librarian who knows where every book is in the library. ● DataNodes (Slaves): These are the "workers" that store the actual data blocks. They report back to the NameNode regularly to say, "Hey, I’m still here, and I have these blocks!"

Key Features of HDFS:

● Scalability: You can add more machines (DataNodes) to store more data. ● Fault Tolerance: If a machine fails, HDFS has backups (replicas) of the data on other machines. ● High Throughput: It’s designed to handle large amounts of data quickly.

Example: Imagine you have a 1 GB file. HDFS splits it into 8 blocks (each 128 MB) and stores them on different machines. If one machine crashes, you can still access the file because the blocks are replicated on other machines.

  1. Hadoop Common

Hadoop Common is like the "toolbox" for Hadoop. It provides shared tools and libraries that all the other components (HDFS, MapReduce, YARN) need to work. Without Hadoop Common, the other parts wouldn’t function properly.

What Hadoop Common Does:

● Provides essential libraries for file systems, networking, and security. ● Ensures all Hadoop components can talk to each other. ● Handles basic tasks like reading/writing files and managing hardware failures.

Example:

Think of Hadoop Common as the foundation of a house. Without a strong foundation, the walls (HDFS), roof (MapReduce), and plumbing (YARN) wouldn’t hold up.

Why is Hadoop Important?

  1. Handles Big Data: It can store and process massive amounts of data that traditional systems can’t handle.
  2. Cost-Effective: It runs on cheap, commodity hardware (regular computers) instead of expensive servers.
  3. Fault-Tolerant: If one machine fails, the system keeps running because data is replicated.
  4. Scalable: You can add more machines to the cluster as your data grows.

Real-Life Example of Hadoop in Action

Imagine you’re running a social media platform with millions of users. Every day, users upload photos, post comments, and like posts. Here’s how Hadoop helps:

  1. HDFS: Stores all the photos, comments, and likes across multiple machines.
  2. MapReduce: Analyzes user behavior, like finding the most liked posts or trending topics.
  3. YARN: Ensures that all these tasks run efficiently without overloading the system.
  4. Hadoop Common: Provides the tools needed to make all this happen seamlessly.

Setting Up Hadoop

Hadoop can be set up in three configurations, depending on your needs:

  1. Developer Mode (Standalone Mode): ○ Runs on a single machine. ○ No Hadoop daemons (background processes) are needed. ○ Used for testing and debugging MapReduce programs. ○ Example: A developer testing a small piece of code locally.
  2. Pseudo-Distributed Mode (Single-Node Cluster): ○ Runs on a single machine but mimics a full cluster. ○ All Hadoop daemons (NameNode, DataNode, ResourceManager, etc.) run on the same machine. ○ Used for development and testing before deploying to a real cluster. ○ Example: Testing a full MapReduce job locally before moving it to production.
  3. Fully Distributed Mode (Cluster Mode): ○ Runs on multiple machines (nodes) in a cluster. ○ Each machine has a specific role (e.g., NameNode, DataNode, ResourceManager). ○ Used for production environments to handle big data. ○ Example: A company processing terabytes of data daily.

Best Practices for Hadoop Deployment

Here’s how to set up and manage Hadoop effectively:

  1. Start Small: ○ Begin with a small cluster (e.g., 4 nodes) as a proof of concept (POC). ○ Test your setup and understand requirements before scaling up. ○ Why? Reduces risk and cost while allowing you to learn.
  2. Monitor Your Cluster: ○ Use tools like Ganglia or Nagios to monitor cluster health. ○ Track NameNode and DataNodes to ensure they’re functioning. ○ For Hadoop distributions like Hortonworks or Cloudera , use Ambari or Cloudera Manager for monitoring. ○ Why? Prevents failures and ensures smooth operation.
  3. Automate Deployment: ○ Use tools like Puppet or Chef to automate cluster setup and management. ○ Why? Saves time and reduces human error.
  4. Implement High Availability (HA): ○ Plan for failover and recovery in case of failures. ○ Ensure the system can handle increased demand and data growth. ○ Why? Avoids downtime and data loss.
  5. Focus on Security: ○ Create users and groups and assign permissions.
  1. Avro Files: ○ Supports schema evolution and compression. ○ Stores data in a binary format along with its schema. ○ Use Case: Data serialization and storage.
  2. Parquet Files: ○ Stores data in a columnar format (great for analytics). ○ Highly efficient in terms of storage and performance. ○ Use Case: Analytical queries (e.g., Hive, Spark SQL).
  3. ORC Files: ○ Optimized for Hive performance. ○ Provides excellent compression and reduces storage space. ○ Use Case: Reading, writing, and processing data in Hive.

Apache Pig , Apache Sqoop , and Apache Drill (PULP FD)

Feature Apache Pig Apache Sqoop Apache Drill

Purpos e

Platform for managing and analyzing large datasets using high-level programming.

Tool for transferring data between Hadoop and relational databases.

Open-source query engine for interactive analysis of large-scale datasets.

Langua ge

Pig Latin (textual language). Command-line tools. SQL (supports standard SQL).

Key Feature s

  • Simple programming: Easy to code, execute, and manage.
    • Import/export data between Hadoop and RDBMS.
      • Schema-free: Query raw data without predefined schemas.
  • Better optimization: Automatically optimizes execution.
    • Supports large objects (Blob, Clob).
      • Supports multiple datastores (HDFS, MongoDB, S3, etc.).
  • Extensive nature: Handles highly specific processing tasks.
    • Append, filter, and select data during import.
      • Columnar execution engine for fast query processing.

Use Cases

  • ETL data pipelines. - Import data from RDBMS to Hadoop (HDFS, Hive, HBase). - Interactive analysis of large datasets.

Apache Hive and Apache HBase

Feature Apache Hive Apache HBase

Function SQL-like query engine for high-volume

data stores.

Low-latency distributed

key-value store for

real-time access.

Purpose Designed for batch processing and data

warehousing.

Designed for real-time

processing and random

access to large datasets.

Processing

Type

Batch processing using MapReduce or

Apache Tez.

Real-time processing with

low-latency reads/writes.

Latency Medium to high latency (due to batch

processing).

Low latency, but can have

spikes under heavy write

loads.

Hadoop

Integration

Runs on top of Hadoop with HDFS or

Amazon S3 for storage.

Runs on top of HDFS or

Amazon S3 using EMRFS.

SQL Support Provides SQL-like querying capabilities

with HiveQL.

No native SQL support;

uses Apache Phoenix for

SQL capabilities.

Schema Defined schema for all tables. Schema-free ; users define

mappings of data fields.

Data Types Supports structured and unstructured

data.

Supports unstructured

data only.

Data Model Table-based with rows and columns. Column-oriented with row

keys , column families , and

timestamps.

ACID

Transactions

Supports ACID transactions at the row

level.

Does not natively support

ACID transactions.

Use Cases - Analyzing relatively static data. - Real-time access to large,

sparse datasets.

  • Less responsive time. - Handling non-relational

data.

  • No rapid changes in data. - Low-latency random

reads/writes.

Integration Integrates with HDFS , HCatalog , Pig , and

MapReduce.

Integrates with HDFS ,

MapReduce , and Apache

Phoenix.

Architecture - Uses HiveQL to convert queries into

MapReduce/Tez jobs.

  • Column-oriented,

non-relational database.

  • Stores metadata in a metastore. - Data is distributed across

region servers.

  • Supports HCatalog for metadata sharing. - Uses ZooKeeper for

coordination.

Scalability Scales well for batch processing and large

datasets.

Scales horizontally across

thousands of servers for

real-time access.

Performance Optimized for batch queries on large

datasets.

Optimized for low-latency

random reads/writes.

Fault

Tolerance

Relies on HDFS for fault tolerance. Built to withstand

individual host failures ;

data is automatically

recovered.

Data Storage Data is stored in HDFS or Amazon S3. Data is stored in HDFS or

Amazon S3 using EMRFS.

Query

Language

Uses HiveQL (SQL-like). Uses HBase API ; Apache

Phoenix adds SQL

support.

○ Hive: Data warehousing, batch analytics.

○ HBase: Real-time applications, sparse datasets.

7. Integration:

○ Hive: Integrates with HDFS, HCatalog, Pig, and MapReduce.

○ HBase: Integrates with HDFS, MapReduce, and Apache Phoenix.

8. Scalability:

○ Hive: Scales for batch processing.

○ HBase: Scales horizontally for real-time access.

When to Use Which?

● Use Hive if:

○ You need to perform batch processing on large datasets.

○ You are comfortable with SQL-like querying (HiveQL).

○ Your data is structured and doesn’t require real-time access.

● Use HBase if:

○ You need real-time access to large datasets.

○ Your data is unstructured or sparse.

○ You require low-latency reads and writes.

Apache Hive and Apache HBase (learn this) P2AS3 FUD

Feature Apache Hive Apache HBase

1. Purpose For batch processing and data warehousing.

For real-time access to large datasets.

2. Processing Type

Uses batch processing (MapReduce/Tez).

Uses real-time processing (low-latency reads/writes).

3. Architecture - Converts SQL-like queries ( HiveQL ) into MapReduce/Tez jobs. - Stores data in column families and uses row keys for fast access. - Stores metadata in a metastore. - Data is split into regions and distributed across servers. - Works with HDFS for storage. - Uses ZooKeeper to manage servers and ensure fault tolerance. 4. Schema Needs a fixed schema (structured data).

No fixed schema (unstructured data).

5. SQL Support Supports HiveQL (SQL-like queries). No native SQL; uses Apache Phoenix for SQL queries. 6. Data Model Works like a traditional table (rows and columns).

Stores data in columns grouped into families , with timestamps.

7. Use Cases - Analyzing static data (e.g., logs, historical data). - Real-time apps (e.g., messaging, recommendations). - Batch processing of large datasets. - Handling sparse datasets (e.g., user profiles, sensor data). 8. Scalability Scales well for batch jobs and large datasets.

Scales across thousands of servers for real-time access.

● Use HBase if: ○ You need real-time access to data (e.g., for apps). ○ Your data is unstructured or sparse. ○ You need low-latency reads and writes.

HBase Data Model

● Column-Oriented: Data is stored in columns grouped into column families. ● Row Key: Each row is identified by a unique row key. ● Versions: Each cell (row + column) can store multiple versions of data, marked by a timestamp. ● Dynamic Columns: Columns can be added on the fly (no fixed schema). ● Sparse Data: Efficiently handles sparse datasets (where many cells are empty). Example:

Row Key Column Family: User Column Family: Activity

User1 User:Name = "Alice" Activity:Login = "2023-10-01"

User:Age = 25 Activity:Purchase = "2023-10-02"

User2 User:Name = "Bob" Activity:Login = "2023-10-03"

HBase Architecture

● Master-Slave Model: ○ HMaster: Manages metadata, table creation, and region assignment. ○ RegionServers: Store and manage data in regions (subsets of tables). ● Regions: Tables are split into regions , which are distributed across RegionServers. ● ZooKeeper: Coordinates between HMaster and RegionServers, ensuring fault tolerance. ● HDFS: Data is stored in HDFS (Hadoop Distributed File System) for durability. ● Auto-Sharding: Tables are automatically split into regions as they grow. How it Works:

  1. Client sends a read/write request to the HMaster.
  2. HMaster directs the request to the appropriate RegionServer.
  3. RegionServer retrieves or updates data in its regions.
  4. Data is stored in HFiles (HBase’s file format) on HDFS.