-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
different message generators for perftest
- Loading branch information
Showing
7 changed files
with
215 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use crate::perf::generate::{MessageGenerator, NextMessage}; | ||
use crate::proto; | ||
use crate::storage::store::test_helper; | ||
use crate::utils::cli; | ||
use crate::utils::factory::events_factory; | ||
use ed25519_dalek::SigningKey; | ||
use rand::Rng; | ||
use std::collections::HashSet; | ||
|
||
pub struct MultiUser { | ||
initialized_fids: HashSet<u32>, | ||
private_key: SigningKey, | ||
thread_id: u32, | ||
} | ||
|
||
impl MultiUser { | ||
pub fn new(thread_id: u32) -> Self { | ||
Self { | ||
initialized_fids: HashSet::new(), | ||
private_key: test_helper::default_signer(), | ||
thread_id, | ||
} | ||
} | ||
} | ||
|
||
impl MessageGenerator for MultiUser { | ||
fn next(&mut self, seq: u64) -> Vec<NextMessage> { | ||
let mut rng = rand::thread_rng(); | ||
|
||
let fid: u32 = rng.gen_range(1..=5000) + 1_000_000 * self.thread_id; | ||
let mut messages = Vec::new(); | ||
|
||
// If the FID has not been initialized, return initial messages | ||
if !self.initialized_fids.contains(&fid) { | ||
let private_key = self.private_key.clone(); | ||
|
||
messages.push(NextMessage::OnChainEvent(cli::compose_rent_event(fid))); | ||
messages.push(NextMessage::OnChainEvent( | ||
events_factory::create_id_register_event(fid, proto::IdRegisterEventType::Register), | ||
)); | ||
messages.push(NextMessage::OnChainEvent( | ||
events_factory::create_signer_event(fid, private_key, proto::SignerEventType::Add), | ||
)); | ||
|
||
self.initialized_fids.insert(fid); | ||
} | ||
|
||
// Add a benchmarking message | ||
let text = format!("For benchmarking {}", seq); | ||
let msg = cli::compose_message(fid, &text, None, Some(&self.private_key)); | ||
messages.push(NextMessage::Message(msg)); | ||
|
||
messages | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use crate::perf::generate::{MessageGenerator, NextMessage}; | ||
use crate::proto; | ||
use crate::storage::store::test_helper; | ||
use crate::utils::cli; | ||
use crate::utils::factory::events_factory; | ||
use ed25519_dalek::SigningKey; | ||
|
||
pub struct SingleUser { | ||
private_key: SigningKey, | ||
initialized: bool, | ||
thread_id: u32, | ||
} | ||
|
||
impl SingleUser { | ||
pub fn new(thread_id: u32) -> Self { | ||
Self { | ||
initialized: false, | ||
private_key: test_helper::default_signer(), | ||
thread_id, | ||
} | ||
} | ||
} | ||
|
||
impl MessageGenerator for SingleUser { | ||
fn next(&mut self, seq: u64) -> Vec<NextMessage> { | ||
let mut messages = Vec::new(); | ||
|
||
let fid = self.thread_id * 1_000_000; | ||
|
||
if !self.initialized { | ||
self.initialized = true; | ||
messages.push(NextMessage::OnChainEvent(cli::compose_rent_event(fid))); | ||
messages.push(NextMessage::OnChainEvent( | ||
events_factory::create_id_register_event(fid, proto::IdRegisterEventType::Register), | ||
)); | ||
messages.push(NextMessage::OnChainEvent( | ||
events_factory::create_signer_event( | ||
fid, | ||
self.private_key.clone(), | ||
proto::SignerEventType::Add, | ||
), | ||
)); | ||
} | ||
|
||
let text = format!("For benchmarking {}", seq); | ||
let msg = cli::compose_message(fid, &text, None, Some(&self.private_key)); | ||
messages.push(NextMessage::Message(msg)); | ||
|
||
messages | ||
} | ||
} | ||
|
||
pub fn assert_send<T: Send>() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::perf::gen_multi::MultiUser; | ||
use crate::perf::gen_single::SingleUser; | ||
use crate::proto; | ||
|
||
pub enum NextMessage { | ||
OnChainEvent(proto::OnChainEvent), | ||
Message(proto::Message), | ||
} | ||
|
||
pub trait MessageGenerator: Send { | ||
fn next(&mut self, seq: u64) -> Vec<NextMessage>; | ||
} | ||
|
||
#[derive(Clone)] | ||
pub enum GeneratorTypes { | ||
SingleUser, | ||
MultiUser, | ||
} | ||
|
||
pub fn new_generator(typ: GeneratorTypes, thread_id: u32) -> Box<dyn MessageGenerator> { | ||
match typ { | ||
GeneratorTypes::SingleUser => Box::new(SingleUser::new(thread_id)), | ||
GeneratorTypes::MultiUser => Box::new(MultiUser::new(thread_id)), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
pub mod engine_only_perftest; | ||
mod gen_multi; | ||
mod gen_single; | ||
pub mod generate; | ||
pub mod perftest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters