NoSQL, Hadoop, Cascading June 2010

40
NoSQL, Hadoop and Cascading Christopher Curtin

description

Introduction to NoSQL and Hadoop/Cascading for the Atlanta IASA Chapter

Transcript of NoSQL, Hadoop, Cascading June 2010

Page 1: NoSQL, Hadoop, Cascading June 2010

NoSQL, Hadoop and Cascading

Christopher Curtin

Page 2: NoSQL, Hadoop, Cascading June 2010

About Me

• 20+ years in Technology• Background in Factory Automation,

Warehouse Management and Food Safety system development before Silverpop

• CTO of Silverpop

Page 3: NoSQL, Hadoop, Cascading June 2010

Topics

• Why NoSQL?• What is NoSQL?• Hadoop• Cascading• Questions

Page 4: NoSQL, Hadoop, Cascading June 2010

Why NoSQL?

• Should be ‘not just SQL’• Not all problems are relational• Not all schemas are known when

developing a solution• Is LAMP the reason?• Difficult to assign a value to a lot of

the data in an enterprise

Page 5: NoSQL, Hadoop, Cascading June 2010

Cost• Obligatory slam on

Oracle/IBM/Microsoft– CPU/Core costs – Disks for fast RDBMS performance– Clustering, Redundancy and DR

• Obligatory slam on Accenture, IBM and Corp IT– Data warehouses– Report writers – Lead Time

Page 6: NoSQL, Hadoop, Cascading June 2010

NIH

• Some of this is ‘not invented here’• But many of these solutions came

from the Internet-scale businesses like Facebook, Google, Twitter, Amazon

• Problems most of us will never see or really understand

Page 7: NoSQL, Hadoop, Cascading June 2010

Topics

• Why NoSQL?• What is NoSQL?• Hadoop• Cascading• Questions

Page 8: NoSQL, Hadoop, Cascading June 2010

What is NoSQL?• Lots of definitions, but a few key ideas– Eventual Consistency vs. ACID (usually)– Distributed on commodity hardware, easy to

add/remove nodes– (Typically) Open Source– (Usually) non-SQL interface

• A few examples– Graph databases– Key/Value stores– Document databases

Page 9: NoSQL, Hadoop, Cascading June 2010

Graph Databases• For handling deeply associative data

(graphs/networks)• Relational isn’t good at recursive

structures• Data both at the leaves (nodes) and edges

(relationships) • Very fast to navigate• “Whiteboard Friendly”• Neo4j (www.neo4j.org)

Page 10: NoSQL, Hadoop, Cascading June 2010

Key/Value Stores

• Don’t call them databases ;-)• No JOIN concept, instead duplicate

data• Think of it as a huge Associated

Array (Map)• Not all values have all attributes• Designed for fast reading• ‘Ridiculous’ sized• SimpleDB (Amazon), BigTable

(Google)

Page 11: NoSQL, Hadoop, Cascading June 2010

Document Databases

• Inspired by Lotus Notes. Really.• Collections of Key/Value stores• But with some additional visibility

into the data of the stores • CouchDB (couchdb.apache.org)– Stores JSON documents– Can search in documents quickly– No schema so Domain changes are

easier

Page 12: NoSQL, Hadoop, Cascading June 2010

Topics

• Why NoSQL?• What is NoSQL?• Hadoop• Cascading• Questions

Page 13: NoSQL, Hadoop, Cascading June 2010

Map/Reduce

• Made famous by Google for how the index the web

• Parallel processing of large datasets across multiple commodity nodes

• Highly fault tolerant• Hadoop is Apache’s implementation

of Map/Reduce

Page 14: NoSQL, Hadoop, Cascading June 2010

Map

• Identifies what is in the input that you want to process

• Can be simple: occurrence of a word• Can be difficult: evaluate each row

and toss those older than 90 days or from IP Range 192.168.1.*

• Output is a list of name/value pairs• Name and value do not have to be

primitives

Page 15: NoSQL, Hadoop, Cascading June 2010

Reduce

• Takes the name/value pairs from the Map step and does something useful with them

• Map/Reduce Framework determines which Reduce instance to call for which Map values so a Reduce only ‘sees’ one set of ‘Name’ values

• Output is the ‘answer’ to the question

• Example: bytes streamed by IP address from Apache logs

Page 16: NoSQL, Hadoop, Cascading June 2010

HDFS• Distributed File System WITHOUT NFS etc.• Hadoop knows which parts of which files

are on which machine (say that 5 times fast!)

• “Move the processing to the data” if possible

• Simple API to move files in and out of HDFS

• 3 Copies of the data in the cluster for redundancy AND performance

Page 17: NoSQL, Hadoop, Cascading June 2010

Runtime Distribution © Concurrent 2009

Page 18: NoSQL, Hadoop, Cascading June 2010

Topics

• Why NoSQL?• What is NoSQL?• Hadoop• Cascading• Questions

Page 19: NoSQL, Hadoop, Cascading June 2010

Getting Started with Map/Reduce• First challenge: real examples• Second challenge: when to map and

when to reduce?• Third challenge: what if I need more

than one of each? How to coordinate?

• Fourth challenge: non-trivial business logic

Page 20: NoSQL, Hadoop, Cascading June 2010

Cascading

• Hadoop coding is non-trivial• Hadoop is looking for a class to do

Map steps and a class to do Reduce step

• What if you need multiple in your application? Who coordinates what can be run in parallel?

• What if you need to do non-Hadoop logic between Hadoop steps?

Page 21: NoSQL, Hadoop, Cascading June 2010

Tuple

• A single ‘row’ of data being processed

• Each column is named• Can access data by name or position

Page 22: NoSQL, Hadoop, Cascading June 2010

TAP

• Abstraction on top of Hadoop files• Allows you to define own parser for

files• Example:• Input = new Hfs(new TextLine(),

a_hdfsDirectory + "/" + name);

Page 23: NoSQL, Hadoop, Cascading June 2010

Operations

• Define what to do on the data• Each – for each “tuple” in data do

this to it• Group – similar to a ‘group by’ in SQL• CoGroup – joins of tuple streams

together• Every – for every key in the Group or

CoGroup do this

Page 24: NoSQL, Hadoop, Cascading June 2010

Pipes

• Pipes tie Operations together• Pipes can be thought of as ‘tuple

streams’• Pipes can be split, allowing parallel

execution of Operations

Page 25: NoSQL, Hadoop, Cascading June 2010

Operations - advanced

• Each operations allow logic on the row, such a parsing dates, creating new attributes etc.

• Every operations allow you to iterate over the ‘group’ of rows to do non-trivial operations.

• Both allow multiple operations in same function, so no nested function calls!

Page 26: NoSQL, Hadoop, Cascading June 2010

PIPE Splitting

• PIPEs define processing flows• A SPLIT of a PIPE will tell Cascading

to pass the TUPLE to another set of logic

• Allows single parsing EACH to feed multiple EVERY steps

• Or output from one EVERY to feed different EVERY steps

Page 27: NoSQL, Hadoop, Cascading June 2010

Flows

• Flows are reusable combinations of Taps, Pipes and Operations

• Allows you to build library of functions

• Groups of Flow are called Cascades

Page 28: NoSQL, Hadoop, Cascading June 2010

Cascading Scheduler

• Once the Flows and Cascades are defined, looks for dependencies

• When executed, tells Hadoop what Map, Reduce or Shuffle steps to take based on what Operations were used

• Knows what can be executed in parallel

• Knows when a step completes what other steps can execute

Page 29: NoSQL, Hadoop, Cascading June 2010

Example OperationRowAggregator aggr = new RowAggregator(row);

Fields groupBy = new Fields(ColumnDefinition.RECIPIENT_ID_NAME);

Pipe formatPipe = new Each("reformat_“ new Fields("line"), a_sentFile);

formatPipe = new GroupBy(formatPipe, groupBy);formatPipe = new Every(formatPipe, Fields.ALL,

aggr);

Page 30: NoSQL, Hadoop, Cascading June 2010

Runtime Distribution © Concurrent 2009

Page 31: NoSQL, Hadoop, Cascading June 2010

Dynamic Flow Creation

• Flows can be created at run time based on inputs.

• 5 input files one week, 10 the next, Java code creates 10 Flows instead of 5

• Group and Every don’t care how many input Taps

Page 32: NoSQL, Hadoop, Cascading June 2010

Dynamic Tuple Definition• Each operations on input Taps can parse

text lines into different Fields• So one source may have 5 inputs, another

10• Each operations can used meta data to

know how to parse• Can write Each operations to output

common Tuples• Every operations can output new Tuples as

well• Dynamically provide GroupBy fields so end

users can build own ad-hoc logic

Page 33: NoSQL, Hadoop, Cascading June 2010

Mixing non-Hadoop code

• Cascading allows you to mix regular java between Flows in a Cascade

• So you can call out to databases, write intermediates to a file etc.

Page 34: NoSQL, Hadoop, Cascading June 2010

External File Creation

• An aggregator can write to the local file system

• Sometimes you don’t need or want to push back to HDFS

• NFS mounts needed since you don’t know where the logic is going to execute

• GROUP BY is critical to doing this right

Page 35: NoSQL, Hadoop, Cascading June 2010

Real Example

• For the hundreds of mailings sent last year

• To millions of recipients• Show me who opened, how often• Break it down by how long they have

been a subscriber• And their Gender• And the number of times clicked on

the offer

Page 36: NoSQL, Hadoop, Cascading June 2010

RDBMS solution

• Lots of million + row joins• Lots of million + row counts• Temporary tables since we want

multiple answers• Lots of memory• Lots of CPU and I/O• $$ becomes bottleneck to adding

more rows or more clients to same logic

Page 37: NoSQL, Hadoop, Cascading June 2010

Cascading Solution• Let Hadoop parse input files• Let Cascading group all inputs by

recipient’s email• Let Cascading call Every functions to look

at all rows for a recipient and ‘flatten’ data• Split ‘flattened’ data Pipes to process in

parallel: time in list, gender, clicked on links

• Bandwidth to export data from RDBMS becomes bottleneck

Page 38: NoSQL, Hadoop, Cascading June 2010

Pros and Cons• Pros

– Mix java between map/reduce steps– Don’t have to worry about when to map, when to reduce– Don’t have to think about dependencies or how to

process– Data definition can change on the fly

• Cons– Level above Hadoop – sometimes ‘black magic’– Data must (should) be outside of database to get most

concurrency

Page 39: NoSQL, Hadoop, Cascading June 2010

Other Solutions• Apache Pig:

http://hadoop.apache.org/pig/• More ‘sql-like’ • Not as easy to mix regular Java into

processes• More ‘ad hoc’ than Cascading

• Amazon Hadoop http://aws.amazon.com/elasticmapreduce/

• Runs on EC2• Provide Map and Reduce functions• Can use Cascading • Pay as you go

Page 40: NoSQL, Hadoop, Cascading June 2010

Resources

• Me: [email protected] @ChrisCurtin

• Chris Wensel: @cwensel • Web site: www.cascading.org• Mailing list off website• AWSome Atlanta Group:

http://www.meetup.com/awsomeatlanta/

• O’Reilly Hadoop Book: • http://oreilly.com/catalog/978059652

1974/