Hands-on Cassandra. OSCON July 20, 2010. Eric Evans eevans@rackspace.com @jericevans http://blog.sym-link.com

Similar documents
Dynamo: Amazon s Highly Available Key-value Store

Distributed Systems. Tutorial 12 Cassandra

Slave. Master. Research Scholar, Bharathiar University

Practical Cassandra. Vitalii

Facebook: Cassandra. Smruti R. Sarangi. Department of Computer Science Indian Institute of Technology New Delhi, India. Overview Design Evaluation

Evaluation of NoSQL databases for large-scale decentralized microblogging

The NoSQL Ecosystem, Relaxed Consistency, and Snoop Dogg. Adam Marcus MIT CSAIL

Making Sense of NoSQL Dan McCreary Wednesday, Nov. 13 th 2014

Seminar Presentation for ECE 658 Instructed by: Prof.Anura Jayasumana Distributed File Systems

Joining Cassandra. Luiz Fernando M. Schlindwein Computer Science Department University of Crete Heraklion, Greece

High Throughput Computing on P2P Networks. Carlos Pérez Miguel

Cassandra. Jonathan Ellis

NoSQL Databases. Institute of Computer Science Databases and Information Systems (DBIS) DB 2, WS 2014/2015

Introduction to NoSQL

NoSQL Data Base Basics

Advanced Data Management Technologies

Cassandra A Decentralized, Structured Storage System

Storage of Structured Data: BigTable and HBase. New Trends In Distributed Systems MSc Software and Systems

Lecture Data Warehouse Systems

LARGE-SCALE DATA STORAGE APPLICATIONS

Study and Comparison of Elastic Cloud Databases : Myth or Reality?

Structured Data Storage

Introduction to NOSQL

Elosztott, skálázódó adatbázis-kezelő rendszer

Cloud Data Management: A Short Overview and Comparison of Current Approaches

nosql and Non Relational Databases

Survey of Apache Big Data Stack

Hypertable Architecture Overview

A Review of Column-Oriented Datastores. By: Zach Pratt. Independent Study Dr. Maskarinec Spring 2011

NoSQL: Going Beyond Structured Data and RDBMS

USC Viterbi School of Engineering

SQL VS. NO-SQL. Adapted Slides from Dr. Jennifer Widom from Stanford

extensible record stores document stores key-value stores Rick Cattel s clustering from Scalable SQL and NoSQL Data Stores SIGMOD Record, 2010

Apache Cassandra 1.2 Documentation

NoSQL Databases. Nikos Parlavantzas

Future Prospects of Scalable Cloud Computing


Case study: CASSANDRA

Designing Performance Monitoring Tool for NoSQL Cassandra Distributed Database

NOSQL DATABASES AND CASSANDRA

A REVIEW ON EFFICIENT DATA ANALYSIS FRAMEWORK FOR INCREASING THROUGHPUT IN BIG DATA. Technology, Coimbatore. Engineering and Technology, Coimbatore.

Preparing Your Data For Cloud

Which NoSQL Database? A Performance Overview

NoSQL Databases: a step to database scalability in Web environment

BRAC. Investigating Cloud Data Storage UNIVERSITY SCHOOL OF ENGINEERING. SUPERVISOR: Dr. Mumit Khan DEPARTMENT OF COMPUTER SCIENCE AND ENGEENIRING

Scalable Multiple NameNodes Hadoop Cloud Storage System

An Open Source NoSQL solution for Internet Access Logs Analysis

Apache Cassandra 1.2

Big Data and Hadoop with components like Flume, Pig, Hive and Jaql

Benchmarking Failover Characteristics of Large-Scale Data Storage Applications: Cassandra and Voldemort

HDB++: HIGH AVAILABILITY WITH. l TANGO Meeting l 20 May 2015 l Reynald Bourtembourg

Distributed Lucene : A distributed free text index for Hadoop

Challenges for Data Driven Systems

Dynamo: Amazon s Highly Available Key-value Store

A COMPARATIVE STUDY OF NOSQL DATA STORAGE MODELS FOR BIG DATA

Cassandra - A Decentralized Structured Storage System

Overview of Databases On MacOS. Karl Kuehn Automation Engineer RethinkDB

Cloud Scale Distributed Data Storage. Jürmo Mehine

Cassandra - A Decentralized Structured Storage System

A programming model in Cloud: MapReduce

A TAXONOMY AND COMPARISON OF HADOOP DISTRIBUTED FILE SYSTEM WITH CASSANDRA FILE SYSTEM

Comparing SQL and NOSQL databases

Contents Set up Cassandra Cluster using Datastax Community Edition on Amazon EC2 Installing OpsCenter on Amazon AMI References Contact

Big Table A Distributed Storage System For Data

Real-Time Big Data in practice with Cassandra. Michaël

An Oracle White Paper April Back to the Future with Oracle Database 12c

these three NoSQL databases because I wanted to see a the two different sides of the CAP

Distributed Data Stores

Review of Query Processing Techniques of Cloud Databases Ruchi Nanda Assistant Professor, IIS University Jaipur.

Big Data Development CASSANDRA NoSQL Training - Workshop. March 13 to am to 5 pm HOTEL DUBAI GRAND DUBAI

Institutionen för datavetenskap Department of Computer and Information Science

COMPARATIVE STUDY OF NOSQL DOCUMENT, COLUMN STORE DATABASES AND EVALUATION OF CASSANDRA

Cassandra A Decentralized Structured Storage System

HBase A Comprehensive Introduction. James Chin, Zikai Wang Monday, March 14, 2011 CS 227 (Topics in Database Management) CIT 367

Cassandra: Principles and Application

Apache Cassandra 2.0

EXPERIMENTAL EVALUATION OF NOSQL DATABASES

Axway API Gateway. Version 7.4.1

Data Management Course Syllabus

Automatic, multi- grained elasticity- provisioning for the Cloud

Measuring Elasticity for Cloud Databases

Why NoSQL? Your database options in the new non- relational world IBM Cloudant 1

The Cloud Trade Off IBM Haifa Research Storage Systems

Comparison of Distribution Technologies in Different NoSQL Database Systems

Scalable Queries For Large Datasets Using Cloud Computing: A Case Study

Cloud Computing in Distributed System

On- Prem MongoDB- as- a- Service Powered by the CumuLogic DBaaS Platform

Transcription:

Hands-on Cassandra OSCON July 20, 2010 Eric Evans eevans@rackspace.com @jericevans http://blog.sym-link.com

2 Background

Influential Papers BigTable Strong consistency Sparse map data model GFS, Chubby, et al Dynamo O(1) distributed hash table (DHT) BASE (aka eventual consistency) Client tunable consistency/availability 3

NoSQL HBase Hypertable MongoDB HyperGraphDB Riak Memcached Voldemort Tokyo Cabinet Neo4J Redis Cassandra CouchDB 4

NoSQL Big data HBase Hypertable MongoDB HyperGraphDB Riak Memcached Voldemort Tokyo Cabinet Neo4J Redis Cassandra CouchDB 5

Bigtable / Dynamo Bigtable Dynamo HBase Riak Hypertable Voldemort Cassandra?? 6

7 Dynamo-Bigtable Lovechild

CAP Theorem Pick Two CP AP Bigtable Dynamo Hypertable Voldemort HBase Cassandra 8

CAP Theorem Pick Two Consistency Availability Partition Tolerance 9

History Facebook (2007-2008) Avinash, former Dynamo engineer Motivated by Inbox Search Google Code (2008-2009) Dark times Apache (2009-Present) Digg, Twitter, Rackspace, Others Rapidly growing community Fast-paced development 10

11 Hands-on Setup

Installation $ TUT_ROOT=$HOME $ cd $TUT_ROOT $ tar xfz apache-cassandra-xxxx-bin.tar.gz $ tar xfz twissandra-xxxx.tar.gz $ tar xfz pycassa-xxxx.tar.gz 12

Setup $ cp twissandra/cassandra.yaml \ apache-cassandra-xxxx/conf $ mkdir $TUT_ROOT/log $ mkdir -p $TUT_ROOT/lib/data $ mkdir -p $TUT_ROOT/lib/commitlog 13

Setup (continued) conf/cassandra.yaml # Where data is stored on disk data_file_directories: - TUT_ROOT/lib/data # Commit log commitlog_directory: TUT_ROOT/lib/commitlog 14

Setup (continued) conf/log4j-server.properties log4j.rootlogger=debug,stdout,r log4j.appender.r.file=tut_root/log/system.log 15

Starting up / Initializing $ cd $TUT_ROOT/apache-cassandra-xxxx $ bin/cassandra -f # In a new terminal $ cd $TUT_ROOT/apache-cassandra-xxxx $ bin/loadschemafromyaml localhost 8080 16

Pycassa / Twissandra $ cd $TUT_ROOT/pycassa $ sudo python setup.py -cassandra install \ [--prefix=/usr/local] $ cd $TUT_ROOT/twissandra $ python manage.py runserver 0.0.0.0:8000 17

18 Data Model

Users CREATE TABLE user ( id INTEGER PRIMARY KEY, username VARCHAR(64), password VARCHAR(64) ); 19

Friends and Followers CREATE TABLE followers ( user INTEGER REFERENCES user(id), follower INTEGER REFERENCES user(id) ); CREATE TABLE following ( user INTEGER REFERENCES user(id), followee INTEGER REFERENCES user(id) ); 20

Tweets CREATE TABLE tweets ( id INTEGER PRIMARY KEY, user INTEGER REFERENCES user(id), body VARCHAR(140), timestamp TIMESTAMP ); 21

Overview Keyspace Uppermost namespace Typically one per application ColumnFamily Associates records of a similar kind Record-level Atomicity Indexed Column Basic unit of storage 22

23 Sparse Table

Column name byte[] Queried against (predicates) Determines sort order value byte[] Opaque to Cassandra timestamp long Conflict resolution (Last Write Wins) 24

Column Comparators Bytes UTF8 TimeUUID Long LexicalUUID Composite (third-party) 25 http://github.com/edanuff/cassandracompositetype

Column Families User Username Friends Followers Tweet Timeline Userline 26

User / Username User Stores users Keyed on a unique ID (UUID). Columns for username and password Username Indexes User Keyed on username One column, the unique UUID for user 27

Friends and Followers Friends Maps a user to the users they follow Keyed on user ID Columns for each user being followed Followers Maps a user to those following them Keyed on username Columns for each user following 28

Tweets Keyed on a unique identifier Columns: Unique identifier User ID Body of the tweet timestamp 29

Timeline / Userline Timeline Keyed on user ID Columns that map timestamps to Tweet ID The materialized view of Tweets for a user. Userline Keyed on user ID Columns that map timestamps to Tweet ID The collection of Tweets attributed to a user 30

31 Pycassa

Pycassa Python Client API connect() Thrift proxy cf = ColumnFamily(proxy, ksp, cfname) cf.insert() long cf.get() dict cf.get_range() dict 32 http://github.com/vomjom/pycassa

Adding a User cass.save_user() username = 'jericevans' password = '**********' useruuid = str(uuid()) columns = { 'id': useruuid, 'username': username, 'password': password } USER.insert(useruuid, columns) USERNAME.insert(username, {'id': useruuid}) 33

Following a Friend cass.add_friends() FRIENDS.insert(userid, {friendid: time()}) FOLLOWERS.insert(friendid, {userid: time()}) 34

35 Tweeting cass.save_tweet() columns = { 'id': tweetid, 'user_id': useruuid, 'body': body, '_ts': timestamp } TWEET.insert(tweetid, columns) columns = {pack('>d', timestamp): tweetid} USERLINE.insert(useruuid, columns) TIMELINE.insert(useruuid, columns) for otheruuid in FOLLOWERS.get(useruuid, 5000): TIMELINE.insert(otheruuid, columns)

Getting a Timeline cass.get_timeline() start = request.get.get('start') limit = NUM_PER_PAGE timeline = TIMLINE.get( userid, column_start=start, column_count=limit, column_reversed=true ) tweets = TWEET.multiget(timeline.values()) 36

37 Hands-on pycassashell

38 Retweet

Adding Retweet $ cd $TUT_ROOT/twissandra $ patch -p1 <../django.patch $ patch -p1 <../retweet.patch 39

Retweet cass.save_retweet() ts = _long(int(time() * 1e6)) for follower in get_follower_ids(userid): TIMELINE.insert(follower_id, {ts: tweet_id}) 40

41 Clustering Concepts

42 P2P Routing

43 P2P Routing

Partitioning (see partitioner) Random 128bit namespace, (MD5) Good distribution Order Preserving Tokens determine namespace Natural order (lexicographical) Range / cover queries Yours?? 44

Replica Placement (see endpoint_snitch) SimpleSnitch Default N-1 successive nodes RackInferringSnitch Infers DC/rack from IP PropertyFileSnitch Configured w/ a properties file 45

46 Bootstrap (see auto_bootstrap)

47 Bootstrap

48 Bootstrap

Remember CAP? Consistency Availability Partition Tolerance 49

Choosing Consistency Write Level Description ZERO Hail Mary ANY 1 replica (HH) ONE 1 replica QUORUM (N / 2) +1 ALL All replicas Read Level Description ZERO N/A ANY N/A ONE 1 replica QUORUM (N / 2) +1 ALL All replicas R + W > N 50

51 Quorum ((N/2) + 1)

52 Quorum ((N/2) + 1)

53 Operations

Cluster sizing Data size and throughput Fault tolerance (replication) Data-center / hosting costs 54

Nodes Go commodity! Cores (more is better) Memory (more is better) Disks Commitlog Storage double-up for working space 55

56 Writes

57 Reads

Tuning (heap size) bin/cassandra.in.sh # Arguments to pass to the JVM JVM_OPTS= \ -Xmx1G \ 58

Tuning (memtable) conf/cassandra.yaml # Amount of data written memtable_throughput_in_mb: 64 # Number of objects written memtable_operations_in_millions: 0.3 # Time elapsed memtable_flush_after_mins: 60 59

Tuning (column families) conf/cassandra.yaml keyspaces: - name: Twissandra column_families: - name: User keys_cached: 100 preload_row_cache: true rows_cached: 1000 60

Tuning (mmap) conf/cassandra.yaml # Choices are auto, standard, mmap, and # mmap_index_only. disk_access_mode: auto 61

Nodetool bin/nodetool host <arg> command ring info cfstats tpstats 62

Nodetool (cont.) bin/nodetool host <arg> command compact snapshot [name] flush drain repair decommission move loadbalance 63

Clustertool bin/clustertool host <arg> command get_endpoints <keyspace> <key> global_snapshot [name] clear_global_snapshot truncate <keyspace> <cfname> 64

65 Wrapping Up

When Things Go Wrong Where to look Logs ERRORs, stack traces Enable DEBUG Isolate if possible Crash files (java_pid*.hprof, hs_err_pid*.log) nodetool / jconsole / etc Thread pool stats Column family stats 66

When Things Go Wrong What to do user@cassandra.apache.org user-subscribe@cassandra.apache.org http://www.mail-archive.com/user@cassandra.apache.org/ http://wiki.apache.org/cassandra https://issues.apache.org/jira/browse/cassandra #cassandra on irc.freenode.net 67

Further Reading Bigtable: A Distributed Storage System for Structured Data Fay Chang, Jeffrey Dean, Sanjay Ghemawat, Wilson C. Hsieh, Deborah A. Wallach, Mike Burrows, Tushar Chandra, Andrew Fikes, and Robert E. Gruber http://labs.google.com/papers/bigtable-osdi06.pdf Dynamo: Amazon s Highly Available Key-value Store Giuseppe DeCandia, Deniz Hastorun, Madan Jampani, Gunavardhan Kakulapati, Avinash Lakshman, Alex Pilchin, Swaminathan Sivasubramanian, Peter Vosshall and Werner Vogels http://www.allthingsdistributed.com/2007/10/amazons_dynamo.html 68

Thanks Apache Cassandra: http://cassandra.apache.org Twissandra: Eric Florenzano (and others) http://github.com/ericflo/twissandra Pycassa: Jonathan Hseu (and others) http://github.com/vomjom/pycassa 69

Fin