SlideShare una empresa de Scribd logo
1 de 33
Descargar para leer sin conexión
Going Native With Apache Cassandra™
QCon London, 2014
www.datastax.com
@DataStaxEMEA
About Me
©2014 DataStax. Do not distribute without consent. 2
Johnny Miller
Solutions Architect
www.datastax.com
@DataStaxEU
@CyanMiller
•  https://www.linkedin.com/in/johnnymiller
DataStax
©2014 DataStax. Do not distribute without consent. 3
•  Founded in April 2010
•  We drive Apache Cassandra™
•  400+ customers (24 of the Fortune 100)
•  220+ employees
•  Contribute approximately 80% of the code to Cassandra
•  Home to Apache Cassandra Chair & most committers
•  Headquartered in San Francisco Bay area
•  European headquarters established in London
We are hiring
www.datastax.com/careers
What do I mean by going native?
©2014 DataStax. Do not distribute without consent. 4
•  Traditionally, Cassandra clients (Hector, Astynax1 etc..) were
developed using Thrift
•  With Cassandra 1.2 (Jan 2013) and the introduction of CQL3
and the CQL native protocol a new easier way of using
Cassandra was introduced.
•  Why?
•  Easier to develop and model
•  Best practices for building modern distributed applications
•  Integrated tools and experience
•  Enable Cassandra to evolve easier and support new features
1Astynax is being updated to include the native driver: https://github.com/Netflix/astyanax/wiki/Astyanax-over-Java-Driver
CQL
©2014 DataStax. Do not distribute without consent. 5
•  Cassandra Query Language
•  CQL is intended to provide a common, simpler and
easier to use interface into Cassandra - and you
probably already know it!
e.g. SELECT * FROM users
•  Usual statements
•  CREATE / DROP / ALTER TABLE / SELECT
Creating A Keyspace
©2014 DataStax. Do not distribute without consent. 6
CREATE KEYSPACE johnny WITH REPLICATION =
{‘class’:’NetworkTopologyStrategy’, ‘USA’:3, ‘EU’: 2};
Node 1
1st copy
Node 4
Node 5
Node 2
2nd copy
Node 3
Node 1
1st copy
Node 4
Node 5
Node 2
2nd copy
Node 3
3rd copy
DC: USA DC: EU
CQL Basics
©2014 DataStax. Do not distribute without consent. 7
CREATE TABLE sporty_league (
team_name varchar,
player_name varchar,
jersey int,
PRIMARY KEY (team_name, player_name)
);
SELECT * FROM sporty_league WHERE team_name = ‘Mighty Mutts’ and player_name = ‘Lucky’;
INSERT INTO sporty_league (team_name, player_name, jersey) VALUES ('Mighty Mutts',’Felix’,
90);
Predicates
•  On the partition key: = and IN
•  On the cluster columns: <, <=, =, >=, >, IN
Collections Data Type
©2014 DataStax. Do not distribute without consent. 8
•  CQL supports having columns that contain collections of data.
•  The collection types include:
•  Set, List and Map.
•  Some performance considerations around collections.
•  Sometimes more efficient to denormalise further rather than use
collections if intending to store lots of data.
•  Favour sets over list – more performant
•  Watch out for collection indexing in Cassandra 2.1!
CREATE TABLE collections_example (
id int PRIMARY KEY,
set_example set<text>,
list_example list<text>,
map_example map<int, text>
);
Query Tracing
©2014 DataStax. Do not distribute without consent. 9
•  You can turn tracing on or off for queries with the TRACING ON |
OFF command.
•  This can help you understand what Cassandra is doing and identify
any performance problems.
Worth reading: http://www.datastax.com/dev/blog/tracing-in-cassandra-1-2
Plus much, much more…
©2014 DataStax. Do not distribute without consent. 10
•  Light Weight Transactions
INSERT INTO customer_account (customerID, customer_email) VALUES (‘LauraS’, ‘lauras@gmail.com’) IF NOT
EXISTS;
UPDATE customer_account SET customer_email=’laurass@gmail.com’
IF customer_email=’lauras@gmail.com’;
•  Counters
UPDATE UserActions SET total = total + 2
WHERE user = 123 AND action = ’xyz';
•  Time to live (TTL)
INSERT INTO users (id, first, last) VALUES (‘abc123’, ‘abe’, ‘lincoln’) USING TTL 3600;
•  Batch Statements
BEGIN BATCH
INSERT INTO users (userID, password, name) VALUES ('user2', 'ch@ngem3b', 'second user')
UPDATE users SET password = 'ps22dhds' WHERE userID = 'user2'
INSERT INTO users (userID, password) VALUES ('user3', 'ch@ngem3c')
DELETE name FROM users WHERE userID = 'user2’
APPLY BATCH;
•  New CQL features coming in Cassandra 2.0.6
•  http://www.datastax.com/dev/blog/cql-in-2-0-6
CQL Native Protocol
Request Pipelining
©2014 DataStax. Do not distribute without consent. 12
With it:
Without it:
Notifications
©2014 DataStax. Do not distribute without consent. 13
Without Notifications
With Notifications
Polling
Pushing
Notifications are for technical events only:
•  Topology changes
•  Node status changes,
•  Schema changes
Asynchronous Architecture
©2014 DataStax. Do not distribute without consent. 14
Client
Thread
Client
Thread
Client
Thread
Driver
1
2 3
4
5
6
Native Drivers
Native Drivers
©2014 DataStax. Do not distribute without consent. 16
•  Java
•  C#
•  Python
•  C++ (beta)
•  ODBC (beta)
•  Clojure
•  Erlang
•  Node.js
•  Ruby
•  Plus many, many more….
Get them here: http://www.datastax.com/download
Connect and Write
©2014 DataStax. Do not distribute without consent. 17
Cluster cluster = Cluster.builder()
.addContactPoints("10.158.02.40", "10.158.02.44")
.build();
Session session = cluster.connect("akeyspace");
session.execute(
"INSERT INTO user (username, password) ”
+ "VALUES(‘johnny’, ‘password1234’)"
);
Note: Clusters and Sessions should be long-lived and re-used.
Read from a table
©2014 DataStax. Do not distribute without consent. 18
ResultSet rs = session.execute("SELECT * FROM user");
List<Row> rows = rs.all();
for (Row row : rows) {
String userName = row.getString("username");
String password = row.getString("password");
}
Asynchronous Read
©2014 DataStax. Do not distribute without consent. 19
ResultSetFuture future = session.executeAsync(
"SELECT * FROM user");
for (Row row : future.get()) {
String userName = row.getString("username");
String password = row.getString("password");
}
Note: The future returned implements Guava's ListenableFuture interface. This
means you can use all Guava's Futures1 methods!
1http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/util/concurrent/Futures.html
Read with Callbacks
©2014 DataStax. Do not distribute without consent. 20
final ResultSetFuture future =
session.executeAsync("SELECT * FROM user");
future.addListener(new Runnable() {
public void run() {
for (Row row : future.get()) {
String userName = row.getString("username");
String password = row.getString("password");
}
}
}, executor);
Parallelize Calls
©2014 DataStax. Do not distribute without consent. 21
int queryCount = 99;
List<ResultSetFuture> futures = new ArrayList<ResultSetFuture>();
for (int i=0; i<queryCount; i++) {
futures.add(
session.executeAsync("SELECT * FROM user "
+"WHERE username = '"+i+"'"));
}
for(ResultSetFuture future : futures) {
for (Row row : future.getUninterruptibly()) {
//do something
}
}
Tip
©2014 DataStax. Do not distribute without consent. 22
•  If you need to do a lot of work, it’s often better to
make many small queries concurrently than to make
one big query.
•  executeAsync and Futures – makes this really easy!
•  Big queries can put a high load on one coordinator
•  Big queries can skew your 99th percentile latencies for
other queries
•  If one small query fails you can easily retry, if a big query
than you have to retry the whole thing
Prepared Statements
©2014 DataStax. Do not distribute without consent. 23
PreparedStatement statement = session.prepare(
"INSERT INTO user (username, password) "
+ "VALUES (?, ?)");
BoundStatement bs = statement.bind();
bs.setString("username", "johnny");
bs.setString("password", "password1234");
session.execute(bs);
Query Builder
©2014 DataStax. Do not distribute without consent. 24
Query query = QueryBuilder
.select()
.all()
.from("akeyspace", "user")
.where(eq("username", "johnny"));
query.setConsistencyLevel(ConsistencyLevel.ONE);
ResultSet rs = session.execute(query);
Multi Data Center Load Balancing
©2014 DataStax. Do not distribute without consent. 25
•  Local nodes are queried first, if none are available
the request will be sent to a remote data center
Cluster cluster = Cluster.builder()	
	 	.addContactPoints("10.158.02.40", "10.158.02.44")	
	 	.withLoadBalancingPolicy(	
	 	 	new DCAwareRoundRobinPolicy("DC1"))	
	 	.build();	
	
	
	
	
	
Name of the local DC
Token Aware Load Balancing
©2014 DataStax. Do not distribute without consent. 26
•  Nodes that own a replica of the data being read or
written by the query will be contacted first
Cluster cluster = Cluster.builder()	
	 	.addContactPoints("10.158.02.40", "10.158.02.44")	
	 	.withLoadBalancingPolicy(	
	 	 	new TokenAwarePolicy(	
	 	 	 	new DCAwareRoundRobinPolicy("DC1")))	
	 	.build();	
	
	
	
	
http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/policies/TokenAwarePolicy.html
Retry Policies
©2014 DataStax. Do not distribute without consent. 27
•  This defined the behavior to adopt when a request
returns a timeout or is unavailable.
Cluster cluster = Cluster.builder()
.addContactPoints("10.158.02.40", "10.158.02.44")
.withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE)
.withLoadBalancingPolicy(new TokenAwarePolicy(new
DCAwareRoundRobinPolicy("DC1")))
.build();
•  DefaultRetryPolicy
•  DowngradingConsistencyRetryPolicy
•  FallthroughRetryPolicy
•  LoggingRetryPolicy
http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/policies/RetryPolicy.html
Reconnection Policies
©2014 DataStax. Do not distribute without consent. 28
•  Policy that decides how often the reconnection to a
dead node is attempted.
Cluster cluster = Cluster.builder()
.addContactPoints("10.158.02.40", "10.158.02.44”)
.withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE)
.withReconnectionPolicy(new ConstantReconnectionPolicy(1000))
.withLoadBalancingPolicy(new TokenAwarePolicy(new
DCAwareRoundRobinPolicy("DC1")))
.build();

	
•  ConstantReconnectionPolicy
•  ExponentialReconnectionPolicy
Automatic Paging
©2014 DataStax. Do not distribute without consent. 29
•  This was new in Cassandra 2.0
•  Previously – you would select data in batches
Query Tracing
©2014 DataStax. Do not distribute without consent. 30
•  Tracing is enabled on a per-query basis.
Query query = QueryBuilder
.select()
.all()
.from("akeyspace", "user")
.where(eq("username", "johnny"))
.enableTracing();
ResultSet rs = session.execute(query);
ExecutionInfo executionInfo = rs.getExecutionInfo();
QueryTrace queryTrace = executionInfo.getQueryTrace();
DevCenter
©2014 DataStax. Do not distribute without consent. 31
•  Desktop app
•  friendly, familiar, productive
•  Free
http://www.datastax.com/devcenter
Find Out More
©2014 DataStax. Do not distribute without consent. 32
DataStax:
•  http://www.datastax.com
Getting Started:
•  http://www.datastax.com/documentation/gettingstarted/index.html
Training:
•  http://www.datatstax.com/training
Downloads:
•  http://www.datastax.com/download
Documentation:
•  http://www.datastax.com/docs
Developer Blog:
•  http://www.datastax.com/dev/blog
Community Site:
•  http://planetcassandra.org
Webinars:
•  http://planetcassandra.org/Learn/CassandraCommunityWebinars
©2014 DataStax. Do not distribute without consent. 33

Más contenido relacionado

La actualidad más candente

Apache Cassandra Certification
Apache Cassandra CertificationApache Cassandra Certification
Apache Cassandra CertificationVskills
 
Nyc summit intro_to_cassandra
Nyc summit intro_to_cassandraNyc summit intro_to_cassandra
Nyc summit intro_to_cassandrazznate
 
From PoCs to Production
From PoCs to ProductionFrom PoCs to Production
From PoCs to ProductionDataStax
 
Cassandra TK 2014 - Large Nodes
Cassandra TK 2014 - Large NodesCassandra TK 2014 - Large Nodes
Cassandra TK 2014 - Large Nodesaaronmorton
 
Introduction to DataStax Enterprise Graph Database
Introduction to DataStax Enterprise Graph DatabaseIntroduction to DataStax Enterprise Graph Database
Introduction to DataStax Enterprise Graph DatabaseDataStax Academy
 
Webinar | Introducing DataStax Enterprise 4.6
Webinar | Introducing DataStax Enterprise 4.6Webinar | Introducing DataStax Enterprise 4.6
Webinar | Introducing DataStax Enterprise 4.6DataStax
 
How to size up an Apache Cassandra cluster (Training)
How to size up an Apache Cassandra cluster (Training)How to size up an Apache Cassandra cluster (Training)
How to size up an Apache Cassandra cluster (Training)DataStax Academy
 
Webinar: Dyn + DataStax - helping companies deliver exceptional end-user expe...
Webinar: Dyn + DataStax - helping companies deliver exceptional end-user expe...Webinar: Dyn + DataStax - helping companies deliver exceptional end-user expe...
Webinar: Dyn + DataStax - helping companies deliver exceptional end-user expe...DataStax
 
C*ollege Credit: Is My App a Good Fit for Cassandra?
C*ollege Credit: Is My App a Good Fit for Cassandra?C*ollege Credit: Is My App a Good Fit for Cassandra?
C*ollege Credit: Is My App a Good Fit for Cassandra?DataStax
 
C* Summit 2013: Searching for a Needle in a Big Data Haystack by Jason Ruther...
C* Summit 2013: Searching for a Needle in a Big Data Haystack by Jason Ruther...C* Summit 2013: Searching for a Needle in a Big Data Haystack by Jason Ruther...
C* Summit 2013: Searching for a Needle in a Big Data Haystack by Jason Ruther...DataStax Academy
 
Cassandra Summit 2014: Apache Cassandra Best Practices at Ebay
Cassandra Summit 2014: Apache Cassandra Best Practices at EbayCassandra Summit 2014: Apache Cassandra Best Practices at Ebay
Cassandra Summit 2014: Apache Cassandra Best Practices at EbayDataStax Academy
 
Webinar: Getting Started with Apache Cassandra
Webinar: Getting Started with Apache CassandraWebinar: Getting Started with Apache Cassandra
Webinar: Getting Started with Apache CassandraDataStax
 
Introducing DataStax Enterprise 4.7
Introducing DataStax Enterprise 4.7Introducing DataStax Enterprise 4.7
Introducing DataStax Enterprise 4.7DataStax
 
Oracle to Cassandra Core Concepts Guide Pt. 2
Oracle to Cassandra Core Concepts Guide Pt. 2Oracle to Cassandra Core Concepts Guide Pt. 2
Oracle to Cassandra Core Concepts Guide Pt. 2DataStax Academy
 
Oracle to Cassandra Core Concepts Guid Part 1: A new hope
Oracle to Cassandra Core Concepts Guid Part 1: A new hopeOracle to Cassandra Core Concepts Guid Part 1: A new hope
Oracle to Cassandra Core Concepts Guid Part 1: A new hopeDataStax
 
Real-time personal trainer on the SMACK stack
Real-time personal trainer on the SMACK stackReal-time personal trainer on the SMACK stack
Real-time personal trainer on the SMACK stackAnirvan Chakraborty
 
Making Every Drop Count: How i20 Addresses the Water Crisis with the IoT and ...
Making Every Drop Count: How i20 Addresses the Water Crisis with the IoT and ...Making Every Drop Count: How i20 Addresses the Water Crisis with the IoT and ...
Making Every Drop Count: How i20 Addresses the Water Crisis with the IoT and ...DataStax
 
Cold Storage That Isn't Glacial (Joshua Hollander, Protectwise) | Cassandra S...
Cold Storage That Isn't Glacial (Joshua Hollander, Protectwise) | Cassandra S...Cold Storage That Isn't Glacial (Joshua Hollander, Protectwise) | Cassandra S...
Cold Storage That Isn't Glacial (Joshua Hollander, Protectwise) | Cassandra S...DataStax
 
Cassandra Community Webinar: MySQL to Cassandra - What I Wish I'd Known
Cassandra Community Webinar: MySQL to Cassandra - What I Wish I'd KnownCassandra Community Webinar: MySQL to Cassandra - What I Wish I'd Known
Cassandra Community Webinar: MySQL to Cassandra - What I Wish I'd KnownDataStax
 
How jKool Analyzes Streaming Data in Real Time with DataStax
How jKool Analyzes Streaming Data in Real Time with DataStaxHow jKool Analyzes Streaming Data in Real Time with DataStax
How jKool Analyzes Streaming Data in Real Time with DataStaxDataStax
 

La actualidad más candente (20)

Apache Cassandra Certification
Apache Cassandra CertificationApache Cassandra Certification
Apache Cassandra Certification
 
Nyc summit intro_to_cassandra
Nyc summit intro_to_cassandraNyc summit intro_to_cassandra
Nyc summit intro_to_cassandra
 
From PoCs to Production
From PoCs to ProductionFrom PoCs to Production
From PoCs to Production
 
Cassandra TK 2014 - Large Nodes
Cassandra TK 2014 - Large NodesCassandra TK 2014 - Large Nodes
Cassandra TK 2014 - Large Nodes
 
Introduction to DataStax Enterprise Graph Database
Introduction to DataStax Enterprise Graph DatabaseIntroduction to DataStax Enterprise Graph Database
Introduction to DataStax Enterprise Graph Database
 
Webinar | Introducing DataStax Enterprise 4.6
Webinar | Introducing DataStax Enterprise 4.6Webinar | Introducing DataStax Enterprise 4.6
Webinar | Introducing DataStax Enterprise 4.6
 
How to size up an Apache Cassandra cluster (Training)
How to size up an Apache Cassandra cluster (Training)How to size up an Apache Cassandra cluster (Training)
How to size up an Apache Cassandra cluster (Training)
 
Webinar: Dyn + DataStax - helping companies deliver exceptional end-user expe...
Webinar: Dyn + DataStax - helping companies deliver exceptional end-user expe...Webinar: Dyn + DataStax - helping companies deliver exceptional end-user expe...
Webinar: Dyn + DataStax - helping companies deliver exceptional end-user expe...
 
C*ollege Credit: Is My App a Good Fit for Cassandra?
C*ollege Credit: Is My App a Good Fit for Cassandra?C*ollege Credit: Is My App a Good Fit for Cassandra?
C*ollege Credit: Is My App a Good Fit for Cassandra?
 
C* Summit 2013: Searching for a Needle in a Big Data Haystack by Jason Ruther...
C* Summit 2013: Searching for a Needle in a Big Data Haystack by Jason Ruther...C* Summit 2013: Searching for a Needle in a Big Data Haystack by Jason Ruther...
C* Summit 2013: Searching for a Needle in a Big Data Haystack by Jason Ruther...
 
Cassandra Summit 2014: Apache Cassandra Best Practices at Ebay
Cassandra Summit 2014: Apache Cassandra Best Practices at EbayCassandra Summit 2014: Apache Cassandra Best Practices at Ebay
Cassandra Summit 2014: Apache Cassandra Best Practices at Ebay
 
Webinar: Getting Started with Apache Cassandra
Webinar: Getting Started with Apache CassandraWebinar: Getting Started with Apache Cassandra
Webinar: Getting Started with Apache Cassandra
 
Introducing DataStax Enterprise 4.7
Introducing DataStax Enterprise 4.7Introducing DataStax Enterprise 4.7
Introducing DataStax Enterprise 4.7
 
Oracle to Cassandra Core Concepts Guide Pt. 2
Oracle to Cassandra Core Concepts Guide Pt. 2Oracle to Cassandra Core Concepts Guide Pt. 2
Oracle to Cassandra Core Concepts Guide Pt. 2
 
Oracle to Cassandra Core Concepts Guid Part 1: A new hope
Oracle to Cassandra Core Concepts Guid Part 1: A new hopeOracle to Cassandra Core Concepts Guid Part 1: A new hope
Oracle to Cassandra Core Concepts Guid Part 1: A new hope
 
Real-time personal trainer on the SMACK stack
Real-time personal trainer on the SMACK stackReal-time personal trainer on the SMACK stack
Real-time personal trainer on the SMACK stack
 
Making Every Drop Count: How i20 Addresses the Water Crisis with the IoT and ...
Making Every Drop Count: How i20 Addresses the Water Crisis with the IoT and ...Making Every Drop Count: How i20 Addresses the Water Crisis with the IoT and ...
Making Every Drop Count: How i20 Addresses the Water Crisis with the IoT and ...
 
Cold Storage That Isn't Glacial (Joshua Hollander, Protectwise) | Cassandra S...
Cold Storage That Isn't Glacial (Joshua Hollander, Protectwise) | Cassandra S...Cold Storage That Isn't Glacial (Joshua Hollander, Protectwise) | Cassandra S...
Cold Storage That Isn't Glacial (Joshua Hollander, Protectwise) | Cassandra S...
 
Cassandra Community Webinar: MySQL to Cassandra - What I Wish I'd Known
Cassandra Community Webinar: MySQL to Cassandra - What I Wish I'd KnownCassandra Community Webinar: MySQL to Cassandra - What I Wish I'd Known
Cassandra Community Webinar: MySQL to Cassandra - What I Wish I'd Known
 
How jKool Analyzes Streaming Data in Real Time with DataStax
How jKool Analyzes Streaming Data in Real Time with DataStaxHow jKool Analyzes Streaming Data in Real Time with DataStax
How jKool Analyzes Streaming Data in Real Time with DataStax
 

Similar a Going native with Apache Cassandra

Introduction to CQL and Data Modeling with Apache Cassandra
Introduction to CQL and Data Modeling with Apache CassandraIntroduction to CQL and Data Modeling with Apache Cassandra
Introduction to CQL and Data Modeling with Apache CassandraJohnny Miller
 
Helsinki Cassandra Meetup #2: Introduction to CQL3 and DataModeling
Helsinki Cassandra Meetup #2: Introduction to CQL3 and DataModelingHelsinki Cassandra Meetup #2: Introduction to CQL3 and DataModeling
Helsinki Cassandra Meetup #2: Introduction to CQL3 and DataModelingBruno Amaro Almeida
 
Druid and Hive Together : Use Cases and Best Practices
Druid and Hive Together : Use Cases and Best PracticesDruid and Hive Together : Use Cases and Best Practices
Druid and Hive Together : Use Cases and Best PracticesDataWorks Summit
 
BI, Reporting and Analytics on Apache Cassandra
BI, Reporting and Analytics on Apache CassandraBI, Reporting and Analytics on Apache Cassandra
BI, Reporting and Analytics on Apache CassandraVictor Coustenoble
 
Webinar: DataStax Enterprise 5.0 What’s New and How It’ll Make Your Life Easier
Webinar: DataStax Enterprise 5.0 What’s New and How It’ll Make Your Life EasierWebinar: DataStax Enterprise 5.0 What’s New and How It’ll Make Your Life Easier
Webinar: DataStax Enterprise 5.0 What’s New and How It’ll Make Your Life EasierDataStax
 
NoSQL's biggest lie: SQL never went away - Martin Esmann
NoSQL's biggest lie: SQL never went away - Martin EsmannNoSQL's biggest lie: SQL never went away - Martin Esmann
NoSQL's biggest lie: SQL never went away - Martin Esmanndistributed matters
 
Demystifying Data Warehouse as a Service (DWaaS)
Demystifying Data Warehouse as a Service (DWaaS)Demystifying Data Warehouse as a Service (DWaaS)
Demystifying Data Warehouse as a Service (DWaaS)Kent Graziano
 
Johnny Miller – Cassandra + Spark = Awesome- NoSQL matters Barcelona 2014
Johnny Miller – Cassandra + Spark = Awesome- NoSQL matters Barcelona 2014Johnny Miller – Cassandra + Spark = Awesome- NoSQL matters Barcelona 2014
Johnny Miller – Cassandra + Spark = Awesome- NoSQL matters Barcelona 2014NoSQLmatters
 
Can Your Mobile Infrastructure Survive 1 Million Concurrent Users?
Can Your Mobile Infrastructure Survive 1 Million Concurrent Users?Can Your Mobile Infrastructure Survive 1 Million Concurrent Users?
Can Your Mobile Infrastructure Survive 1 Million Concurrent Users?TechWell
 
Webinar - QuerySurge and Azure DevOps in the Azure Cloud
 Webinar - QuerySurge and Azure DevOps in the Azure Cloud Webinar - QuerySurge and Azure DevOps in the Azure Cloud
Webinar - QuerySurge and Azure DevOps in the Azure CloudRTTS
 
Spark + Cassandra = Real Time Analytics on Operational Data
Spark + Cassandra = Real Time Analytics on Operational DataSpark + Cassandra = Real Time Analytics on Operational Data
Spark + Cassandra = Real Time Analytics on Operational DataVictor Coustenoble
 
Enterprise Architecture vs. Data Architecture
Enterprise Architecture vs. Data ArchitectureEnterprise Architecture vs. Data Architecture
Enterprise Architecture vs. Data ArchitectureDATAVERSITY
 
What We Learned About Cassandra While Building go90 (Christopher Webster & Th...
What We Learned About Cassandra While Building go90 (Christopher Webster & Th...What We Learned About Cassandra While Building go90 (Christopher Webster & Th...
What We Learned About Cassandra While Building go90 (Christopher Webster & Th...DataStax
 
High available BizTalk infrastructure on Azure IaaS
High available BizTalk infrastructure on Azure IaaSHigh available BizTalk infrastructure on Azure IaaS
High available BizTalk infrastructure on Azure IaaSBizTalk360
 
Delivering Apache Hadoop for the Modern Data Architecture
Delivering Apache Hadoop for the Modern Data Architecture Delivering Apache Hadoop for the Modern Data Architecture
Delivering Apache Hadoop for the Modern Data Architecture Hortonworks
 
ASHviz - Dats visualization research experiments using ASH data
ASHviz - Dats visualization research experiments using ASH dataASHviz - Dats visualization research experiments using ASH data
ASHviz - Dats visualization research experiments using ASH dataJohn Beresniewicz
 
DataStax NYC Java Meetup: Cassandra with Java
DataStax NYC Java Meetup: Cassandra with JavaDataStax NYC Java Meetup: Cassandra with Java
DataStax NYC Java Meetup: Cassandra with Javacarolinedatastax
 
Webinar: Get On-Demand Education Anytime, Anywhere with Coursera and DataStax
Webinar: Get On-Demand Education Anytime, Anywhere with Coursera and DataStaxWebinar: Get On-Demand Education Anytime, Anywhere with Coursera and DataStax
Webinar: Get On-Demand Education Anytime, Anywhere with Coursera and DataStaxDataStax
 

Similar a Going native with Apache Cassandra (20)

Introduction to CQL and Data Modeling with Apache Cassandra
Introduction to CQL and Data Modeling with Apache CassandraIntroduction to CQL and Data Modeling with Apache Cassandra
Introduction to CQL and Data Modeling with Apache Cassandra
 
Helsinki Cassandra Meetup #2: Introduction to CQL3 and DataModeling
Helsinki Cassandra Meetup #2: Introduction to CQL3 and DataModelingHelsinki Cassandra Meetup #2: Introduction to CQL3 and DataModeling
Helsinki Cassandra Meetup #2: Introduction to CQL3 and DataModeling
 
Druid and Hive Together : Use Cases and Best Practices
Druid and Hive Together : Use Cases and Best PracticesDruid and Hive Together : Use Cases and Best Practices
Druid and Hive Together : Use Cases and Best Practices
 
BI, Reporting and Analytics on Apache Cassandra
BI, Reporting and Analytics on Apache CassandraBI, Reporting and Analytics on Apache Cassandra
BI, Reporting and Analytics on Apache Cassandra
 
Webinar: DataStax Enterprise 5.0 What’s New and How It’ll Make Your Life Easier
Webinar: DataStax Enterprise 5.0 What’s New and How It’ll Make Your Life EasierWebinar: DataStax Enterprise 5.0 What’s New and How It’ll Make Your Life Easier
Webinar: DataStax Enterprise 5.0 What’s New and How It’ll Make Your Life Easier
 
NoSQL's biggest lie: SQL never went away - Martin Esmann
NoSQL's biggest lie: SQL never went away - Martin EsmannNoSQL's biggest lie: SQL never went away - Martin Esmann
NoSQL's biggest lie: SQL never went away - Martin Esmann
 
Demystifying Data Warehouse as a Service (DWaaS)
Demystifying Data Warehouse as a Service (DWaaS)Demystifying Data Warehouse as a Service (DWaaS)
Demystifying Data Warehouse as a Service (DWaaS)
 
Johnny Miller – Cassandra + Spark = Awesome- NoSQL matters Barcelona 2014
Johnny Miller – Cassandra + Spark = Awesome- NoSQL matters Barcelona 2014Johnny Miller – Cassandra + Spark = Awesome- NoSQL matters Barcelona 2014
Johnny Miller – Cassandra + Spark = Awesome- NoSQL matters Barcelona 2014
 
Can Your Mobile Infrastructure Survive 1 Million Concurrent Users?
Can Your Mobile Infrastructure Survive 1 Million Concurrent Users?Can Your Mobile Infrastructure Survive 1 Million Concurrent Users?
Can Your Mobile Infrastructure Survive 1 Million Concurrent Users?
 
Webinar - QuerySurge and Azure DevOps in the Azure Cloud
 Webinar - QuerySurge and Azure DevOps in the Azure Cloud Webinar - QuerySurge and Azure DevOps in the Azure Cloud
Webinar - QuerySurge and Azure DevOps in the Azure Cloud
 
Spark + Cassandra = Real Time Analytics on Operational Data
Spark + Cassandra = Real Time Analytics on Operational DataSpark + Cassandra = Real Time Analytics on Operational Data
Spark + Cassandra = Real Time Analytics on Operational Data
 
Exploring sql server 2016
Exploring sql server 2016Exploring sql server 2016
Exploring sql server 2016
 
Exploring sql server 2016 bi
Exploring sql server 2016 biExploring sql server 2016 bi
Exploring sql server 2016 bi
 
Enterprise Architecture vs. Data Architecture
Enterprise Architecture vs. Data ArchitectureEnterprise Architecture vs. Data Architecture
Enterprise Architecture vs. Data Architecture
 
What We Learned About Cassandra While Building go90 (Christopher Webster & Th...
What We Learned About Cassandra While Building go90 (Christopher Webster & Th...What We Learned About Cassandra While Building go90 (Christopher Webster & Th...
What We Learned About Cassandra While Building go90 (Christopher Webster & Th...
 
High available BizTalk infrastructure on Azure IaaS
High available BizTalk infrastructure on Azure IaaSHigh available BizTalk infrastructure on Azure IaaS
High available BizTalk infrastructure on Azure IaaS
 
Delivering Apache Hadoop for the Modern Data Architecture
Delivering Apache Hadoop for the Modern Data Architecture Delivering Apache Hadoop for the Modern Data Architecture
Delivering Apache Hadoop for the Modern Data Architecture
 
ASHviz - Dats visualization research experiments using ASH data
ASHviz - Dats visualization research experiments using ASH dataASHviz - Dats visualization research experiments using ASH data
ASHviz - Dats visualization research experiments using ASH data
 
DataStax NYC Java Meetup: Cassandra with Java
DataStax NYC Java Meetup: Cassandra with JavaDataStax NYC Java Meetup: Cassandra with Java
DataStax NYC Java Meetup: Cassandra with Java
 
Webinar: Get On-Demand Education Anytime, Anywhere with Coursera and DataStax
Webinar: Get On-Demand Education Anytime, Anywhere with Coursera and DataStaxWebinar: Get On-Demand Education Anytime, Anywhere with Coursera and DataStax
Webinar: Get On-Demand Education Anytime, Anywhere with Coursera and DataStax
 

Último

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 

Último (20)

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 

Going native with Apache Cassandra

  • 1. Going Native With Apache Cassandra™ QCon London, 2014 www.datastax.com @DataStaxEMEA
  • 2. About Me ©2014 DataStax. Do not distribute without consent. 2 Johnny Miller Solutions Architect www.datastax.com @DataStaxEU @CyanMiller •  https://www.linkedin.com/in/johnnymiller
  • 3. DataStax ©2014 DataStax. Do not distribute without consent. 3 •  Founded in April 2010 •  We drive Apache Cassandra™ •  400+ customers (24 of the Fortune 100) •  220+ employees •  Contribute approximately 80% of the code to Cassandra •  Home to Apache Cassandra Chair & most committers •  Headquartered in San Francisco Bay area •  European headquarters established in London We are hiring www.datastax.com/careers
  • 4. What do I mean by going native? ©2014 DataStax. Do not distribute without consent. 4 •  Traditionally, Cassandra clients (Hector, Astynax1 etc..) were developed using Thrift •  With Cassandra 1.2 (Jan 2013) and the introduction of CQL3 and the CQL native protocol a new easier way of using Cassandra was introduced. •  Why? •  Easier to develop and model •  Best practices for building modern distributed applications •  Integrated tools and experience •  Enable Cassandra to evolve easier and support new features 1Astynax is being updated to include the native driver: https://github.com/Netflix/astyanax/wiki/Astyanax-over-Java-Driver
  • 5. CQL ©2014 DataStax. Do not distribute without consent. 5 •  Cassandra Query Language •  CQL is intended to provide a common, simpler and easier to use interface into Cassandra - and you probably already know it! e.g. SELECT * FROM users •  Usual statements •  CREATE / DROP / ALTER TABLE / SELECT
  • 6. Creating A Keyspace ©2014 DataStax. Do not distribute without consent. 6 CREATE KEYSPACE johnny WITH REPLICATION = {‘class’:’NetworkTopologyStrategy’, ‘USA’:3, ‘EU’: 2}; Node 1 1st copy Node 4 Node 5 Node 2 2nd copy Node 3 Node 1 1st copy Node 4 Node 5 Node 2 2nd copy Node 3 3rd copy DC: USA DC: EU
  • 7. CQL Basics ©2014 DataStax. Do not distribute without consent. 7 CREATE TABLE sporty_league ( team_name varchar, player_name varchar, jersey int, PRIMARY KEY (team_name, player_name) ); SELECT * FROM sporty_league WHERE team_name = ‘Mighty Mutts’ and player_name = ‘Lucky’; INSERT INTO sporty_league (team_name, player_name, jersey) VALUES ('Mighty Mutts',’Felix’, 90); Predicates •  On the partition key: = and IN •  On the cluster columns: <, <=, =, >=, >, IN
  • 8. Collections Data Type ©2014 DataStax. Do not distribute without consent. 8 •  CQL supports having columns that contain collections of data. •  The collection types include: •  Set, List and Map. •  Some performance considerations around collections. •  Sometimes more efficient to denormalise further rather than use collections if intending to store lots of data. •  Favour sets over list – more performant •  Watch out for collection indexing in Cassandra 2.1! CREATE TABLE collections_example ( id int PRIMARY KEY, set_example set<text>, list_example list<text>, map_example map<int, text> );
  • 9. Query Tracing ©2014 DataStax. Do not distribute without consent. 9 •  You can turn tracing on or off for queries with the TRACING ON | OFF command. •  This can help you understand what Cassandra is doing and identify any performance problems. Worth reading: http://www.datastax.com/dev/blog/tracing-in-cassandra-1-2
  • 10. Plus much, much more… ©2014 DataStax. Do not distribute without consent. 10 •  Light Weight Transactions INSERT INTO customer_account (customerID, customer_email) VALUES (‘LauraS’, ‘lauras@gmail.com’) IF NOT EXISTS; UPDATE customer_account SET customer_email=’laurass@gmail.com’ IF customer_email=’lauras@gmail.com’; •  Counters UPDATE UserActions SET total = total + 2 WHERE user = 123 AND action = ’xyz'; •  Time to live (TTL) INSERT INTO users (id, first, last) VALUES (‘abc123’, ‘abe’, ‘lincoln’) USING TTL 3600; •  Batch Statements BEGIN BATCH INSERT INTO users (userID, password, name) VALUES ('user2', 'ch@ngem3b', 'second user') UPDATE users SET password = 'ps22dhds' WHERE userID = 'user2' INSERT INTO users (userID, password) VALUES ('user3', 'ch@ngem3c') DELETE name FROM users WHERE userID = 'user2’ APPLY BATCH; •  New CQL features coming in Cassandra 2.0.6 •  http://www.datastax.com/dev/blog/cql-in-2-0-6
  • 12. Request Pipelining ©2014 DataStax. Do not distribute without consent. 12 With it: Without it:
  • 13. Notifications ©2014 DataStax. Do not distribute without consent. 13 Without Notifications With Notifications Polling Pushing Notifications are for technical events only: •  Topology changes •  Node status changes, •  Schema changes
  • 14. Asynchronous Architecture ©2014 DataStax. Do not distribute without consent. 14 Client Thread Client Thread Client Thread Driver 1 2 3 4 5 6
  • 16. Native Drivers ©2014 DataStax. Do not distribute without consent. 16 •  Java •  C# •  Python •  C++ (beta) •  ODBC (beta) •  Clojure •  Erlang •  Node.js •  Ruby •  Plus many, many more…. Get them here: http://www.datastax.com/download
  • 17. Connect and Write ©2014 DataStax. Do not distribute without consent. 17 Cluster cluster = Cluster.builder() .addContactPoints("10.158.02.40", "10.158.02.44") .build(); Session session = cluster.connect("akeyspace"); session.execute( "INSERT INTO user (username, password) ” + "VALUES(‘johnny’, ‘password1234’)" ); Note: Clusters and Sessions should be long-lived and re-used.
  • 18. Read from a table ©2014 DataStax. Do not distribute without consent. 18 ResultSet rs = session.execute("SELECT * FROM user"); List<Row> rows = rs.all(); for (Row row : rows) { String userName = row.getString("username"); String password = row.getString("password"); }
  • 19. Asynchronous Read ©2014 DataStax. Do not distribute without consent. 19 ResultSetFuture future = session.executeAsync( "SELECT * FROM user"); for (Row row : future.get()) { String userName = row.getString("username"); String password = row.getString("password"); } Note: The future returned implements Guava's ListenableFuture interface. This means you can use all Guava's Futures1 methods! 1http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/util/concurrent/Futures.html
  • 20. Read with Callbacks ©2014 DataStax. Do not distribute without consent. 20 final ResultSetFuture future = session.executeAsync("SELECT * FROM user"); future.addListener(new Runnable() { public void run() { for (Row row : future.get()) { String userName = row.getString("username"); String password = row.getString("password"); } } }, executor);
  • 21. Parallelize Calls ©2014 DataStax. Do not distribute without consent. 21 int queryCount = 99; List<ResultSetFuture> futures = new ArrayList<ResultSetFuture>(); for (int i=0; i<queryCount; i++) { futures.add( session.executeAsync("SELECT * FROM user " +"WHERE username = '"+i+"'")); } for(ResultSetFuture future : futures) { for (Row row : future.getUninterruptibly()) { //do something } }
  • 22. Tip ©2014 DataStax. Do not distribute without consent. 22 •  If you need to do a lot of work, it’s often better to make many small queries concurrently than to make one big query. •  executeAsync and Futures – makes this really easy! •  Big queries can put a high load on one coordinator •  Big queries can skew your 99th percentile latencies for other queries •  If one small query fails you can easily retry, if a big query than you have to retry the whole thing
  • 23. Prepared Statements ©2014 DataStax. Do not distribute without consent. 23 PreparedStatement statement = session.prepare( "INSERT INTO user (username, password) " + "VALUES (?, ?)"); BoundStatement bs = statement.bind(); bs.setString("username", "johnny"); bs.setString("password", "password1234"); session.execute(bs);
  • 24. Query Builder ©2014 DataStax. Do not distribute without consent. 24 Query query = QueryBuilder .select() .all() .from("akeyspace", "user") .where(eq("username", "johnny")); query.setConsistencyLevel(ConsistencyLevel.ONE); ResultSet rs = session.execute(query);
  • 25. Multi Data Center Load Balancing ©2014 DataStax. Do not distribute without consent. 25 •  Local nodes are queried first, if none are available the request will be sent to a remote data center Cluster cluster = Cluster.builder() .addContactPoints("10.158.02.40", "10.158.02.44") .withLoadBalancingPolicy( new DCAwareRoundRobinPolicy("DC1")) .build(); Name of the local DC
  • 26. Token Aware Load Balancing ©2014 DataStax. Do not distribute without consent. 26 •  Nodes that own a replica of the data being read or written by the query will be contacted first Cluster cluster = Cluster.builder() .addContactPoints("10.158.02.40", "10.158.02.44") .withLoadBalancingPolicy( new TokenAwarePolicy( new DCAwareRoundRobinPolicy("DC1"))) .build(); http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/policies/TokenAwarePolicy.html
  • 27. Retry Policies ©2014 DataStax. Do not distribute without consent. 27 •  This defined the behavior to adopt when a request returns a timeout or is unavailable. Cluster cluster = Cluster.builder() .addContactPoints("10.158.02.40", "10.158.02.44") .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE) .withLoadBalancingPolicy(new TokenAwarePolicy(new DCAwareRoundRobinPolicy("DC1"))) .build(); •  DefaultRetryPolicy •  DowngradingConsistencyRetryPolicy •  FallthroughRetryPolicy •  LoggingRetryPolicy http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/policies/RetryPolicy.html
  • 28. Reconnection Policies ©2014 DataStax. Do not distribute without consent. 28 •  Policy that decides how often the reconnection to a dead node is attempted. Cluster cluster = Cluster.builder() .addContactPoints("10.158.02.40", "10.158.02.44”) .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE) .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)) .withLoadBalancingPolicy(new TokenAwarePolicy(new DCAwareRoundRobinPolicy("DC1"))) .build();
 •  ConstantReconnectionPolicy •  ExponentialReconnectionPolicy
  • 29. Automatic Paging ©2014 DataStax. Do not distribute without consent. 29 •  This was new in Cassandra 2.0 •  Previously – you would select data in batches
  • 30. Query Tracing ©2014 DataStax. Do not distribute without consent. 30 •  Tracing is enabled on a per-query basis. Query query = QueryBuilder .select() .all() .from("akeyspace", "user") .where(eq("username", "johnny")) .enableTracing(); ResultSet rs = session.execute(query); ExecutionInfo executionInfo = rs.getExecutionInfo(); QueryTrace queryTrace = executionInfo.getQueryTrace();
  • 31. DevCenter ©2014 DataStax. Do not distribute without consent. 31 •  Desktop app •  friendly, familiar, productive •  Free http://www.datastax.com/devcenter
  • 32. Find Out More ©2014 DataStax. Do not distribute without consent. 32 DataStax: •  http://www.datastax.com Getting Started: •  http://www.datastax.com/documentation/gettingstarted/index.html Training: •  http://www.datatstax.com/training Downloads: •  http://www.datastax.com/download Documentation: •  http://www.datastax.com/docs Developer Blog: •  http://www.datastax.com/dev/blog Community Site: •  http://planetcassandra.org Webinars: •  http://planetcassandra.org/Learn/CassandraCommunityWebinars
  • 33. ©2014 DataStax. Do not distribute without consent. 33