Scylla Documentation Logo Documentation
  • Server
    • Scylla Open Source
    • Scylla Enterprise
    • Scylla Alternator
  • Cloud
    • Scylla Cloud
    • Scylla Cloud Docs
  • Tools
    • Scylla Manager
    • Scylla Monitoring Stack
    • Scylla Operator
  • Drivers
    • CQL Drivers
    • DynamoDB Drivers
Download
Menu

Caution

You're viewing documentation for a previous version of Scylla Python Driver. Switch to the latest stable version.

Scylla Python Driver Execution Profiles

Execution Profiles¶

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.

Mapping Legacy Parameters to Profiles¶

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.

Using Execution Profiles¶

Default¶

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.

Initializing cluster with profiles¶

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})

Adding named profiles¶

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.

Passing a profile instance without mapping¶

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.

PREVIOUS
Upgrading
NEXT
Performance Notes
  • 3.22.3
    • 3.25.4
    • 3.24.8
    • 3.22.3
    • 3.21.0
  • API Documentation
    • cassandra - Exceptions and Enums
    • cassandra.cluster - Clusters and Sessions
    • cassandra.policies - Load balancing and Failure Handling Policies
    • cassandra.auth - Authentication
    • cassandra.graph - Graph Statements, Options, and Row Factories
    • cassandra.metadata - Schema and Ring Topology
    • cassandra.metrics - Performance Metrics
    • cassandra.query - Prepared Statements, Batch Statements, Tracing, and Row Factories
    • cassandra.pool - Hosts and Connection Pools
    • cassandra.protocol - Protocol Features
    • cassandra.encoder - Encoders for non-prepared Statements
    • cassandra.decoder - Data Return Formats
    • cassandra.concurrent - Utilities for Concurrent Statement Execution
    • cassandra.connection - Low Level Connection Info
    • cassandra.util - Utilities
    • cassandra.timestamps - Timestamp Generation
    • cassandra.io.asyncioreactor - asyncio Event Loop
    • cassandra.io.asyncorereactor - asyncore Event Loop
    • cassandra.io.eventletreactor - eventlet-compatible Connection
    • cassandra.io.libevreactor - libev Event Loop
    • cassandra.io.geventreactor - gevent-compatible Event Loop
    • cassandra.io.twistedreactor - Twisted Event Loop
    • cassandra.cqlengine.models - Table models for object mapping
    • cassandra.cqlengine.columns - Column types for object mapping models
    • cassandra.cqlengine.query - Query and filter model objects
    • cassandra.cqlengine.connection - Connection management for cqlengine
    • cassandra.cqlengine.management - Schema management for cqlengine
    • cassandra.cqlengine.usertype - Model classes for User Defined Types
    • cassandra.datastax.graph - Graph Statements, Options, and Row Factories
    • cassandra.datastax.graph.fluent
    • cassandra.datastax.graph.fluent.query
    • cassandra.datastax.graph.fluent.predicates
  • Installation
  • Getting Started
  • Scylla Specific Features
  • Upgrading
  • Execution Profiles
  • Performance Notes
  • Paging Large Queries
  • Lightweight Transactions (Compare-and-set)
  • Security
  • User Defined Types
  • Object Mapper
    • Upgrade Guide
    • Models
    • Making Queries
    • Batch Queries
    • Connections
    • Third party integrations
    • Frequently Asked Questions
  • Working with Dates and Times
  • Scylla Cloud
  • Frequently Asked Questions
  • Create an issue
  • Edit this page

On this page

  • Execution Profiles
    • Mapping Legacy Parameters to Profiles
    • Using Execution Profiles
      • Default
      • Initializing cluster with profiles
      • Adding named profiles
      • Passing a profile instance without mapping
Logo
Docs Contact Us About Us
Mail List Icon Slack Icon
© ScyllaDB 2021 and © DataStax 2013-2017
Powered by Sphinx 4.3.2 & ScyllaDB Theme 1.2.2