mock: add prng
This commit is contained in:
parent
a10518486e
commit
6230725881
|
@ -126,6 +126,15 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.13"
|
||||
|
@ -2089,6 +2098,15 @@ version = "0.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4"
|
||||
|
||||
[[package]]
|
||||
name = "matchers"
|
||||
version = "0.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1"
|
||||
dependencies = [
|
||||
"regex-automata 0.1.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "matchers"
|
||||
version = "0.1.0"
|
||||
|
@ -4692,6 +4710,17 @@ dependencies = [
|
|||
"valuable",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-log"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f751112709b4e791d8ce53e32c4ed2d353565a795ce84da2285393f41557bdf2"
|
||||
dependencies = [
|
||||
"log",
|
||||
"once_cell",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-log"
|
||||
version = "0.2.0"
|
||||
|
@ -4703,13 +4732,45 @@ dependencies = [
|
|||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-serde"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-subscriber"
|
||||
version = "0.2.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"chrono",
|
||||
"lazy_static",
|
||||
"matchers 0.0.1",
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sharded-slab",
|
||||
"smallvec",
|
||||
"thread_local",
|
||||
"tracing",
|
||||
"tracing-core",
|
||||
"tracing-log 0.1.4",
|
||||
"tracing-serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-subscriber"
|
||||
version = "0.3.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
|
||||
dependencies = [
|
||||
"matchers",
|
||||
"matchers 0.1.0",
|
||||
"nu-ansi-term",
|
||||
"once_cell",
|
||||
"regex",
|
||||
|
@ -4718,7 +4779,7 @@ dependencies = [
|
|||
"thread_local",
|
||||
"tracing",
|
||||
"tracing-core",
|
||||
"tracing-log",
|
||||
"tracing-log 0.2.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -5267,6 +5328,8 @@ dependencies = [
|
|||
"tokio-stream",
|
||||
"tonic 0.10.2",
|
||||
"tonic-health",
|
||||
"tracing",
|
||||
"tracing-subscriber 0.2.25",
|
||||
"vergen",
|
||||
"yellowstone-grpc-proto",
|
||||
]
|
||||
|
@ -5314,7 +5377,7 @@ dependencies = [
|
|||
"tonic 0.10.2",
|
||||
"tonic-health",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
"tracing-subscriber 0.3.18",
|
||||
"vergen",
|
||||
"yellowstone-grpc-client",
|
||||
"yellowstone-grpc-proto",
|
||||
|
|
|
@ -44,6 +44,8 @@ yellowstone-grpc-proto = { workspace = true }
|
|||
rand = { version = "0.7.3", features = [] }
|
||||
bytes = "1.5.0"
|
||||
|
||||
tracing = "0.1.40"
|
||||
tracing-subscriber = { version = "0.2.15", features = ["env-filter"] }
|
||||
lz4_flex = { version = "0.11" }
|
||||
async-stream = "0.3.5"
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use bytes::Bytes;
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use rand::distributions::Standard;
|
||||
use rand::{random, thread_rng, Rng, RngCore};
|
||||
use solana_geyser_plugin_interface::geyser_plugin_interface::GeyserPluginError;
|
||||
|
@ -8,6 +8,7 @@ use solana_sdk::recent_blockhashes_account::update_account;
|
|||
use std::ops::Add;
|
||||
use std::thread::{sleep, spawn};
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
use log::{debug, info};
|
||||
use tokio::sync::mpsc::UnboundedSender;
|
||||
use tokio::time::Instant;
|
||||
use yellowstone_grpc_geyser::config::{ConfigBlockFailAction, ConfigGrpc, ConfigGrpcFilters};
|
||||
|
@ -18,6 +19,9 @@ use yellowstone_grpc_proto::geyser::CommitmentLevel;
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
tracing_subscriber::fmt::init();
|
||||
info!("starting mock service");
|
||||
|
||||
let config_grpc = ConfigGrpc {
|
||||
address: "127.0.0.1:50001".parse().unwrap(),
|
||||
tls_config: None,
|
||||
|
@ -38,7 +42,7 @@ async fn main() {
|
|||
tokio::spawn(mainnet_traffic(grpc_channel));
|
||||
|
||||
loop {
|
||||
println!("MOCK STILL RUNNING");
|
||||
debug!("MOCK STILL RUNNING");
|
||||
sleep(Duration::from_millis(1000));
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +59,7 @@ async fn mainnet_traffic(grpc_channel: UnboundedSender<Message>) {
|
|||
let sizes = vec![
|
||||
0, 8, 8, 165, 165, 165, 165, 11099, 11099, 11099, 11099, 11099, 11099,
|
||||
];
|
||||
const target_bytes_total: usize = 30_000_000;
|
||||
const target_bytes_total: usize = 10_000_000;
|
||||
let mut bytes_total = 0;
|
||||
|
||||
let mut requested_sizes: Vec<usize> = Vec::new();
|
||||
|
@ -83,10 +87,11 @@ async fn mainnet_traffic(grpc_channel: UnboundedSender<Message>) {
|
|||
let next_message_at =
|
||||
slot_started_at.add(Duration::from_secs_f64(avg_delay * i as f64));
|
||||
|
||||
let data: Vec<u8> = thread_rng()
|
||||
.sample_iter(&Standard)
|
||||
.take(data_bytes)
|
||||
.collect();
|
||||
let account_build_started_at = Instant::now();
|
||||
let mut data = BytesMut::with_capacity(data_bytes);
|
||||
fill_with_xor_prng(data.as_mut());
|
||||
let data = data.to_vec();
|
||||
|
||||
// using random slows down everything - could be the generator PRNG or the entropy preventing compression
|
||||
// let data: Vec<u8> = thread_rng().sample_iter(&Standard).take(data_bytes).collect();
|
||||
|
||||
|
@ -107,6 +112,10 @@ async fn mainnet_traffic(grpc_channel: UnboundedSender<Message>) {
|
|||
is_startup: false,
|
||||
};
|
||||
|
||||
let elapsed = account_build_started_at.elapsed();
|
||||
// 0.25us
|
||||
debug!("time consumed to build fake account message: {:.2}us", elapsed.as_secs_f64() * 1_000_000.0);
|
||||
|
||||
grpc_channel
|
||||
.send(Message::Account(update_account))
|
||||
.expect("channel was closed");
|
||||
|
@ -170,3 +179,21 @@ async fn helloworld_traffic(grpc_channel: UnboundedSender<Message>) {
|
|||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
}
|
||||
}
|
||||
|
||||
fn fill_with_xor_prng(binary: &mut [u8]) {
|
||||
// seed only first have of the binary; the sond half will be all 111
|
||||
let seed_n = binary.len() / 2;
|
||||
let mut state: u32 = 0xdeadbeef;
|
||||
for i_word in 0..seed_n / 4 {
|
||||
let mut x = state;
|
||||
x ^= x << 13;
|
||||
x ^= x >> 17;
|
||||
x ^= x << 5;
|
||||
state = x;
|
||||
|
||||
binary[i_word * 4 + 0] = (x >> 0) as u8;
|
||||
binary[i_word * 4 + 1] = (x >> 8) as u8;
|
||||
binary[i_word * 4 + 2] = (x >> 16) as u8;
|
||||
binary[i_word * 4 + 3] = (x >> 24) as u8;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue