intro to riak

65
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Distributed computation on dynamo-style distributed storage: Riak pipe An introduction to Riak Jaseem Abid September 19, 2012

Upload: jaseem-abid

Post on 08-May-2015

1.591 views

Category:

Technology


10 download

TRANSCRIPT

Page 1: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.

......

Distributed computation on dynamo-styledistributed storage: Riak pipe

An introduction to Riak

Jaseem Abid

September 19, 2012

Page 2: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Riak

Page 3: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. What is Riak ?

Riak is an open source, distributed NoSQL database implementingthe principles from Amazon’s Dynamo paper.

Page 4: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Dynamo Model

Riak is a highly available, proprietary key-value structured storagesystem or a distributed data store. It has properties of bothdatabases and distributed hash tables (DHTs). It is not directlyexposed as a web service, but is used to power parts of otherAmazon Web Services such as Amazon S3.

Implementations

Apache CassandraProject VoldemortRiakAmazon DynamoDB

Page 5: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Dynamo Model

Riak is a highly available, proprietary key-value structured storagesystem or a distributed data store. It has properties of bothdatabases and distributed hash tables (DHTs). It is not directlyexposed as a web service, but is used to power parts of otherAmazon Web Services such as Amazon S3.

Implementations

Apache CassandraProject VoldemortRiakAmazon DynamoDB

Page 6: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Dynamo Model

Riak is a highly available, proprietary key-value structured storagesystem or a distributed data store. It has properties of bothdatabases and distributed hash tables (DHTs). It is not directlyexposed as a web service, but is used to power parts of otherAmazon Web Services such as Amazon S3.

Implementations

Apache CassandraProject VoldemortRiakAmazon DynamoDB

Page 7: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Dynamo Model

Riak is a highly available, proprietary key-value structured storagesystem or a distributed data store. It has properties of bothdatabases and distributed hash tables (DHTs). It is not directlyexposed as a web service, but is used to power parts of otherAmazon Web Services such as Amazon S3.

Implementations

Apache CassandraProject VoldemortRiakAmazon DynamoDB

Page 8: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Dynamo Model

Riak is a highly available, proprietary key-value structured storagesystem or a distributed data store. It has properties of bothdatabases and distributed hash tables (DHTs). It is not directlyexposed as a web service, but is used to power parts of otherAmazon Web Services such as Amazon S3.

Implementations

Apache CassandraProject VoldemortRiakAmazon DynamoDB

Page 9: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. This talk

Front Matter

Dynamo (and NoSQL) are nothing newMuch of Dynamo was invented > 10 years agoDynamo chooses AP of CAPThis talk will focus on properties of Dynamo-inspired systems(Riak, Cassandra, Voldemort)

Page 10: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. CAP theorem

Page 11: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. CAP theorem

Consistent, writes are atomic and all subsequent requestsretrieve the new value

Available, the database will always return a value as long as asingle server is runningPartition Tolerant, the system will still function even if servercommunication is temporarily lost—that is, a networkpartitionYou can have only two at once.

Page 12: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. CAP theorem

Consistent, writes are atomic and all subsequent requestsretrieve the new valueAvailable, the database will always return a value as long as asingle server is running

Partition Tolerant, the system will still function even if servercommunication is temporarily lost—that is, a networkpartitionYou can have only two at once.

Page 13: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. CAP theorem

Consistent, writes are atomic and all subsequent requestsretrieve the new valueAvailable, the database will always return a value as long as asingle server is runningPartition Tolerant, the system will still function even if servercommunication is temporarily lost—that is, a networkpartition

You can have only two at once.

Page 14: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. CAP theorem

Consistent, writes are atomic and all subsequent requestsretrieve the new valueAvailable, the database will always return a value as long as asingle server is runningPartition Tolerant, the system will still function even if servercommunication is temporarily lost—that is, a networkpartitionYou can have only two at once.

Page 15: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. CAP theorem

Riak picks AP of CAP

Page 16: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Eventual Consistency

Distributed databases must be partition tolerant, so thechoice between availability and consistency can be difficult.The real world is eventually consistent and works (mostly) fine*Eventual* doesn’t mean minutes, days, or even seconds innon-failure casesDNS, HTTP with Expires: headerHow you model the real world matters!

Page 17: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Riak ArchitectureAmazon’s Dynamo architectureDistributed, Scalable, No single point of failureNo transactions; trade strong consistency for eventual consistency

Page 18: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Simple Key Value data store - Store anything

Plain text, JSON, or XML to images or video clips—all accessiblethrough a simple HTTP interface

Riak KV

Page 19: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Simple Key Value data store - Store anything

Plain text, JSON, or XML to images or video clips—all accessiblethrough a simple HTTP interfaceRiak KV

Page 20: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Fault-Tolerant

Riak is also fault-tolerant. Servers can go up or down at anymoment with no single point of failure.

Page 21: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Riak loves the web

Query Riak via URLs, headers, and verbs, and Riak returns assetsand standard HTTP response codes.

Page 22: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Scalable

# start 4 nodes

$ dev/dev1/bin/riak start$ dev/dev2/bin/riak start$ dev/dev3/bin/riak start$ dev/dev4/bin/riak start

# scale out$ dev/dev2/bin/riak-admin join [email protected]

# scabe back in$ riak-admin leave

Page 23: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Queriablity

REST APIEasy quick and dirtyMap ReduceProvide set of starting keys, filter via mapMap reduce is meant for calulations/ aggregations and not queries.Riak SearchFull text search in RiakOpinionatedRoll out your own indicesDifficult to get it rightMore code to maintainOften introduces SPOFs

Page 24: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Riak REST API

Representational state transfer

Create Update Read Delete verbsRiak and cURL

Page 25: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Riak REST API

Representational state transferCreate Update Read Delete verbs

Riak and cURL

Page 26: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Riak REST API

Representational state transferCreate Update Read Delete verbsRiak and cURL

Page 27: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. REST API w/ curl

$ curl http://localhost:8091/pingOK

# Let’s issue a bad query.# -I tells cURL that we want only the header response.

$ curl -I http://localhost:8091/riak/no_bucket/no_keyHTTP/1.1 404 Object Not FoundServer: MochiWeb/1.1 WebMachine/1.7.3 \(participate in the frantic)

Date: Thu, 04 Aug 2011 01:25:49 GMTContent-Type: text/plainContent-Length: 10

Page 28: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Lets PUT something in the DB

$ curl -v -X PUT http://localhost:8091/riak/favs/db \-H "Content-Type: text/html" \-d "<html>

<body><h1>

My new favorite DB is RIAK</h1>

</body></html>"

Page 29: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Now get it back

curl -X GET http://localhost:8091/riak/favs/db

Or just hit the browser

Page 30: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Or POST it

$ curl -I -X POST http://localhost:8091/riak/animals \-H "Content-Type: application/json" \-d '{

"nickname" : "Sergeant Stubby","breed" : "Terrier"

}'

HTTP/1.1 201 CreatedVary: Accept-EncodingServer: MochiWeb/1.1 WebMachine/1.7.3 \(participate in the frantic)Location: /riak/animals/6VZc2o7zKxq2B34kJrm1S0ma3PODate: Tue, 05 Apr 2011 07:45:33 GMTContent-Type: application/jsonContent-Length: 0

Page 31: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Dump anything

curl -X PUT HTTP://127.0.0.1:8091/riak/images/1.jpg \-H "Content-type: image/jpeg" \--data-binary @image_name.jpg

Page 32: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Or DELETE it

$ curl -I -X DELETE http://localhost:8091/riak/ \animals/6VZc2o7zKxq2B34kJrm1S0ma3PO

HTTP/1.1 204 No ContentVary: Accept-EncodingServer: MochiWeb/1.1 WebMachine/1.7.3 \(participate in the frantic)

Date: Mon, 11 Apr 2011 05:08:39 GMTContent-Type: application/x-www-form-urlencodedContent-Length: 0

DELETE won’t return any body, but the HTTP code will be 204 ifsuccessful. Otherwise, as you’d expect, it returns a 404.

Page 33: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Map Reduce

Google :)*large* data setsFunctional ProgrammingApache HadoopWhy C suck here

Page 34: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. The tldr; version

MapReduce is a framework for processing embarrassingly parallelproblems across huge datasets using a large number of computers(nodes), collectively referred to as a cluster (if all nodes are on thesame local network and use similar hardware) or a grid (if thenodes are shared across geographically and administrativelydistributed systems, and use more heterogenous hardware).Computational processing can occur on data stored either in afilesystem (unstructured) or in a database (structured).MapReduce can take advantage of locality of data, processing dataon or near the storage assets to decrease transmission of data.

Page 35: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Map

”Map” step: The master node takes the input, divides it intosmaller sub-problems, and distributes them to worker nodes. Aworker node may do this again in turn, leading to a multi-level treestructure. The worker node processes the smaller problem, andpasses the answer back to its master node.

Page 36: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Reduce

”Reduce” step: The master node then collects the answers to allthe sub-problems and combines them in some way to form theoutput – the answer to the problem it was originally trying to solve.

Page 37: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. JSON

{"name": "John Smith","age": 25,"address": {

"streetAddress": "21 2nd Street","city": "New York""postalCode": "10021"

},"phoneNumber": [

{"type": "home","number": "212 555-1234"

},{

"type": "fax","number": "646 555-4567"

}]

}

Page 38: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Map

The Riak way

function (v) {return [v.phoneNumber];

}

The couchDB way

function (v) {emit("phone", v.phoneNumber);

}

Page 39: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Riak Search

...

Page 40: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Riak Secondary Indices

...

Page 41: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Riak …

Written in : Erlang & C, some Javascript

Page 42: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Riak …

Protocol: HTTP/REST or custom binary

Page 43: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Riak …

Tunable trade-offs for distribution and replication (N, R, W)

Page 44: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Riak …

Pre - and post-commit hooks in JavaScript or Erlang, forvalidation and security.

Page 45: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Riak …

Map/reduce in JavaScript or Erlang

Page 46: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Riak …

Links & link walking: use it as a graph database

Page 47: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Riak …

Secondary indices: but only one at once Large object support(Luwak)

Page 48: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Riak …

Comes in ”open source” and ”enterprise” editions

Page 49: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Riak …

Full-text search, indexing, querying with Riak …Search server (beta)

Page 50: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Riak …

In the process of migrating the storing backend from ”Bitcask” toGoogle ”LevelDB”

Page 51: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Riak …

Masterless multi-site replication replication and SNMP monitoringare commercially licensed

Page 52: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Riak …

Best used: If you want something Cassandra-like (Dynamo-like),but no way you’re gonna deal with the bloat and complexity. If youneed very good single-site scalability, availability andfault-tolerance, but you’re ready to pay for multi-site replication.

Page 53: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Riak …

For example: Point-of-sales data collection. Factory controlsystems. Places where even seconds of downtime hurt. Could beused as a well-update-able web server.

Page 54: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Review

Multi-node ClusteringMapReduce ProcessingIntegrated Full-Text SearchSecondary IndexingMasterless Multi-Site ReplicationLarge Object SupportImplementationArchitecture

Page 55: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Why use Riak

ScalableRiak is built so you can add more capacity as your app or platformgrows. When you add new machines, Riak distributes dataautomatically around the cluster with no downtime and anear-linear increase in performance and throughput

Page 56: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Why use Riak

Simple OpsRiak is the most boring database you’ll ever run in production. Nosharding required, just horizontal scaling and straight-forwardcapacity planning. The same operational tasks apply to smallclusters and large clusters. More machines does not mean moreops.

Page 57: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Why use Riak

MasterlessA Riak cluster is masterless. No node is special and any node canhandle requests for any other node in the cluster. All requests toRiak happen concurrently and developers don’t have to spend timeworrying about read/write locks or single points of failure.

Page 58: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Why use Riak

Fault TolerantDecide how many replicas of the data you want (start at 3). Ifnodes go down, requests are routed transparently to other nodes.Riak uses proven architectural principles like hinted handoff andread repair so you can always write and read data, even in failureconditions.

Page 59: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Why use Riak

Complex QueriesIn addition to key/value access to your data, Riak has built-insupport for MapReduce, Full Text Search, and Secondary Indexes,giving developers various ways to store and query their data.

Page 60: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Why use Riak

Flexible APIsRiak is equipped with fully-featured HTTP and Protocol BuffersAPIs, with support for both of these transports in all of oursupported client libraries. You can also write your own client layerto wrap our APIs if your use case or preference calls for it.

Page 61: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Why use Riak

1000s of UsersComcast, Yammer, Voxer, Boeing, BestBuy, SEOMoz, Joyent,Kiip, DotCloud, Formspring, GitHub, and the Danish Governmentare just a few of the thousands of startups and enterprises thathave deployed Riak.

Page 62: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Who uses it and why?

github git.iocomcast Internal object storageyammer NotificationsDISQUS analytics

AOL 1.5 billion data objects per dayMozilla User reviews

joyent, best buy …

Page 63: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Why use Riak

Language SupportBasho and the Riak Community maintain libraries for most majorlanguages including Java, Node.js, Python, Ruby, PHP, C/C++,and many more. All the client code, like the core Riak code, isavailable on GitHub.

Page 64: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

.. Why use Riak

Powerful CommunityThe Riak community is composed of smart, passionate hackerswho are contributing code, support, and evangelism every day.There are hundreds of companies and individuals testing, breaking,running, and building Riak.

Page 65: Intro to riak

..........

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

.....

.....

......

.....

......

.....

.....

.

Questions?