ExecutionProfile is a grouping of configurable options regarding CQL statement execution. Profiles can be created to represent different workloads, which can be run conveniently on a single session.
Overview
Execution profiles enable you to configure different execution settings for different queries:- Consistency levels - Read and write consistency requirements
- Timeouts - Client-side request timeouts
- Load balancing - Node selection strategy
- Retry policy - How to handle retries
- Speculative execution - When to send speculative requests
ExecutionProfile- Immutable set of settingsExecutionProfileHandle- Handle that points to a profile
Creating a Profile
Use the builder pattern to create a profile:Using with Session
Set a default execution profile for all session operations:Using with Statements
Attach a profile to individual statements:Builder Methods
builder
Creates a new
ExecutionProfileBuilder with all options set to defaults.Returns: ExecutionProfileBuilderExample:to_builder
Creates a builder with all options set to the same values as this profile.Useful for creating variations of an existing profile.Returns:
ExecutionProfileBuilderExample:Configuration Methods
consistency
Sets the default consistency level for statement executions.Can be overridden by explicitly setting consistency on individual statements.Default:
Consistency::LocalQuorumParameters:consistency: Consistency- Consistency level to use
ExecutionProfileBuilderExample:serial_consistency
Sets the default serial consistency for lightweight transactions (CAS operations).Can be overridden by explicitly setting serial consistency on individual statements.Default:
Some(SerialConsistency::LocalSerial)Parameters:serial_consistency: Option<SerialConsistency>- Serial consistency to use
ExecutionProfileBuilderExample:request_timeout
Sets the client-side timeout for executing statements.If set to
None, the driver will wait indefinitely for a response.Default: Some(Duration::from_secs(30))Parameters:timeout: Option<Duration>- Timeout duration orNonefor no timeout
ExecutionProfileBuilderExample:load_balancing_policy
Sets the load balancing policy for selecting which nodes to query.Default: See
DefaultPolicyParameters:load_balancing_policy: Arc<dyn LoadBalancingPolicy>- Policy to use
ExecutionProfileBuilderExample:LoadBalancingPolicy for more information.retry_policy
Sets the retry policy for handling failed queries.Default: See
DefaultRetryPolicyParameters:retry_policy: Arc<dyn RetryPolicy>- Policy to use
ExecutionProfileBuilderExample:RetryPolicy for more information.speculative_execution_policy
Sets the speculative execution policy for sending backup queries.Speculative execution sends the same query to multiple nodes if the first doesn’t respond quickly enough.Default: See
None (disabled)Parameters:speculative_execution_policy: Option<Arc<dyn SpeculativeExecutionPolicy>>- Policy to use
ExecutionProfileBuilderExample:SpeculativeExecutionPolicy for more information.build
Builds the
ExecutionProfile after setting all options.Returns: ExecutionProfileExample:Profile Methods
into_handle
Converts the profile into an
ExecutionProfileHandle.Handles can be cloned and shared across multiple sessions and statements.Returns: ExecutionProfileHandleExample:into_handle_with_label
Converts the profile into an
ExecutionProfileHandle with a debugging label.The label is useful for debugging when tracking which statements use which profiles.Parameters:label: String- Debug label for the handle
ExecutionProfileHandleExample:Getters
The following methods retrieve the current settings from a profile:Gets the client timeout associated with this profile.Returns:
Option<Duration>Gets the consistency level associated with this profile.Returns:
ConsistencyGets the serial consistency (if set) associated with this profile.Returns:
Option<SerialConsistency>Gets the load balancing policy associated with this profile.Returns:
&Arc<dyn LoadBalancingPolicy>Gets the retry policy associated with this profile.Returns:
&Arc<dyn RetryPolicy>Gets the speculative execution policy associated with this profile.Returns:
Option<&Arc<dyn SpeculativeExecutionPolicy>>ExecutionProfileHandle
A handle that points to anExecutionProfile. Handles enable remapping all associated entities (statements/sessions) to another profile at once.
Cloned handles initially point to the same execution profile. Remapping one handle affects all clones, as they share the same underlying reference through
Arc<ArcSwap>.pointee_to_builder
Creates a builder with settings from the profile this handle points to.Returns:
ExecutionProfileBuilderExample:to_profile
Returns the execution profile currently pointed to by this handle.Returns:
ExecutionProfileExample:map_to_another_profile
Makes the handle point to a new execution profile.All entities (statements/sessions) holding this handle will immediately reflect the change.Parameters:
profile: ExecutionProfile- New profile to point to
Workload Examples
Multiple Workloads
Dynamic Remapping
Default Values
| Setting | Default Value |
|---|---|
| Consistency | LocalQuorum |
| Serial Consistency | Some(LocalSerial) |
| Request Timeout | Some(30 seconds) |
| Load Balancing Policy | DefaultPolicy |
| Retry Policy | DefaultRetryPolicy |
| Speculative Execution | None (disabled) |
Related Types
Session- Can use execution profiles for all operationsSessionBuilder- Set default execution profile withdefault_execution_profile_handle()Statement- Can have an execution profile attachedPreparedStatement- Can have an execution profile attachedLoadBalancingPolicy- Node selection strategyRetryPolicy- Retry behavior configurationSpeculativeExecutionPolicy- Speculative execution configuration
