Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(code/starknet): Add mempool load generator to the Starknet test app #821

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

OakenKnight
Copy link
Member

Closes: #801


PR author checklist

For all contributors

For external contributors

Copy link

codecov bot commented Jan 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.69%. Comparing base (e4194ab) to head (d6c56f4).
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #821      +/-   ##
==========================================
- Coverage   76.50%   74.69%   -1.81%     
==========================================
  Files         169      171       +2     
  Lines       14358    14898     +540     
==========================================
+ Hits        10984    11127     +143     
- Misses       3374     3771     +397     
Flag Coverage Δ
integration 74.38% <ø> (-1.79%) ⬇️
mbt 20.24% <ø> (-1.18%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@romac romac added work in progress Work in progress code Code/implementation related labels Jan 30, 2025
@romac romac changed the title feat(code/starknet): Improve mempool of Starknet test app feat(code/starknet): Add mempool load generator to the Starknet test app Jan 30, 2025
code/crates/starknet/host/src/host/starknet.rs Outdated Show resolved Hide resolved
code/crates/starknet/host/src/mempool_load.rs Outdated Show resolved Hide resolved
code/crates/starknet/host/src/mempool_load.rs Show resolved Hide resolved
code/crates/starknet/host/src/mempool_load.rs Outdated Show resolved Hide resolved
Comment on lines 114 to 120
let mut rng = rand::thread_rng();
let interval = Duration::from_secs(rng.gen_range(1..10));
let count = rng.gen_range(500..=10000) as usize;
let size = rng.gen_range(128..=512) as usize;
tokio::spawn(ticker(interval, myself.clone(), move || {
Msg::GenerateTransactions { count, size }
}))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still uniform load but with random parameters. A non-uniform load would have spikes of high load relative to the normal.

Maybe we could do something like this (in pseudo-Rust):

MempoolLoadType::NonUniformLoad {
    /// Base transaction count
    base_count: usize,

    /// Base transaction size
    base_size: usize,

    /// How much the transaction count can vary
    count_variation: std::ops::Range<i32>,

    size_variation: std::ops::Range<i32>,

    /// Chance of generating a spike.
    /// e.g. 0.1 = 10% chance of spike
    spike_probability: f64,

    /// Multiplier for spike transactions
    /// e.g. 10 = 10x more transactions during spike
    spike_multiplier: usize,

    /// Range of intervals between generating load, in milliseconds
    sleep_interval: std::ops::Range<u64>,
}
tokio::spawn(move async {
// Determine if this iteration should generate a spike
let is_spike = rng.gen_bool(params.spike_probability);

// Vary transaction count and size
let count_variation = rng.gen_range(params.count_variation);
let size_variation = rng.gen_range(params.size_variation);

let count = if is_spike {
    (params.base_count + count_variation) * params.spike_multiplier
} else {
    params.base_count + count_variation
};

let size = params.base_size + size_variation;

// Create and send the message
let msg = HostMsg::GenerateTransactions {
    count: count.max(1), // Ensure count is at least 1
    size: size.max(1),   // Ensure size is at least 1
};

if myself.send(msg).is_err() {
    println!("Channel closed, stopping load generator");
    break;
}

// Random sleep between 100ms and 1s
let sleep_duration = Duration::from_millis(params.sleep_interval);
sleep(sleep_duration);

Note that this does not require ticker as the sleep duration is random.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code Code/implementation related work in progress Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

code: Improve mempool of Starknet test app
2 participants