Skip to main content

MultiTransaction

Struct MultiTransaction 

Source
pub struct MultiTransaction(/* private fields */);

Implementations§

Source§

impl MultiTransaction

Source

pub fn oracle_window_count(&self) -> usize

Source

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

Source

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>

Source

pub fn spawner(&self) -> ActorSpawner

Source

pub fn config(&self) -> Arc<dyn GetConfig>

Source

pub fn advance_version_to(&self, version: CommitVersion)

Source

pub fn bootstrapping_completed(&self)

Source

pub fn query_done_until(&self) -> CommitVersion

Source§

impl MultiTransaction

Source§

impl MultiTransaction

Source

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

Source

pub fn get( &self, key: &TaggedKey, version: CommitVersion, ) -> Result<Option<Committed>>

Source

pub fn contains_key( &self, key: &TaggedKey, version: CommitVersion, ) -> Result<bool>

Source

pub fn store(&self) -> &MultiStore

Source§

impl MultiTransaction

Source

pub fn current_version(&self) -> Result<CommitVersion>

Source

pub fn done_until(&self) -> CommitVersion

Source

pub fn wait_for_mark_timeout( &self, version: CommitVersion, timeout: Duration, ) -> bool

Source

pub fn notify_on_mark( &self, version: CommitVersion, callback: Box<dyn FnOnce() + Send>, )

Trait Implementations§

Source§

impl Clone for MultiTransaction

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Deref for MultiTransaction

Source§

type Target = Inner

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl WithEventBus for MultiTransaction

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more