Scalability and Map Reduce Scalability The term scalability

  • Slides: 51
Download presentation
Scalability and Map. Reduce

Scalability and Map. Reduce

Scalability • The term 'scalability' can be defined as the "capability of a system,

Scalability • The term 'scalability' can be defined as the "capability of a system, network, or process to handle a growing amount of work, or its potential to be enlarged to accommodate that growth. “ • As data, data science projects, and the data science team grow, is the enterprise able to support these adequately? Mark Hornick DIRECTOR, ADVANCED ANALYTICS AND MACHINE LEARNING (He has defined 5 levels of scalability like CMM: (https: //blogs. oracle. com/r/data-science-maturity-model-scalability-dimension-part-8) 1. Data volumes are typically "small" and limited by desktop-scale 2. Data science projects take on greater complexity and leverage larger data volumes 3. Individual groups adopt varied scalable data science tools and provide greater hardware resources for data scientist use. 4. Enterprise standardizes on an integrated suite of scalable data science tools and dedicates sufficient hardware capacity to data science projects. 5. Data scientists have on-demand access to elastic compute resources both on premises and in the cloud with highly scalable algorithms and infrastructure. )

What Does Scalable Mean? • Operationally: • In the past: “Works even if data

What Does Scalable Mean? • Operationally: • In the past: “Works even if data doesn’t fit in main memory” • Now: “Can make use of 1000 s of cheap computers” • Algorithmically: • In the past: If you have N data items, you must do no more than Nm operations -- “polynomial time algorithms” • Now: If you have N data items, you must do no more than Nm/k operations, for some large k (Polynomial-time algorithms must be parallelized ) • Soon: If you have N data items, you should do no more than N * log(N) operations • As data sizes go up, you may only get one pass at the data The data is streaming -- you better make that one pass count Ex: Large Synoptic Survey Telescope (30 TB / night)

Example: Find matching DNA sequences • Given a set of sequences • Find all

Example: Find matching DNA sequences • Given a set of sequences • Find all sequences equal to “GATTACGATATTA”

Sequentially = Linear Time TACCTGCCGTAA GATTACGATATTA

Sequentially = Linear Time TACCTGCCGTAA GATTACGATATTA

Sort and apply technique like Binary Search

Sort and apply technique like Binary Search

Sort and apply technique like Binary Search

Sort and apply technique like Binary Search

Sort and apply technique like Binary Search

Sort and apply technique like Binary Search

Sort and apply technique like Binary Search

Sort and apply technique like Binary Search

Relational Databases are good at “Needle in Haystack” problems: Extracting small results from big

Relational Databases are good at “Needle in Haystack” problems: Extracting small results from big datasets Transparently provide “old style” scalability Your query will always/almost finish, regardless of dataset size. Indexes are easily built and automatically used when appropriate CREATE INDEX seq_idx ON sequence(seq); SELECT seq FROM sequence WHERE seq = ‘GATTACGATATTA’;

New task: Read Trimming •  Given a set of DNA sequences •  Trim the

New task: Read Trimming •  Given a set of DNA sequences •  Trim the final n bps of each sequence •  Generate a new data set

TACCTGCCGTAA GATTACGATATTA time = 0 time = 1 TACCTGCCGTAA becomes TACCT time = 2

TACCTGCCGTAA GATTACGATATTA time = 0 time = 1 TACCTGCCGTAA becomes TACCT time = 2 CCCCCAATGAC becomes CCCCC

Can we improve this processing: Read Trimming • Sorting ? • Indexes ? •

Can we improve this processing: Read Trimming • Sorting ? • Indexes ? • No. As we will have to touch each object once. • We have to touch every record no matter what. The task is fundamentally O(N) • Can we do any better?

Divide task into subtasks

Divide task into subtasks

 • How much time did this take? • 7 cycles • 40 records,

• How much time did this take? • 7 cycles • 40 records, 6 workers time = 7 • O(N/k)

Schematic of a Parallel Read Trimming Task

Schematic of a Parallel Read Trimming Task

New Task: Convert 405 k TIFF images to PNG

New Task: Convert 405 k TIFF images to PNG

New Task: Run thousands of simulations

New Task: Run thousands of simulations

Find the most common word in each document

Find the most common word in each document

Compute the word frequency of 5 million documents

Compute the word frequency of 5 million documents

There’s a pattern here…. • A function that maps a read to a trimmed

There’s a pattern here…. • A function that maps a read to a trimmed read • A function that maps a TIFF image to a PNG image • A function that maps a set of parameters to a simulation result • A function that maps a document to its most common word • A function that maps a document to a histogram of word frequencies

Compute the word frequency of 5 million documents

Compute the word frequency of 5 million documents

Map Reduce • Google: paper published 2004 • Free variant: Hadoop • Map-reduce =

Map Reduce • Google: paper published 2004 • Free variant: Hadoop • Map-reduce = high-level programming model and implementation for largescale parallel data processing slide src: Dan Suciu and Magda Balazinska

Data Model A file = a bag of (key, value) pairs A map-reduce program:

Data Model A file = a bag of (key, value) pairs A map-reduce program: Input: a bag of (inputkey, value)pairs Output: a bag of (outputkey, value)pairs

2 Phases of Map. Reduce Step 1: The MAP Phase : User provides the

2 Phases of Map. Reduce Step 1: The MAP Phase : User provides the MAP-function: • Input: (input key, value) • Ouput: bag of (intermediate key, value) System applies the map function in parallel to all (input key, value) pairs in the input file Step 2: The REDUCE Phase: User provides the REDUCE function: • Input: (intermediate key, bag of values) • Output: bag of output (values) The system will group all pairs with the same intermediate key, and passes the bag of values to the REDUCE function

Map. Reduce Programming Model Input & Output: each a set of key/value pairs Programmer

Map. Reduce Programming Model Input & Output: each a set of key/value pairs Programmer specifies two functions: map (in_key, in_value) -> list(out_key, intermediate_value) – Processes input key/value pair – Produces set of intermediate pairs reduce (out_key, list(intermediate_value)) -> list(out_value) • Combines all intermediate values for a particular key • Produces a set of merged output values (usually just one)

Example: What does this do? map(String input_key, String input_value): // input_key: document name //

Example: What does this do? map(String input_key, String input_value): // input_key: document name // input_value: document contents for each word w in input_value: Emit. Intermediate(w, 1); reduce(String intermediate_key, Iterator intermediate_values): // intermediate_key: word // intermediate_values: ? ? int result = 0; for each v in intermediate_values: result += v; Emit. Final(intermediate_key, result);

Example: Word length histogram Abridged Declaration of Independence A Declaration By the Representatives of

Example: Word length histogram Abridged Declaration of Independence A Declaration By the Representatives of the United States of America, in General Congress Assembled. When in the course of human events it becomes necessary for a people to advance from that subordination in which they have hitherto remained, and to assume among powers of the earth the equal and independent station to which the laws of nature and of nature's god entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the change. We hold these truths to be self-evident; that all men are created equal and independent; that from that equal creation they derive rights inherent and inalienable, among which are the preservation of life, and liberty, and the pursuit of happiness; that to secure these ends, governments are instituted among men, deriving their just power from the consent of the governed; that whenever any form of government shall become destructive of these ends, it is the right of the people to alter or to abolish it, and to institute new government, laying it's foundation on such principles and organizing it's power in such form, as to them shall seem most likely to effect their safety and happiness. Prudence indeed will dictate that governments long established should not be changed for light and transient causes: and accordingly all experience that shown that mankind are more disposed to suffer while evils are sufferable, than to right themselves by abolishing the forms to which they are accustomed. But when a long train of abuses and usurpations, begun at a distinguished period, and pursuing invariably the same object, evinces a design to reduce them to arbitrary power, it is their right, it is their duty, to throw off such government and to provide new guards for future security. Such has been the patient sufferings of the colonies; and such is now the necessity which constrains them to expunge their former systems of government. the history of his present majesty is a history of unremitting injuries and usurpations, among which no one fact stands single or solitary to contradict the uniform tenor of the rest, all of which have in direct object the establishment of an absolute tyranny over these states. To prove this, let facts be submitted to a candid world, for the truth of which we pledge a faith yet unsullied by falsehood. How many “big”, “medium”, and “small” words are used?

Example: Word length histogram

Example: Word length histogram

Example: Word length histogram

Example: Word length histogram

Example: Word length histogram

Example: Word length histogram

Sec. 1. 2 Inverted index • For each term t, we must store a

Sec. 1. 2 Inverted index • For each term t, we must store a list of all documents that contain t. • Identify each doc by a doc. ID, a document serial number • Can we used fixed-size arrays for this? Brutus 1 Caesar 1 Calpurnia 2 2 2 31 4 11 31 45 173 174 4 5 6 16 57 132 54 101 What happens if the word Caesar is added to document 14? 38

Sec. 1. 2 Inverted index • We need variable-size postings lists • On disk,

Sec. 1. 2 Inverted index • We need variable-size postings lists • On disk, a continuous run of postings is normal and best • In memory, can use linked lists or variable length arrays • Some tradeoffs in size/ease of insertion Posting Brutus 1 Caesar 1 Calpurnia Dictionary 2 2 2 31 4 11 31 45 173 174 4 5 6 16 57 132 54 101 Postings Sorted by doc. ID (more later on why). 39

Sec. 1. 2 Inverted index construction Documents to be indexed Friends, Romans, countrymen. Tokenizer

Sec. 1. 2 Inverted index construction Documents to be indexed Friends, Romans, countrymen. Tokenizer Token stream Friends Romans Countrymen friend roman countryman Linguistic modules Modified tokens Indexer Inverted index friend 2 4 roman 1 2 countryman 13 16

Initial stages of text processing • Tokenization • Cut character sequence into word tokens

Initial stages of text processing • Tokenization • Cut character sequence into word tokens • Deal with “John’s”, a state-of-the-art solution • Normalization • Map text and query term to same form • You want U. S. A. and USA to match • Stemming • We may wish different forms of a root to match • authorize, authorization • Stop words • We may omit very common words (or not) • the, a, to, of

Sec. 1. 2 Indexer steps: Token sequence • Sequence of (Modified token, Document ID)

Sec. 1. 2 Indexer steps: Token sequence • Sequence of (Modified token, Document ID) pairs. Doc 1 I did enact Julius Caesar I was killed i’ the Capitol; Brutus killed me. Doc 2 So let it be with Caesar. The noble Brutus hath told you Caesar was ambitious

Sec. 1. 2 Indexer steps: Sort • Sort by terms • And then doc.

Sec. 1. 2 Indexer steps: Sort • Sort by terms • And then doc. ID Core indexing step

Sec. 1. 2 Indexer steps: Dictionary & Postings • Multiple term entries in a

Sec. 1. 2 Indexer steps: Dictionary & Postings • Multiple term entries in a single document are merged. • Split into Dictionary and Postings • Doc. frequency information is added.

More example: Build an Inverted Index

More example: Build an Inverted Index

More Example: Relational Join

More Example: Relational Join

Assignment Hadoop • Install Hadoop on your system (Hadoop on a single system) (write

Assignment Hadoop • Install Hadoop on your system (Hadoop on a single system) (write steps on a document for submission) • Program and execute word count example on installed Hadoop system via installed system on your personal computer. (Take screen shots and place those on the document with steps for submission on turnitin. )