Was this page helpful?
ScyllaDB Python Driver is available under the Apache v2 License. ScyllaDB Python Driver is a fork of DataStax Python Driver. See Copyright here.
Execution profiles aim at making it easier to execute requests in different ways within
a single connected Session
. Execution profiles are being introduced to deal with the exploding number of
configuration options, especially as the database platform evolves more complex workloads.
The legacy configuration remains intact, but legacy and Execution Profile APIs
cannot be used simultaneously on the same client Cluster
. Legacy configuration
will be removed in the next major release (4.0).
An execution profile and its parameters should be unique across Cluster
instances.
For example, an execution profile and its LoadBalancingPolicy
should
not be applied to more than one Cluster
instance.
This document explains how Execution Profiles relate to existing settings, and shows how to use the new profiles for request execution.
Execution profiles can inherit from cluster.ExecutionProfile
, and currently provide the following options,
previously input from the noted attributes:
load_balancing_policy - Cluster.load_balancing_policy
request_timeout - Session.default_timeout
, optional Session.execute()
parameter
retry_policy - Cluster.default_retry_policy
, optional Statement.retry_policy
attribute
consistency_level - Session.default_consistency_level
, optional Statement.consistency_level
attribute
serial_consistency_level - Session.default_serial_consistency_level
, optional Statement.serial_consistency_level
attribute
row_factory - Session.row_factory
attribute
When using the new API, these parameters can be defined by instances of cluster.ExecutionProfile
.
from cassandra.cluster import Cluster
cluster = Cluster()
session = cluster.connect()
local_query = 'SELECT rpc_address FROM system.local'
for _ in cluster.metadata.all_hosts():
print(session.execute(local_query)[0])
Row(rpc_address='127.0.0.2')
Row(rpc_address='127.0.0.1')
The default execution profile is built from Cluster parameters and default Session attributes. This profile matches existing default parameters.
from cassandra.cluster import ExecutionProfile
from cassandra.policies import WhiteListRoundRobinPolicy
node1_profile = ExecutionProfile(load_balancing_policy=WhiteListRoundRobinPolicy(['127.0.0.1']))
node2_profile = ExecutionProfile(load_balancing_policy=WhiteListRoundRobinPolicy(['127.0.0.2']))
profiles = {'node1': node1_profile, 'node2': node2_profile}
session = Cluster(execution_profiles=profiles).connect()
for _ in cluster.metadata.all_hosts():
print(session.execute(local_query, execution_profile='node1')[0])
Row(rpc_address='127.0.0.1')
Row(rpc_address='127.0.0.1')
for _ in cluster.metadata.all_hosts():
print(session.execute(local_query, execution_profile='node2')[0])
Row(rpc_address='127.0.0.2')
Row(rpc_address='127.0.0.2')
for _ in cluster.metadata.all_hosts():
print(session.execute(local_query)[0])
Row(rpc_address='127.0.0.2')
Row(rpc_address='127.0.0.1')
Note that, even when custom profiles are injected, the default TokenAwarePolicy(DCAwareRoundRobinPolicy())
is still
present. To override the default, specify a policy with the EXEC_PROFILE_DEFAULT
key.
from cassandra.cluster import EXEC_PROFILE_DEFAULT
profile = ExecutionProfile(request_timeout=30)
cluster = Cluster(execution_profiles={EXEC_PROFILE_DEFAULT: profile})
New profiles can be added constructing from scratch, or deriving from default:
locked_execution = ExecutionProfile(load_balancing_policy=WhiteListRoundRobinPolicy(['127.0.0.1']))
node1_profile = 'node1_whitelist'
cluster.add_execution_profile(node1_profile, locked_execution)
for _ in cluster.metadata.all_hosts():
print(session.execute(local_query, execution_profile=node1_profile)[0])
Row(rpc_address='127.0.0.1')
Row(rpc_address='127.0.0.1')
See Cluster.add_execution_profile()
for details and optional parameters.
We also have the ability to pass profile instances to be used for execution, but not added to the mapping:
from cassandra.query import tuple_factory
tmp = session.execution_profile_clone_update('node1', request_timeout=100, row_factory=tuple_factory)
print(session.execute(local_query, execution_profile=tmp)[0])
print(session.execute(local_query, execution_profile='node1')[0])
('127.0.0.1',)
Row(rpc_address='127.0.0.1')
The new profile is a shallow copy, so the tmp
profile shares a load balancing policy with one managed by the cluster.
If reference objects are to be updated in the clone, one would typically set those attributes to a new instance.
Was this page helpful?
ScyllaDB Python Driver is available under the Apache v2 License. ScyllaDB Python Driver is a fork of DataStax Python Driver. See Copyright here.
cassandra
- Exceptions and Enumscassandra.cluster
- Clusters and Sessionscassandra.policies
- Load balancing and Failure Handling Policiescassandra.auth
- Authenticationcassandra.metadata
- Schema and Ring Topologycassandra.metrics
- Performance Metricscassandra.query
- Prepared Statements, Batch Statements, Tracing, and Row Factoriescassandra.pool
- Hosts and Connection Poolscassandra.protocol
- Protocol Featurescassandra.encoder
- Encoders for non-prepared Statementscassandra.decoder
- Data Return Formatscassandra.concurrent
- Utilities for Concurrent Statement Executioncassandra.connection
- Low Level Connection Infocassandra.util
- Utilitiescassandra.timestamps
- Timestamp Generationcassandra.io.asyncioreactor
- asyncio
Event Loopcassandra.io.asyncorereactor
- asyncore
Event Loopcassandra.io.eventletreactor
- eventlet
-compatible Connectioncassandra.io.libevreactor
- libev
Event Loopcassandra.io.geventreactor
- gevent
-compatible Event Loopcassandra.io.twistedreactor
- Twisted Event Loopcassandra.cqlengine.models
- Table models for object mappingcassandra.cqlengine.columns
- Column types for object mapping modelscassandra.cqlengine.query
- Query and filter model objectscassandra.cqlengine.connection
- Connection management for cqlenginecassandra.cqlengine.management
- Schema management for cqlenginecassandra.cqlengine.usertype
- Model classes for User Defined Types