forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
shrink batches when over 80% of the space is wasted (solana-labs#23066)
* shrink batches when over 80% of the space is wasted
- Loading branch information
1 parent
a68c496
commit 01b18e0
Showing
4 changed files
with
457 additions
and
22 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
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,86 @@ | ||
#![allow(clippy::integer_arithmetic)] | ||
#![feature(test)] | ||
|
||
extern crate test; | ||
|
||
use { | ||
rand::prelude::*, | ||
solana_perf::{ | ||
packet::{to_packet_batches, PacketBatch, PACKETS_PER_BATCH}, | ||
sigverify, | ||
}, | ||
test::Bencher, | ||
}; | ||
|
||
const NUM_PACKETS: usize = 1024 * 4; | ||
|
||
fn test_packet_with_size(size: usize, rng: &mut ThreadRng) -> Vec<u8> { | ||
// subtract 8 bytes because the length will get serialized as well | ||
(0..size.checked_sub(8).unwrap()) | ||
.map(|_| rng.gen()) | ||
.collect() | ||
} | ||
|
||
fn do_bench_shrink_packets(bencher: &mut Bencher, mut batches: Vec<PacketBatch>) { | ||
// verify packets | ||
bencher.iter(|| { | ||
let _ans = sigverify::shrink_batches(&mut batches); | ||
batches.iter_mut().for_each(|b| { | ||
b.packets | ||
.iter_mut() | ||
.for_each(|p| p.meta.set_discard(thread_rng().gen())) | ||
}); | ||
}); | ||
} | ||
|
||
#[bench] | ||
#[ignore] | ||
fn bench_shrink_diff_small_packets(bencher: &mut Bencher) { | ||
let mut rng = rand::thread_rng(); | ||
|
||
let batches = to_packet_batches( | ||
&(0..NUM_PACKETS) | ||
.map(|_| test_packet_with_size(128, &mut rng)) | ||
.collect::<Vec<_>>(), | ||
PACKETS_PER_BATCH, | ||
); | ||
|
||
do_bench_shrink_packets(bencher, batches); | ||
} | ||
|
||
#[bench] | ||
#[ignore] | ||
fn bench_shrink_diff_big_packets(bencher: &mut Bencher) { | ||
let mut rng = rand::thread_rng(); | ||
|
||
let batches = to_packet_batches( | ||
&(0..NUM_PACKETS) | ||
.map(|_| test_packet_with_size(1024, &mut rng)) | ||
.collect::<Vec<_>>(), | ||
PACKETS_PER_BATCH, | ||
); | ||
|
||
do_bench_shrink_packets(bencher, batches); | ||
} | ||
|
||
#[bench] | ||
#[ignore] | ||
fn bench_shrink_count_packets(bencher: &mut Bencher) { | ||
let mut rng = rand::thread_rng(); | ||
|
||
let mut batches = to_packet_batches( | ||
&(0..NUM_PACKETS) | ||
.map(|_| test_packet_with_size(128, &mut rng)) | ||
.collect::<Vec<_>>(), | ||
PACKETS_PER_BATCH, | ||
); | ||
batches.iter_mut().for_each(|b| { | ||
b.packets | ||
.iter_mut() | ||
.for_each(|p| p.meta.set_discard(thread_rng().gen())) | ||
}); | ||
|
||
bencher.iter(|| { | ||
let _ = sigverify::count_valid_packets(&batches); | ||
}); | ||
} |
Oops, something went wrong.