pub struct MultiTransaction(/* private fields */);Implementations§
Source§impl MultiTransaction
impl MultiTransaction
pub fn oracle_window_count(&self) -> usize
Sourcepub fn testing() -> Self
pub fn testing() -> Self
Examples found in repository?
examples/oracle_performance.rs (line 47)
39pub fn oracle_performance_benchmark() {
40 println!("=== Oracle Performance Benchmark ===\n");
41
42 let test_sizes = vec![1000, 5000, 10000, 25000];
43
44 for &num_txns in &test_sizes {
45 println!("Testing with {} transactions...", num_txns);
46
47 let engine = MultiTransaction::testing();
48
49 let start = Instant::now();
50
51 for i in 0..num_txns {
52 let mut tx = engine.begin_command().unwrap();
53
54 let key = as_key!(format!("key_{}", i));
55 let value = as_values!(format!("value_{}", i));
56
57 tx.set(&key, value).unwrap();
58 tx.commit(vec![]).unwrap();
59 }
60
61 let duration = start.elapsed();
62 let tps = num_txns as f64 / duration.as_secs_f64();
63
64 println!(" {} transactions in {:?}", num_txns, duration);
65 println!(" {:.0} TPS (transactions per second)", tps);
66 println!(" {:.2} μs per transaction\n", duration.as_micros() as f64 / num_txns as f64);
67 }
68}
69
70pub fn concurrent_oracle_benchmark() {
71 println!("=== Concurrent Oracle Performance Benchmark ===\n");
72
73 let test_configs = vec![(10, 1000), (50, 500), (100, 250), (1000, 50)];
74
75 for &(num_threads, txns_per_thread) in &test_configs {
76 let total_txns = num_threads * txns_per_thread;
77 println!(
78 "Testing {} threads × {} transactions = {} total...",
79 num_threads, txns_per_thread, total_txns
80 );
81
82 let engine = Arc::new(MultiTransaction::testing());
83 let start = Instant::now();
84
85 let mut handles = vec![];
86
87 for thread_id in 0..num_threads {
88 let engine_clone = engine.clone();
89 let handle = spawn(move || {
90 let base_key = thread_id * txns_per_thread;
91 for i in 0..txns_per_thread {
92 let mut tx = engine_clone.begin_command().unwrap();
93
94 let key = as_key!(base_key + i);
95 let value = as_values!(i);
96
97 tx.set(&key, value).unwrap();
98 tx.commit(vec![]).unwrap();
99 }
100 });
101 handles.push(handle);
102 }
103
104 for handle in handles {
105 handle.join().expect("Task panicked");
106 }
107
108 let duration = start.elapsed();
109 let tps = total_txns as f64 / duration.as_secs_f64();
110
111 println!(" {} total transactions in {:?}", total_txns, duration);
112 println!(" {:.0} TPS (transactions per second)", tps);
113 println!(" {:.2} μs per transaction\n", duration.as_micros() as f64 / total_txns as f64);
114 }
115}
116
117pub fn conflict_detection_benchmark() {
118 println!("=== Conflict Detection Performance Benchmark ===\n");
119
120 let engine = MultiTransaction::testing();
121
122 for i in 0..1000 {
123 let mut tx = engine.begin_command().unwrap();
124 let key = as_key!(format!("shared_key_{}", i % 100));
125 let value = as_values!(i);
126 tx.set(&key, value).unwrap();
127 tx.commit(vec![]).unwrap();
128 }
129
130 println!("Pre-populated with 1000 transactions across 100 keys");
131
132 let num_conflict_txns = 10000;
133 let start = Instant::now();
134 let mut conflicts = 0;
135
136 for i in 0..num_conflict_txns {
137 let mut tx = engine.begin_command().unwrap();
138
139 let key = as_key!(format!("shared_key_{}", i % 100));
140 let value = as_values!(i + 1000);
141
142 tx.set(&key, value).unwrap();
143
144 match tx.commit(vec![]) {
145 Ok(_) => {}
146 Err(e) if e.code == "TXN_001" => {
147 conflicts += 1;
148 }
149 Err(e) => panic!("Unexpected error: {:?}", e),
150 };
151 }
152
153 let duration = start.elapsed();
154 let tps = num_conflict_txns as f64 / duration.as_secs_f64();
155
156 println!(" {} transactions with potential conflicts in {:?}", num_conflict_txns, duration);
157 println!(
158 " {} actual conflicts detected ({:.1}%)",
159 conflicts,
160 conflicts as f64 / num_conflict_txns as f64 * 100.0
161 );
162 println!(" {:.0} TPS (transactions per second)", tps);
163 println!(" {:.2} μs per transaction", duration.as_micros() as f64 / num_conflict_txns as f64);
164}Source§impl MultiTransaction
impl MultiTransaction
pub fn new( store: MultiStore, single: SingleTransaction, event_bus: EventBus, spawner: ActorSpawner, metrics_clock: Clock, version_epoch: VersionEpoch, rng: Rng, config: Arc<dyn GetConfig>, ) -> Result<Self>
pub fn spawner(&self) -> ActorSpawner
pub fn config(&self) -> Arc<dyn GetConfig> ⓘ
pub fn advance_version_to(&self, version: CommitVersion)
pub fn bootstrapping_completed(&self)
pub fn query_done_until(&self) -> CommitVersion
Source§impl MultiTransaction
impl MultiTransaction
pub fn version(&self) -> Result<CommitVersion>
pub fn begin_query(&self) -> Result<MultiReadTransaction>
pub fn begin_query_at_version( &self, lease: &VersionLeaseGuard, ) -> Result<MultiReadTransaction>
pub fn acquire_version_lease( &self, version: CommitVersion, ) -> Result<VersionLeaseGuard>
pub fn acquire_current_snapshot_lease( &self, ) -> Result<(CommitVersion, VersionLeaseGuard)>
pub fn leases(&self) -> Arc<VersionLeases> ⓘ
Source§impl MultiTransaction
impl MultiTransaction
Sourcepub fn begin_command(&self) -> Result<MultiWriteTransaction>
pub fn begin_command(&self) -> Result<MultiWriteTransaction>
Examples found in repository?
examples/oracle_performance.rs (line 52)
39pub fn oracle_performance_benchmark() {
40 println!("=== Oracle Performance Benchmark ===\n");
41
42 let test_sizes = vec![1000, 5000, 10000, 25000];
43
44 for &num_txns in &test_sizes {
45 println!("Testing with {} transactions...", num_txns);
46
47 let engine = MultiTransaction::testing();
48
49 let start = Instant::now();
50
51 for i in 0..num_txns {
52 let mut tx = engine.begin_command().unwrap();
53
54 let key = as_key!(format!("key_{}", i));
55 let value = as_values!(format!("value_{}", i));
56
57 tx.set(&key, value).unwrap();
58 tx.commit(vec![]).unwrap();
59 }
60
61 let duration = start.elapsed();
62 let tps = num_txns as f64 / duration.as_secs_f64();
63
64 println!(" {} transactions in {:?}", num_txns, duration);
65 println!(" {:.0} TPS (transactions per second)", tps);
66 println!(" {:.2} μs per transaction\n", duration.as_micros() as f64 / num_txns as f64);
67 }
68}
69
70pub fn concurrent_oracle_benchmark() {
71 println!("=== Concurrent Oracle Performance Benchmark ===\n");
72
73 let test_configs = vec![(10, 1000), (50, 500), (100, 250), (1000, 50)];
74
75 for &(num_threads, txns_per_thread) in &test_configs {
76 let total_txns = num_threads * txns_per_thread;
77 println!(
78 "Testing {} threads × {} transactions = {} total...",
79 num_threads, txns_per_thread, total_txns
80 );
81
82 let engine = Arc::new(MultiTransaction::testing());
83 let start = Instant::now();
84
85 let mut handles = vec![];
86
87 for thread_id in 0..num_threads {
88 let engine_clone = engine.clone();
89 let handle = spawn(move || {
90 let base_key = thread_id * txns_per_thread;
91 for i in 0..txns_per_thread {
92 let mut tx = engine_clone.begin_command().unwrap();
93
94 let key = as_key!(base_key + i);
95 let value = as_values!(i);
96
97 tx.set(&key, value).unwrap();
98 tx.commit(vec![]).unwrap();
99 }
100 });
101 handles.push(handle);
102 }
103
104 for handle in handles {
105 handle.join().expect("Task panicked");
106 }
107
108 let duration = start.elapsed();
109 let tps = total_txns as f64 / duration.as_secs_f64();
110
111 println!(" {} total transactions in {:?}", total_txns, duration);
112 println!(" {:.0} TPS (transactions per second)", tps);
113 println!(" {:.2} μs per transaction\n", duration.as_micros() as f64 / total_txns as f64);
114 }
115}
116
117pub fn conflict_detection_benchmark() {
118 println!("=== Conflict Detection Performance Benchmark ===\n");
119
120 let engine = MultiTransaction::testing();
121
122 for i in 0..1000 {
123 let mut tx = engine.begin_command().unwrap();
124 let key = as_key!(format!("shared_key_{}", i % 100));
125 let value = as_values!(i);
126 tx.set(&key, value).unwrap();
127 tx.commit(vec![]).unwrap();
128 }
129
130 println!("Pre-populated with 1000 transactions across 100 keys");
131
132 let num_conflict_txns = 10000;
133 let start = Instant::now();
134 let mut conflicts = 0;
135
136 for i in 0..num_conflict_txns {
137 let mut tx = engine.begin_command().unwrap();
138
139 let key = as_key!(format!("shared_key_{}", i % 100));
140 let value = as_values!(i + 1000);
141
142 tx.set(&key, value).unwrap();
143
144 match tx.commit(vec![]) {
145 Ok(_) => {}
146 Err(e) if e.code == "TXN_001" => {
147 conflicts += 1;
148 }
149 Err(e) => panic!("Unexpected error: {:?}", e),
150 };
151 }
152
153 let duration = start.elapsed();
154 let tps = num_conflict_txns as f64 / duration.as_secs_f64();
155
156 println!(" {} transactions with potential conflicts in {:?}", num_conflict_txns, duration);
157 println!(
158 " {} actual conflicts detected ({:.1}%)",
159 conflicts,
160 conflicts as f64 / num_conflict_txns as f64 * 100.0
161 );
162 println!(" {:.0} TPS (transactions per second)", tps);
163 println!(" {:.2} μs per transaction", duration.as_micros() as f64 / num_conflict_txns as f64);
164}Source§impl MultiTransaction
impl MultiTransaction
pub fn get( &self, key: &TaggedKey, version: CommitVersion, ) -> Result<Option<Committed>>
pub fn contains_key( &self, key: &TaggedKey, version: CommitVersion, ) -> Result<bool>
pub fn store(&self) -> &MultiStore
Source§impl MultiTransaction
impl MultiTransaction
pub fn current_version(&self) -> Result<CommitVersion>
pub fn done_until(&self) -> CommitVersion
pub fn wait_for_mark_timeout( &self, version: CommitVersion, timeout: Duration, ) -> bool
pub fn notify_on_mark( &self, version: CommitVersion, callback: Box<dyn FnOnce() + Send>, )
Trait Implementations§
Source§impl Clone for MultiTransaction
impl Clone for MultiTransaction
Source§impl Deref for MultiTransaction
impl Deref for MultiTransaction
Source§impl WithEventBus for MultiTransaction
impl WithEventBus for MultiTransaction
Auto Trait Implementations§
impl !RefUnwindSafe for MultiTransaction
impl !UnwindSafe for MultiTransaction
impl Freeze for MultiTransaction
impl Send for MultiTransaction
impl Sync for MultiTransaction
impl Unpin for MultiTransaction
impl UnsafeUnpin for MultiTransaction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more