Expand description
ExecutionProfile is a grouping of configurable options regarding CQL statement execution.
Profiles can be created to represent different workloads, which thanks to them can be run conveniently on a single session.
There are two classes of objects related to execution profiles: ExecutionProfile and ExecutionProfileHandle.
The former is simply an immutable set of the settings. The latter is a handle that at particular moment points
to some ExecutionProfile (but during its lifetime, it can change the profile it points at).
Handles are assigned to Sessions and Statements.
At any moment, handles point to another ExecutionProfile. This allows convenient switching between workloads
for all Sessions and/or Statements that, for instance, share common characteristics.
§Example
To create an ExecutionProfile and attach it as default for Session:
use scylla::client::session::Session;
use scylla::client::session_builder::SessionBuilder;
use scylla::statement::Consistency;
use scylla::client::execution_profile::ExecutionProfile;
let profile = ExecutionProfile::builder()
.consistency(Consistency::LocalOne)
.request_timeout(None) // no request timeout
.build();
let handle = profile.into_handle();
let session: Session = SessionBuilder::new()
.known_node("127.0.0.1:9042")
.default_execution_profile_handle(handle)
.build()
.await?;§Example
To create an ExecutionProfile and attach it to a Statement:
use scylla::statement::unprepared::Statement;
use scylla::statement::Consistency;
use scylla::client::execution_profile::ExecutionProfile;
use std::time::Duration;
let profile = ExecutionProfile::builder()
.consistency(Consistency::All)
.request_timeout(Some(Duration::from_secs(30)))
.build();
let handle = profile.into_handle();
let mut query1 = Statement::from("SELECT * FROM ks.table");
query1.set_execution_profile_handle(Some(handle.clone()));
let mut query2 = Statement::from("SELECT pk FROM ks.table WHERE pk = ?");
query2.set_execution_profile_handle(Some(handle));§Example
To create an ExecutionProfile with config options defaulting
to those set on another profile:
use scylla::statement::Consistency;
use scylla::client::execution_profile::ExecutionProfile;
use std::time::Duration;
let base_profile = ExecutionProfile::builder()
.request_timeout(Some(Duration::from_secs(30)))
.build();
let profile = base_profile.to_builder()
.consistency(Consistency::All)
.build();
ExecutionProfileHandles can be remapped to another ExecutionProfile, and the change affects all sessions and statements that have been assigned that handle. This enables quick workload switches.
Example mapping:
- session1 -> handle1 -> profile1
- statement1 -> handle1 -> profile1
- statement2 -> handle2 -> profile2
We can now remap handle2 to profile1, so that the mapping for statement2 becomes as follows:
- statement2 -> handle2 -> profile1
We can also change statement1’s handle to handle2, and remap handle1 to profile2, yielding:
- session1 -> handle1 -> profile2
- statement1 -> handle2 -> profile1
- statement2 -> handle2 -> profile1
As you can see, profiles are a powerful and convenient way to define and modify your workloads.
§Example
Below, the remaps described above are followed in code.
use scylla::client::session::Session;
use scylla::client::session_builder::SessionBuilder;
use scylla::statement::unprepared::Statement;
use scylla::statement::Consistency;
use scylla::client::execution_profile::ExecutionProfile;
let profile1 = ExecutionProfile::builder()
.consistency(Consistency::One)
.build();
let profile2 = ExecutionProfile::builder()
.consistency(Consistency::Two)
.build();
let mut handle1 = profile1.clone().into_handle();
let mut handle2 = profile2.clone().into_handle();
let session: Session = SessionBuilder::new()
.known_node("127.0.0.1:9042")
.default_execution_profile_handle(handle1.clone())
.build()
.await?;
let mut query1 = Statement::from("SELECT * FROM ks.table");
let mut query2 = Statement::from("SELECT pk FROM ks.table WHERE pk = ?");
query1.set_execution_profile_handle(Some(handle1.clone()));
query2.set_execution_profile_handle(Some(handle2.clone()));
// session1 -> handle1 -> profile1
// query1 -> handle1 -> profile1
// query2 -> handle2 -> profile2
// We can now remap handle2 to profile1:
handle2.map_to_another_profile(profile1);
// ...so that the mapping for query2 becomes as follows:
// query2 -> handle2 -> profile1
// We can also change query1's handle to handle2:
query1.set_execution_profile_handle(Some(handle2.clone()));
// ...and remap handle1 to profile2:
handle1.map_to_another_profile(profile2);
// ...yielding:
// session1 -> handle1 -> profile2
// query1 -> handle2 -> profile1
// query2 -> handle2 -> profile1
Structs§
- Execution
Profile - A profile that groups configurable options regarding statement execution.
- Execution
Profile Builder ExecutionProfileBuilderis used to create newExecutionProfiles- Execution
Profile Handle - A handle that points to an ExecutionProfile.