SlideShare une entreprise Scribd logo
1  sur  52
Télécharger pour lire hors ligne
Things You Should Be Doing When
Using Cassandra Drivers
Rebecca Mills
Junior Evangelist at Datastax
@rebccamills
What do I do?
2
Confidential
•  Try to create awareness for open source Cassandra
•  Develop content
•  Identify problems newcomers might be encountering
•  Develop strategies and material to help with that first
ease of initial use
Of course all this extends to drivers!
Confidential
 3
•  Learning and playing with the drivers as much as I
can
•  Develop “Getting Started” tutorials for drivers in
various programming languages
•  Making it my mission to bring the details to light
So How Can We Communicate with
Cassandra in “X” Language?
Confidential
 4
We have what you need!
Confidential
 5
•  Datastax provides drivers for Java, Python, C#
•  Fresh out of the oven Ruby, Node.js, and C++
•  Also loads of open source drivers to chose from
•  Check out the Planet Cassandra Client Drivers
section
Confidential
 6
Let’s get into some of the basics of
smart Cassandra driver usage:
1. One Cluster instance per cluster
Confidential
 7
•  Configure different important aspects of the way
connections and queries will be handled. 

•  Contact points
•  Retry Policies
•  Load Balancing Policies
cluster	
  =	
  Cluster(['10.1.1.3',	
  '10.1.1.4',	
  '10.1.1.5'],	
  
	
  	
  	
  	
  compression=True,	
  
	
  	
  	
  	
  load_balancing_policy=TokenAwarePolicy(	
  
	
  	
  	
  	
  	
  	
  	
  	
  DCAwareRoundRobinPolicy(local_dc='US_EAST')))	
  
2. One Session per keyspace
Confidential
 8
•  Query execution, connection pooling
•  Long-lived object
•  Not to be used in a request/response short-lived
fashion
•  Share the same cluster and session instances
across your application
Cluster & Session
Confidential
 9
cluster	
  =	
  Cluster(['10.1.1.3',	
  '10.1.1.4',	
  '10.1.1.5'],	
  
	
  	
  	
  	
  compression=True,	
  
	
  	
  	
  	
  load_balancing_policy=TokenAwarePolicy(	
  
	
  	
  	
  	
  	
  	
  	
  	
  DCAwareRoundRobinPolicy(local_dc='US_EAST')))	
  
	
  
session	
  =	
  cluster.connect('demo')	
  
3. Use Prepared Statements 
Confidential
 10
•  If you execute a statement more than once
•  Has multiple benefits
•  Prepare once, bind and execute multiple times
•  We’ll talk more about this soon!
Confidential
 11
Cool
Useful
Confidential
 12
Deep Dives:
Confidential
 13
•  Prepared Statements
•  Load Balancing Policies 
•  Retry Policies
•  Connection Pooling
•  Async API
Why use Prepared Statements?
Confidential
 14
•  More performant than using strings
•  Will be parsed only once on the server
•  We expect you to use them with repeated queries in
production
•  Avoid CQL injection
Prepared Statements
Confidential
 15
Consider a string

session.execute(""”	
  
	
  
INSERT	
  INTO	
  users	
  (lastname,	
  age,	
  city,	
  email,	
  firstname)	
  VALUES	
  (‘Jones’,	
  35,	
  
‘Austin’,	
  ‘bob@example.com’,	
  ‘Bob’)	
  
	
  
"""
Prepared Statements
Confidential
 16
session.execute("""	
  
INSERT	
  INTO	
  users	
  (lastname,	
  age,	
  city,	
  email,	
  firstname)	
  VALUES	
  (‘Smith’,	
  24,	
  ‘Tampa’,	
  ‘ken@example.com’,	
  ‘Bob’)	
  
	
  
""")	
  
	
  
session.execute(""”	
  
	
  
INSERT	
  INTO	
  users	
  (lastname,	
  age,	
  city,	
  email,	
  firstname)	
  VALUES	
  (‘Power’,	
  45,	
  ‘New	
  York’,	
  ‘kate@example.com’,	
  ‘Kate’)	
  
	
  
""")	
  
	
  
session.execute(""”	
  
	
  
INSERT	
  INTO	
  users	
  (lastname,	
  age,	
  city,	
  email,	
  firstname)	
  VALUES	
  (‘Renolds’,	
  33,	
  ‘Miami’,	
  ‘carl@example.com’,	
  ‘Carl’)	
  
	
  
""")	
  
Prepared Statements


Confidential
 17
Now the same, as a prepared statement
	
  
Prepared_stmt	
  =	
  session.prepare	
  (“INSERT	
  INTO	
  users	
  (lastname,	
  age,	
  city,	
  email,	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
firstname)	
  VALUES	
  (?,	
  ?,	
  ?,	
  ?,	
  ?)”)	
  
Bound_stmt	
  =	
  prepared.bind([‘Jones’,	
  35,	
  ‘Austin’,	
  ‘bob@example.com’,	
  ‘Bob’])	
  
Stmt	
  =	
  session.execute(bound_stmt)	
  	
  	
  
What’s the difference?
Confidential
 18
Prepared Statements
Confidential
 19
Client Cassandra
Entire Query String
Client Cassandra
Query ID & BoundValues
INSERT with strings
INSERT with PreparedStatements
Large amount of data
Parse cost
Smaller amount of data
No parsing
So what does that mean to me?
Confidential
 20
Speed!
Confidential
 21
Prepared Statements


Confidential
 22
http://techblog.netflix.com/2013/12/astyanax-update.html
Prepared Statements
Confidential
 23
Putting a prepared statement in a for loop is an anti-
pattern

	
  for	
  (int	
  i;	
  i	
  <	
  10;	
  i++)	
  {	
  
	
  	
  PreparedStatement	
  ps	
  =	
  session.prepare("UPDATE	
  user	
  SET	
  disabled	
  =	
  1	
  
WHERE	
  id	
  =	
  ?");	
  
	
  	
  	
  	
  
	
  	
  session.execute(ps.bind(i));	
  
}	
  
Load Balancing
Confidential
 24
•  A load balancing policy will determine which node to
run an insert or query.
•  Since a client can read or write to any node,
sometimes that can be inefficient.
•  If a node receives a read or write owned on another
node, it will coordinate that request for the client.
•  We can use a load balancing policy to control that
action.
Load Balancing deep dive
Confidential
 25
Using this example
Cluster cluster = new Cluster!
.builder().!
.addContactPoint(“10.0.0.1”)!
.withRetryPolicy(DefaultRetryPolicy.INSTANCE)!
.withLoadBalancingPolicy(!
new TokenAwarePolicy(!
new DCAwareRoundRobinPolicy())!
Example data model
Confidential
 26
CREATE TABLE users (!
username text PRIMARY KEY!
firstName text,!
lastName text!
);!
!
INSERT INTO users (username, firstName, lastName)!
VALUES (‘rmills’, ‘Rebecca’, ‘Mills’);!
!
INSERT INTO users (username, firstName, lastName)!
VALUES (‘pmcfadin’, ‘Patrick’, ‘McFadin’);!
!
Discover cluster
Confidential
 27
Client
.addContactPoint(“10.0.0.1”)!
10.0.0.1
00-25
10.0.0.4
76-100
10.0.0.2
26-50
10.0.0.3
51-75
RF=3
Populate connection pool
Confidential
 28
10.0.0.1
00-25
Client
10.0.0.4
76-100
10.0.0.2
26-50
10.0.0.3
51-75
Node Primary Replica Replica
10.0.0.1 00-25 76-100 51-75
10.0.0.2 26-50 00-25 76-100
10.0.0.3 51-75 26-50 00-25
10.0.0.4 76-100 51-75 26-50
DC1!
DC1!
Request for data
Confidential
 29
Client 10.0.0.1
00-25
10.0.0.4
76-100
10.0.0.2
26-50
10.0.0.3
51-75
SELECT firstName!
FROM users!
WHERE userName = ‘rmills’;!
rmills Murmur3 Hash Token = 15!
DC1!
Token Aware
Confidential
 30
Client 10.0.0.1
00-25
10.0.0.4
76-100
10.0.0.2
26-50
10.0.0.3
51-75
SELECT firstName!
FROM users!
WHERE userName = ‘rmills’;!
Token = 15!
withLoadBalancingPolicy(!
new TokenAwarePolicy(!
DC1!
Token Aware
Confidential
 31
Client 10.0.0.1
00-25
10.0.0.4
76-100
10.0.0.2
26-50
10.0.0.3
51-75
SELECT firstName!
FROM users!
WHERE userName = ‘rmills’;!
Token = 15!
DC1!
Which node?
DC1!
Node Primary Replica Replica
10.0.0.1 00-25 76-100 51-75
10.0.0.2 26-50 00-25 76-100
10.0.0.3 51-75 26-50 00-25
10.0.0.4 76-100 51-75 26-50
Token Aware
Confidential
 32
Client 10.0.0.1
00-25
10.0.0.4
76-100
10.0.0.2
26-50
10.0.0.3
51-75
SELECT firstName!
FROM users!
WHERE userName = ‘rmills’;!
Token = 15!
DC1!
DC1!
Node Primary Replica Replica
10.0.0.1 00-25 76-100 51-75
10.0.0.2 26-50 00-25 76-100
10.0.0.3 51-75 26-50 00-25
10.0.0.4 76-100 51-75 26-50
Token Aware
Confidential
 33
Client 10.0.0.1
00-25
10.0.0.4
76-100
10.0.0.2
26-50
10.0.0.3
51-75
SELECT firstName!
FROM users!
WHERE userName = ‘rmills’;!
Token = 15!
DC1!
DC1!
Node Primary Replica Replica
10.0.0.1 00-25 76-100 51-75
10.0.0.2 26-50 00-25 76-100
10.0.0.3 51-75 26-50 00-25
10.0.0.4 76-100 51-75 26-50
Node Primary Replica Replica
10.0.0.1 00-25 76-100 51-75
10.0.0.2 26-50 00-25 76-100
10.0.0.3 51-75 26-50 00-25
10.0.0.4 76-100 51-75 26-50
Token Aware
Confidential
 34
Client 10.0.0.1
00-25
10.0.0.4
76-100
10.0.0.2
26-50
10.0.0.3
51-75
SELECT firstName!
FROM users!
WHERE userName = ‘rmills’;!
DC1!
DC1!
withLoadBalancingPolicy(!
new TokenAwarePolicy(!
new DCAwareRoundRobinPolicy())!
!
Token Aware
Confidential
 35
Client 10.0.0.1
00-25
10.0.0.4
76-100
10.0.0.2
26-50
10.0.0.3
51-75
SELECT firstName!
FROM users!
WHERE userName = ‘rmills’;!
DC1!
DC1!
withLoadBalancingPolicy(!
new TokenAwarePolicy(!
new DCAwareRoundRobinPolicy())!
!
Node Primary Replica Replica
10.0.0.1 00-25 76-100 51-75
10.0.0.2 26-50 00-25 76-100
10.0.0.3 51-75 26-50 00-25
10.0.0.4 76-100 51-75 26-50
Node Primary Replica Replica
10.0.0.1 00-25 76-100 51-75
10.0.0.2 26-50 00-25 76-100
10.0.0.3 51-75 26-50 00-25
10.0.0.4 76-100 51-75 26-50
Token Aware - Retry
Confidential
 36
Client 10.0.0.1
00-25
10.0.0.4
76-100
10.0.0.2
26-50
10.0.0.3
51-75
SELECT firstName!
FROM users!
WHERE userName = ‘rmills’;!
DC1!
DC1!
withLoadBalancingPolicy(!
new TokenAwarePolicy(!
new DCAwareRoundRobinPolicy())!
!
Retry
Timeout
Without Token Aware
Confidential
 37
Using this modified example
Cluster cluster = new Cluster!
.builder().!
.addContactPoint(“10.0.0.1”)!
.withRetryPolicy(DefaultRetryPolicy.INSTANCE)!
.withLoadBalancingPolicy(!
new DCAwareRoundRobinPolicy())!
Request for data
Confidential
 38
Client 10.0.0.1
00-25
10.0.0.4
76-100
10.0.0.2
26-50
10.0.0.3
51-75
SELECT firstName!
FROM users!
WHERE userName = ‘pmcfadin’;!
pmcfadin Murmur3 Hash Token = 77!
DC1!
No Token Aware
Confidential
 39
Client 10.0.0.1
00-25
10.0.0.4
76-100
10.0.0.2
26-50
10.0.0.3
51-75
SELECT firstName!
FROM users!
WHERE userName = ‘pmcfadin’;!
Token = 77!
DC1!
DC1!
.withLoadBalancingPolicy(!
new DCAwareRoundRobinPolicy())!
Node Primary Replica Replica
10.0.0.1 00-25 76-100 51-75
10.0.0.2 26-50 00-25 76-100
10.0.0.3 51-75 26-50 00-25
10.0.0.4 76-100 51-75 26-50
Data placement
Confidential
 40
Client 10.0.0.1
00-25
10.0.0.4
76-100
10.0.0.2
26-50
10.0.0.3
51-75
SELECT firstName!
FROM users!
WHERE userName = ‘pmcfadin’;!
Token = 77!
DC1!
DC1!
.withLoadBalancingPolicy(!
new DCAwareRoundRobinPolicy())!
Node Primary Replica Replica
10.0.0.1 00-25 76-100 51-75
10.0.0.2 26-50 00-25 76-100
10.0.0.3 51-75 26-50 00-25
10.0.0.4 76-100 51-75 26-50
Standard Round Robin
Confidential
 41
Client 10.0.0.1
00-25
10.0.0.4
76-100
10.0.0.2
26-50
10.0.0.3
51-75
SELECT firstName!
FROM users!
WHERE userName = ‘pmcfadin’;!
Token = 77!
DC1!
DC1!
.withLoadBalancingPolicy(!
new DCAwareRoundRobinPolicy())!
Node Primary Replica Replica
10.0.0.1 00-25 76-100 51-75
10.0.0.2 26-50 00-25 76-100
10.0.0.3 51-75 26-50 00-25
10.0.0.4 76-100 51-75 26-50 Coordinate
Load Balancing 
Confidential
 42
•  Default pre-java 2.0.2: RoundRobinPolicy
•  Now: TokenAwarePolicy – Adds token awareness to
a child policy
•  Acts as a filter, wraps around another policy
•  Used to reduce network hops, as only replicas will
be considered
Load Balancing - Whitelist
Confidential
 43
•  Ensures only the hosts from a provided list are used
•  Wraps a child policy
•  Used to limit the effects of automatic peer discovery
•  Execute queries only a given list of hosts
Asynchronous Statements
Confidential
 44
•  Native binary protocol
supports request
pipelining
•  A single connection can
be used for single
simultaneous and
independent request/
response exchanges
Asynchronous Statements
Confidential
 45
•  Don’t have to wait for a query to complete and
return rows directly, non-blocking IO
•  Method almost immediately returns a future	
  object

NodeClient
Asynchronous Statements
Confidential
 46
query	
  =	
  "SELECT	
  *	
  FROM	
  users	
  WHERE	
  lastname=%s"	
  
future	
  =	
  session.execute_async(query,	
  [lastname])	
  
	
  
#	
  ...	
  do	
  some	
  other	
  work	
  
	
  
try:	
  
	
  	
  	
  	
  rows	
  =	
  future.result()	
  
	
  	
  	
  	
  user	
  =	
  rows[0]	
  
	
  	
  	
  	
  print	
  user.name,	
  user.age	
  
except	
  ReadTimeout:	
  
	
  	
  	
  	
  log.exception("Query	
  timed	
  out:")	
  
Asynchronous Statements
Confidential
 47
	
  #	
  build	
  a	
  list	
  of	
  futures	
  
futures	
  =	
  []	
  
query	
  =	
  "SELECT	
  *	
  FROM	
  users	
  WHERE	
  lastname=%s"	
  
for	
  user_id	
  in	
  ids_to_fetch:	
  
	
  	
  	
  	
  futures.append(session.execute_async(query,	
  
[lastname])	
  
	
  
#	
  wait	
  for	
  them	
  to	
  complete	
  and	
  use	
  the	
  results	
  
for	
  future	
  in	
  futures:	
  
	
  	
  	
  	
  rows	
  =	
  future.result()	
  
	
  	
  	
  	
  print	
  rows[0].name,	
  rows[0].age	
  
Where can I download the drivers?




Confidential
 48
Planet Cassandra
Confidential
 49
•  A great place for Apache Cassandra resources!
•  Blog post, webinars, tutorials, and much much more!
•  Also a great place for your driver needs
Confidential
 50
Confidential
 51
Thank You!



Twitter: @rebccamills


Confidential
 52

Contenu connexe

Tendances

FIWARE Data Management in High Availability
FIWARE Data Management in High AvailabilityFIWARE Data Management in High Availability
FIWARE Data Management in High AvailabilityFederico Michele Facca
 
Meetup cassandra for_java_cql
Meetup cassandra for_java_cqlMeetup cassandra for_java_cql
Meetup cassandra for_java_cqlzznate
 
Dynamic Database Credentials: Security Contingency Planning
Dynamic Database Credentials: Security Contingency PlanningDynamic Database Credentials: Security Contingency Planning
Dynamic Database Credentials: Security Contingency PlanningSean Chittenden
 
Altitude SF 2017: Debugging Fastly VCL 101
Altitude SF 2017: Debugging Fastly VCL 101Altitude SF 2017: Debugging Fastly VCL 101
Altitude SF 2017: Debugging Fastly VCL 101Fastly
 
In-depth caching in Varnish - GOG Varnish Meetup, march 2019
In-depth caching in Varnish - GOG Varnish Meetup, march 2019In-depth caching in Varnish - GOG Varnish Meetup, march 2019
In-depth caching in Varnish - GOG Varnish Meetup, march 2019GOG.com dev team
 
Where Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsConcentric Sky
 
Gruntwork Executive Summary
Gruntwork Executive SummaryGruntwork Executive Summary
Gruntwork Executive SummaryYevgeniy Brikman
 
Production Readiness Strategies in an Automated World
Production Readiness Strategies in an Automated WorldProduction Readiness Strategies in an Automated World
Production Readiness Strategies in an Automated WorldSean Chittenden
 
Altitude SF 2017: Advanced VCL: Shielding and Clustering
Altitude SF 2017: Advanced VCL: Shielding and ClusteringAltitude SF 2017: Advanced VCL: Shielding and Clustering
Altitude SF 2017: Advanced VCL: Shielding and ClusteringFastly
 
Resilience Testing
Resilience Testing Resilience Testing
Resilience Testing Ran Levy
 
Chickens & Eggs: Managing secrets in AWS with Hashicorp Vault
Chickens & Eggs: Managing secrets in AWS with Hashicorp VaultChickens & Eggs: Managing secrets in AWS with Hashicorp Vault
Chickens & Eggs: Managing secrets in AWS with Hashicorp VaultJeff Horwitz
 
Trusts You Might Have Missed
Trusts You Might Have MissedTrusts You Might Have Missed
Trusts You Might Have MissedWill Schroeder
 
Training Slides: 302 - Securing Your Cluster With SSL
Training Slides: 302 - Securing Your Cluster With SSLTraining Slides: 302 - Securing Your Cluster With SSL
Training Slides: 302 - Securing Your Cluster With SSLContinuent
 
Mitigating Security Threats with Fastly - Joe Williams at Fastly Altitude 2015
Mitigating Security Threats with Fastly - Joe Williams at Fastly Altitude 2015Mitigating Security Threats with Fastly - Joe Williams at Fastly Altitude 2015
Mitigating Security Threats with Fastly - Joe Williams at Fastly Altitude 2015Fastly
 
06 response-headers
06 response-headers06 response-headers
06 response-headerssnopteck
 
Nagios Conference 2006 | Nagios 3.0 and beyond by Ethan Galstad
Nagios Conference 2006 |  Nagios 3.0 and beyond by Ethan GalstadNagios Conference 2006 |  Nagios 3.0 and beyond by Ethan Galstad
Nagios Conference 2006 | Nagios 3.0 and beyond by Ethan GalstadNETWAYS
 

Tendances (17)

FIWARE Data Management in High Availability
FIWARE Data Management in High AvailabilityFIWARE Data Management in High Availability
FIWARE Data Management in High Availability
 
Meetup cassandra for_java_cql
Meetup cassandra for_java_cqlMeetup cassandra for_java_cql
Meetup cassandra for_java_cql
 
Dynamic Database Credentials: Security Contingency Planning
Dynamic Database Credentials: Security Contingency PlanningDynamic Database Credentials: Security Contingency Planning
Dynamic Database Credentials: Security Contingency Planning
 
Altitude SF 2017: Debugging Fastly VCL 101
Altitude SF 2017: Debugging Fastly VCL 101Altitude SF 2017: Debugging Fastly VCL 101
Altitude SF 2017: Debugging Fastly VCL 101
 
In-depth caching in Varnish - GOG Varnish Meetup, march 2019
In-depth caching in Varnish - GOG Varnish Meetup, march 2019In-depth caching in Varnish - GOG Varnish Meetup, march 2019
In-depth caching in Varnish - GOG Varnish Meetup, march 2019
 
Where Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the Seams
 
Gruntwork Executive Summary
Gruntwork Executive SummaryGruntwork Executive Summary
Gruntwork Executive Summary
 
Production Readiness Strategies in an Automated World
Production Readiness Strategies in an Automated WorldProduction Readiness Strategies in an Automated World
Production Readiness Strategies in an Automated World
 
Altitude SF 2017: Advanced VCL: Shielding and Clustering
Altitude SF 2017: Advanced VCL: Shielding and ClusteringAltitude SF 2017: Advanced VCL: Shielding and Clustering
Altitude SF 2017: Advanced VCL: Shielding and Clustering
 
Resilience Testing
Resilience Testing Resilience Testing
Resilience Testing
 
Bridging the Gap
Bridging the GapBridging the Gap
Bridging the Gap
 
Chickens & Eggs: Managing secrets in AWS with Hashicorp Vault
Chickens & Eggs: Managing secrets in AWS with Hashicorp VaultChickens & Eggs: Managing secrets in AWS with Hashicorp Vault
Chickens & Eggs: Managing secrets in AWS with Hashicorp Vault
 
Trusts You Might Have Missed
Trusts You Might Have MissedTrusts You Might Have Missed
Trusts You Might Have Missed
 
Training Slides: 302 - Securing Your Cluster With SSL
Training Slides: 302 - Securing Your Cluster With SSLTraining Slides: 302 - Securing Your Cluster With SSL
Training Slides: 302 - Securing Your Cluster With SSL
 
Mitigating Security Threats with Fastly - Joe Williams at Fastly Altitude 2015
Mitigating Security Threats with Fastly - Joe Williams at Fastly Altitude 2015Mitigating Security Threats with Fastly - Joe Williams at Fastly Altitude 2015
Mitigating Security Threats with Fastly - Joe Williams at Fastly Altitude 2015
 
06 response-headers
06 response-headers06 response-headers
06 response-headers
 
Nagios Conference 2006 | Nagios 3.0 and beyond by Ethan Galstad
Nagios Conference 2006 |  Nagios 3.0 and beyond by Ethan GalstadNagios Conference 2006 |  Nagios 3.0 and beyond by Ethan Galstad
Nagios Conference 2006 | Nagios 3.0 and beyond by Ethan Galstad
 

Similaire à Things YouShould Be Doing When Using Cassandra Drivers

DataStax Enterprise & Apache Cassandra – Essentials for Financial Services – ...
DataStax Enterprise & Apache Cassandra – Essentials for Financial Services – ...DataStax Enterprise & Apache Cassandra – Essentials for Financial Services – ...
DataStax Enterprise & Apache Cassandra – Essentials for Financial Services – ...Daniel Cohen
 
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
 
Integrating Infrastructure as Code into a Continuous Delivery Pipeline | AWS ...
Integrating Infrastructure as Code into a Continuous Delivery Pipeline | AWS ...Integrating Infrastructure as Code into a Continuous Delivery Pipeline | AWS ...
Integrating Infrastructure as Code into a Continuous Delivery Pipeline | AWS ...Amazon Web Services
 
AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...
AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...
AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...Amazon Web Services
 
VMworld 2016: Virtualize Active Directory, the Right Way!
VMworld 2016: Virtualize Active Directory, the Right Way! VMworld 2016: Virtualize Active Directory, the Right Way!
VMworld 2016: Virtualize Active Directory, the Right Way! VMworld
 
Cassandra NodeJS driver & NodeJS Paris
Cassandra NodeJS driver & NodeJS ParisCassandra NodeJS driver & NodeJS Paris
Cassandra NodeJS driver & NodeJS ParisDuyhai Doan
 
Delivery Pipelines as a First Class Citizen @deliverAgile2019
Delivery Pipelines as a First Class Citizen @deliverAgile2019Delivery Pipelines as a First Class Citizen @deliverAgile2019
Delivery Pipelines as a First Class Citizen @deliverAgile2019ciberkleid
 
MongoDB World 2019: Why NBCUniversal Migrated to MongoDB Atlas
MongoDB World 2019: Why NBCUniversal Migrated to MongoDB AtlasMongoDB World 2019: Why NBCUniversal Migrated to MongoDB Atlas
MongoDB World 2019: Why NBCUniversal Migrated to MongoDB AtlasMongoDB
 
How to Build a Multi-DC Cassandra Cluster in AWS with OpsCenter LCM
How to Build a Multi-DC Cassandra Cluster in AWS with OpsCenter LCMHow to Build a Multi-DC Cassandra Cluster in AWS with OpsCenter LCM
How to Build a Multi-DC Cassandra Cluster in AWS with OpsCenter LCMAnant Corporation
 
APAC ksqlDB Workshop
APAC ksqlDB WorkshopAPAC ksqlDB Workshop
APAC ksqlDB Workshopconfluent
 
Back to Basics Spanish Webinar 3 - Introducción a los replica sets
Back to Basics Spanish Webinar 3 - Introducción a los replica setsBack to Basics Spanish Webinar 3 - Introducción a los replica sets
Back to Basics Spanish Webinar 3 - Introducción a los replica setsMongoDB
 
Tips, Tricks & Best Practices for large scale HDInsight Deployments
Tips, Tricks & Best Practices for large scale HDInsight DeploymentsTips, Tricks & Best Practices for large scale HDInsight Deployments
Tips, Tricks & Best Practices for large scale HDInsight DeploymentsAshish Thapliyal
 
DDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCDDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCAndy Butland
 
2016 07 - CloudBridge Python library (XSEDE16)
2016 07 - CloudBridge Python library (XSEDE16)2016 07 - CloudBridge Python library (XSEDE16)
2016 07 - CloudBridge Python library (XSEDE16)Enis Afgan
 
AWS Summit Auckland - Introducing Well-Architected for Developers
AWS Summit Auckland  - Introducing Well-Architected for DevelopersAWS Summit Auckland  - Introducing Well-Architected for Developers
AWS Summit Auckland - Introducing Well-Architected for DevelopersAmazon Web Services
 
Toronto Virtual Meetup #7 - Anypoint VPC, VPN and DLB Architecture
Toronto Virtual Meetup #7 - Anypoint VPC, VPN and DLB ArchitectureToronto Virtual Meetup #7 - Anypoint VPC, VPN and DLB Architecture
Toronto Virtual Meetup #7 - Anypoint VPC, VPN and DLB ArchitectureAlexandra N. Martinez
 
Day 4 - Cloud Migration - But How?
Day 4 - Cloud Migration - But How?Day 4 - Cloud Migration - But How?
Day 4 - Cloud Migration - But How?Amazon Web Services
 
What they don't tell you about micro-services
What they don't tell you about micro-servicesWhat they don't tell you about micro-services
What they don't tell you about micro-servicesDaniel Rolnick
 

Similaire à Things YouShould Be Doing When Using Cassandra Drivers (20)

Advanced Cassandra
Advanced CassandraAdvanced Cassandra
Advanced Cassandra
 
DataStax Enterprise & Apache Cassandra – Essentials for Financial Services – ...
DataStax Enterprise & Apache Cassandra – Essentials for Financial Services – ...DataStax Enterprise & Apache Cassandra – Essentials for Financial Services – ...
DataStax Enterprise & Apache Cassandra – Essentials for Financial Services – ...
 
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...
 
Integrating Infrastructure as Code into a Continuous Delivery Pipeline | AWS ...
Integrating Infrastructure as Code into a Continuous Delivery Pipeline | AWS ...Integrating Infrastructure as Code into a Continuous Delivery Pipeline | AWS ...
Integrating Infrastructure as Code into a Continuous Delivery Pipeline | AWS ...
 
AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...
AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...
AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...
 
Solid principles
Solid principlesSolid principles
Solid principles
 
VMworld 2016: Virtualize Active Directory, the Right Way!
VMworld 2016: Virtualize Active Directory, the Right Way! VMworld 2016: Virtualize Active Directory, the Right Way!
VMworld 2016: Virtualize Active Directory, the Right Way!
 
Cassandra NodeJS driver & NodeJS Paris
Cassandra NodeJS driver & NodeJS ParisCassandra NodeJS driver & NodeJS Paris
Cassandra NodeJS driver & NodeJS Paris
 
Delivery Pipelines as a First Class Citizen @deliverAgile2019
Delivery Pipelines as a First Class Citizen @deliverAgile2019Delivery Pipelines as a First Class Citizen @deliverAgile2019
Delivery Pipelines as a First Class Citizen @deliverAgile2019
 
MongoDB World 2019: Why NBCUniversal Migrated to MongoDB Atlas
MongoDB World 2019: Why NBCUniversal Migrated to MongoDB AtlasMongoDB World 2019: Why NBCUniversal Migrated to MongoDB Atlas
MongoDB World 2019: Why NBCUniversal Migrated to MongoDB Atlas
 
How to Build a Multi-DC Cassandra Cluster in AWS with OpsCenter LCM
How to Build a Multi-DC Cassandra Cluster in AWS with OpsCenter LCMHow to Build a Multi-DC Cassandra Cluster in AWS with OpsCenter LCM
How to Build a Multi-DC Cassandra Cluster in AWS with OpsCenter LCM
 
APAC ksqlDB Workshop
APAC ksqlDB WorkshopAPAC ksqlDB Workshop
APAC ksqlDB Workshop
 
Back to Basics Spanish Webinar 3 - Introducción a los replica sets
Back to Basics Spanish Webinar 3 - Introducción a los replica setsBack to Basics Spanish Webinar 3 - Introducción a los replica sets
Back to Basics Spanish Webinar 3 - Introducción a los replica sets
 
Tips, Tricks & Best Practices for large scale HDInsight Deployments
Tips, Tricks & Best Practices for large scale HDInsight DeploymentsTips, Tricks & Best Practices for large scale HDInsight Deployments
Tips, Tricks & Best Practices for large scale HDInsight Deployments
 
DDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCDDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVC
 
2016 07 - CloudBridge Python library (XSEDE16)
2016 07 - CloudBridge Python library (XSEDE16)2016 07 - CloudBridge Python library (XSEDE16)
2016 07 - CloudBridge Python library (XSEDE16)
 
AWS Summit Auckland - Introducing Well-Architected for Developers
AWS Summit Auckland  - Introducing Well-Architected for DevelopersAWS Summit Auckland  - Introducing Well-Architected for Developers
AWS Summit Auckland - Introducing Well-Architected for Developers
 
Toronto Virtual Meetup #7 - Anypoint VPC, VPN and DLB Architecture
Toronto Virtual Meetup #7 - Anypoint VPC, VPN and DLB ArchitectureToronto Virtual Meetup #7 - Anypoint VPC, VPN and DLB Architecture
Toronto Virtual Meetup #7 - Anypoint VPC, VPN and DLB Architecture
 
Day 4 - Cloud Migration - But How?
Day 4 - Cloud Migration - But How?Day 4 - Cloud Migration - But How?
Day 4 - Cloud Migration - But How?
 
What they don't tell you about micro-services
What they don't tell you about micro-servicesWhat they don't tell you about micro-services
What they don't tell you about micro-services
 

Dernier

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
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
"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
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
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
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
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
 
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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 

Dernier (20)

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
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
"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
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
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
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
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
 
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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 

Things YouShould Be Doing When Using Cassandra Drivers

  • 1. Things You Should Be Doing When Using Cassandra Drivers Rebecca Mills Junior Evangelist at Datastax @rebccamills
  • 2. What do I do? 2 Confidential •  Try to create awareness for open source Cassandra •  Develop content •  Identify problems newcomers might be encountering •  Develop strategies and material to help with that first ease of initial use
  • 3. Of course all this extends to drivers! Confidential 3 •  Learning and playing with the drivers as much as I can •  Develop “Getting Started” tutorials for drivers in various programming languages •  Making it my mission to bring the details to light
  • 4. So How Can We Communicate with Cassandra in “X” Language? Confidential 4
  • 5. We have what you need! Confidential 5 •  Datastax provides drivers for Java, Python, C# •  Fresh out of the oven Ruby, Node.js, and C++ •  Also loads of open source drivers to chose from •  Check out the Planet Cassandra Client Drivers section
  • 6. Confidential 6 Let’s get into some of the basics of smart Cassandra driver usage:
  • 7. 1. One Cluster instance per cluster Confidential 7 •  Configure different important aspects of the way connections and queries will be handled. •  Contact points •  Retry Policies •  Load Balancing Policies cluster  =  Cluster(['10.1.1.3',  '10.1.1.4',  '10.1.1.5'],          compression=True,          load_balancing_policy=TokenAwarePolicy(                  DCAwareRoundRobinPolicy(local_dc='US_EAST')))  
  • 8. 2. One Session per keyspace Confidential 8 •  Query execution, connection pooling •  Long-lived object •  Not to be used in a request/response short-lived fashion •  Share the same cluster and session instances across your application
  • 9. Cluster & Session Confidential 9 cluster  =  Cluster(['10.1.1.3',  '10.1.1.4',  '10.1.1.5'],          compression=True,          load_balancing_policy=TokenAwarePolicy(                  DCAwareRoundRobinPolicy(local_dc='US_EAST')))     session  =  cluster.connect('demo')  
  • 10. 3. Use Prepared Statements Confidential 10 •  If you execute a statement more than once •  Has multiple benefits •  Prepare once, bind and execute multiple times •  We’ll talk more about this soon!
  • 13. Deep Dives: Confidential 13 •  Prepared Statements •  Load Balancing Policies •  Retry Policies •  Connection Pooling •  Async API
  • 14. Why use Prepared Statements? Confidential 14 •  More performant than using strings •  Will be parsed only once on the server •  We expect you to use them with repeated queries in production •  Avoid CQL injection
  • 15. Prepared Statements Confidential 15 Consider a string session.execute(""”     INSERT  INTO  users  (lastname,  age,  city,  email,  firstname)  VALUES  (‘Jones’,  35,   ‘Austin’,  ‘bob@example.com’,  ‘Bob’)     """
  • 16. Prepared Statements Confidential 16 session.execute("""   INSERT  INTO  users  (lastname,  age,  city,  email,  firstname)  VALUES  (‘Smith’,  24,  ‘Tampa’,  ‘ken@example.com’,  ‘Bob’)     """)     session.execute(""”     INSERT  INTO  users  (lastname,  age,  city,  email,  firstname)  VALUES  (‘Power’,  45,  ‘New  York’,  ‘kate@example.com’,  ‘Kate’)     """)     session.execute(""”     INSERT  INTO  users  (lastname,  age,  city,  email,  firstname)  VALUES  (‘Renolds’,  33,  ‘Miami’,  ‘carl@example.com’,  ‘Carl’)     """)  
  • 17. Prepared Statements
 Confidential 17 Now the same, as a prepared statement   Prepared_stmt  =  session.prepare  (“INSERT  INTO  users  (lastname,  age,  city,  email,                     firstname)  VALUES  (?,  ?,  ?,  ?,  ?)”)   Bound_stmt  =  prepared.bind([‘Jones’,  35,  ‘Austin’,  ‘bob@example.com’,  ‘Bob’])   Stmt  =  session.execute(bound_stmt)      
  • 19. Prepared Statements Confidential 19 Client Cassandra Entire Query String Client Cassandra Query ID & BoundValues INSERT with strings INSERT with PreparedStatements Large amount of data Parse cost Smaller amount of data No parsing
  • 20. So what does that mean to me? Confidential 20
  • 23. Prepared Statements Confidential 23 Putting a prepared statement in a for loop is an anti- pattern  for  (int  i;  i  <  10;  i++)  {      PreparedStatement  ps  =  session.prepare("UPDATE  user  SET  disabled  =  1   WHERE  id  =  ?");              session.execute(ps.bind(i));   }  
  • 24. Load Balancing Confidential 24 •  A load balancing policy will determine which node to run an insert or query. •  Since a client can read or write to any node, sometimes that can be inefficient. •  If a node receives a read or write owned on another node, it will coordinate that request for the client. •  We can use a load balancing policy to control that action.
  • 25. Load Balancing deep dive Confidential 25 Using this example Cluster cluster = new Cluster! .builder().! .addContactPoint(“10.0.0.1”)! .withRetryPolicy(DefaultRetryPolicy.INSTANCE)! .withLoadBalancingPolicy(! new TokenAwarePolicy(! new DCAwareRoundRobinPolicy())!
  • 26. Example data model Confidential 26 CREATE TABLE users (! username text PRIMARY KEY! firstName text,! lastName text! );! ! INSERT INTO users (username, firstName, lastName)! VALUES (‘rmills’, ‘Rebecca’, ‘Mills’);! ! INSERT INTO users (username, firstName, lastName)! VALUES (‘pmcfadin’, ‘Patrick’, ‘McFadin’);! !
  • 28. Populate connection pool Confidential 28 10.0.0.1 00-25 Client 10.0.0.4 76-100 10.0.0.2 26-50 10.0.0.3 51-75 Node Primary Replica Replica 10.0.0.1 00-25 76-100 51-75 10.0.0.2 26-50 00-25 76-100 10.0.0.3 51-75 26-50 00-25 10.0.0.4 76-100 51-75 26-50 DC1! DC1!
  • 29. Request for data Confidential 29 Client 10.0.0.1 00-25 10.0.0.4 76-100 10.0.0.2 26-50 10.0.0.3 51-75 SELECT firstName! FROM users! WHERE userName = ‘rmills’;! rmills Murmur3 Hash Token = 15! DC1!
  • 30. Token Aware Confidential 30 Client 10.0.0.1 00-25 10.0.0.4 76-100 10.0.0.2 26-50 10.0.0.3 51-75 SELECT firstName! FROM users! WHERE userName = ‘rmills’;! Token = 15! withLoadBalancingPolicy(! new TokenAwarePolicy(! DC1!
  • 31. Token Aware Confidential 31 Client 10.0.0.1 00-25 10.0.0.4 76-100 10.0.0.2 26-50 10.0.0.3 51-75 SELECT firstName! FROM users! WHERE userName = ‘rmills’;! Token = 15! DC1! Which node? DC1! Node Primary Replica Replica 10.0.0.1 00-25 76-100 51-75 10.0.0.2 26-50 00-25 76-100 10.0.0.3 51-75 26-50 00-25 10.0.0.4 76-100 51-75 26-50
  • 32. Token Aware Confidential 32 Client 10.0.0.1 00-25 10.0.0.4 76-100 10.0.0.2 26-50 10.0.0.3 51-75 SELECT firstName! FROM users! WHERE userName = ‘rmills’;! Token = 15! DC1! DC1! Node Primary Replica Replica 10.0.0.1 00-25 76-100 51-75 10.0.0.2 26-50 00-25 76-100 10.0.0.3 51-75 26-50 00-25 10.0.0.4 76-100 51-75 26-50
  • 33. Token Aware Confidential 33 Client 10.0.0.1 00-25 10.0.0.4 76-100 10.0.0.2 26-50 10.0.0.3 51-75 SELECT firstName! FROM users! WHERE userName = ‘rmills’;! Token = 15! DC1! DC1! Node Primary Replica Replica 10.0.0.1 00-25 76-100 51-75 10.0.0.2 26-50 00-25 76-100 10.0.0.3 51-75 26-50 00-25 10.0.0.4 76-100 51-75 26-50
  • 34. Node Primary Replica Replica 10.0.0.1 00-25 76-100 51-75 10.0.0.2 26-50 00-25 76-100 10.0.0.3 51-75 26-50 00-25 10.0.0.4 76-100 51-75 26-50 Token Aware Confidential 34 Client 10.0.0.1 00-25 10.0.0.4 76-100 10.0.0.2 26-50 10.0.0.3 51-75 SELECT firstName! FROM users! WHERE userName = ‘rmills’;! DC1! DC1! withLoadBalancingPolicy(! new TokenAwarePolicy(! new DCAwareRoundRobinPolicy())! !
  • 35. Token Aware Confidential 35 Client 10.0.0.1 00-25 10.0.0.4 76-100 10.0.0.2 26-50 10.0.0.3 51-75 SELECT firstName! FROM users! WHERE userName = ‘rmills’;! DC1! DC1! withLoadBalancingPolicy(! new TokenAwarePolicy(! new DCAwareRoundRobinPolicy())! ! Node Primary Replica Replica 10.0.0.1 00-25 76-100 51-75 10.0.0.2 26-50 00-25 76-100 10.0.0.3 51-75 26-50 00-25 10.0.0.4 76-100 51-75 26-50
  • 36. Node Primary Replica Replica 10.0.0.1 00-25 76-100 51-75 10.0.0.2 26-50 00-25 76-100 10.0.0.3 51-75 26-50 00-25 10.0.0.4 76-100 51-75 26-50 Token Aware - Retry Confidential 36 Client 10.0.0.1 00-25 10.0.0.4 76-100 10.0.0.2 26-50 10.0.0.3 51-75 SELECT firstName! FROM users! WHERE userName = ‘rmills’;! DC1! DC1! withLoadBalancingPolicy(! new TokenAwarePolicy(! new DCAwareRoundRobinPolicy())! ! Retry Timeout
  • 37. Without Token Aware Confidential 37 Using this modified example Cluster cluster = new Cluster! .builder().! .addContactPoint(“10.0.0.1”)! .withRetryPolicy(DefaultRetryPolicy.INSTANCE)! .withLoadBalancingPolicy(! new DCAwareRoundRobinPolicy())!
  • 38. Request for data Confidential 38 Client 10.0.0.1 00-25 10.0.0.4 76-100 10.0.0.2 26-50 10.0.0.3 51-75 SELECT firstName! FROM users! WHERE userName = ‘pmcfadin’;! pmcfadin Murmur3 Hash Token = 77! DC1!
  • 39. No Token Aware Confidential 39 Client 10.0.0.1 00-25 10.0.0.4 76-100 10.0.0.2 26-50 10.0.0.3 51-75 SELECT firstName! FROM users! WHERE userName = ‘pmcfadin’;! Token = 77! DC1! DC1! .withLoadBalancingPolicy(! new DCAwareRoundRobinPolicy())! Node Primary Replica Replica 10.0.0.1 00-25 76-100 51-75 10.0.0.2 26-50 00-25 76-100 10.0.0.3 51-75 26-50 00-25 10.0.0.4 76-100 51-75 26-50
  • 40. Data placement Confidential 40 Client 10.0.0.1 00-25 10.0.0.4 76-100 10.0.0.2 26-50 10.0.0.3 51-75 SELECT firstName! FROM users! WHERE userName = ‘pmcfadin’;! Token = 77! DC1! DC1! .withLoadBalancingPolicy(! new DCAwareRoundRobinPolicy())! Node Primary Replica Replica 10.0.0.1 00-25 76-100 51-75 10.0.0.2 26-50 00-25 76-100 10.0.0.3 51-75 26-50 00-25 10.0.0.4 76-100 51-75 26-50
  • 41. Standard Round Robin Confidential 41 Client 10.0.0.1 00-25 10.0.0.4 76-100 10.0.0.2 26-50 10.0.0.3 51-75 SELECT firstName! FROM users! WHERE userName = ‘pmcfadin’;! Token = 77! DC1! DC1! .withLoadBalancingPolicy(! new DCAwareRoundRobinPolicy())! Node Primary Replica Replica 10.0.0.1 00-25 76-100 51-75 10.0.0.2 26-50 00-25 76-100 10.0.0.3 51-75 26-50 00-25 10.0.0.4 76-100 51-75 26-50 Coordinate
  • 42. Load Balancing Confidential 42 •  Default pre-java 2.0.2: RoundRobinPolicy •  Now: TokenAwarePolicy – Adds token awareness to a child policy •  Acts as a filter, wraps around another policy •  Used to reduce network hops, as only replicas will be considered
  • 43. Load Balancing - Whitelist Confidential 43 •  Ensures only the hosts from a provided list are used •  Wraps a child policy •  Used to limit the effects of automatic peer discovery •  Execute queries only a given list of hosts
  • 44. Asynchronous Statements Confidential 44 •  Native binary protocol supports request pipelining •  A single connection can be used for single simultaneous and independent request/ response exchanges
  • 45. Asynchronous Statements Confidential 45 •  Don’t have to wait for a query to complete and return rows directly, non-blocking IO •  Method almost immediately returns a future  object NodeClient
  • 46. Asynchronous Statements Confidential 46 query  =  "SELECT  *  FROM  users  WHERE  lastname=%s"   future  =  session.execute_async(query,  [lastname])     #  ...  do  some  other  work     try:          rows  =  future.result()          user  =  rows[0]          print  user.name,  user.age   except  ReadTimeout:          log.exception("Query  timed  out:")  
  • 47. Asynchronous Statements Confidential 47  #  build  a  list  of  futures   futures  =  []   query  =  "SELECT  *  FROM  users  WHERE  lastname=%s"   for  user_id  in  ids_to_fetch:          futures.append(session.execute_async(query,   [lastname])     #  wait  for  them  to  complete  and  use  the  results   for  future  in  futures:          rows  =  future.result()          print  rows[0].name,  rows[0].age  
  • 48. Where can I download the drivers?
 
 Confidential 48
  • 49. Planet Cassandra Confidential 49 •  A great place for Apache Cassandra resources! •  Blog post, webinars, tutorials, and much much more! •  Also a great place for your driver needs