Skip to content

Commit

Permalink
add bench test for pool map
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Mar 14, 2024
1 parent 08e50f2 commit 8463d72
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 32 deletions.
13 changes: 0 additions & 13 deletions tx-pool/src/component/pool_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ impl PoolMap {
self.get_by_id(id).expect("unconsistent pool")
}

pub(crate) fn get_by_status(&self, status: Status) -> Vec<&PoolEntry> {
self.entries.get_by_status(&status)
}

pub(crate) fn pending_size(&self) -> usize {
self.pending_count + self.gap_count
}
Expand Down Expand Up @@ -656,15 +652,6 @@ impl PoolMap {
self.pending_count + self.gap_count + self.proposed_count,
self.entries.len()
);
// let duration = instant.elapsed();
// eprintln!(
// "pending: {}, gap: {}, proposed: {} => duration: {:?} total_entries_size: {}",
// self.pending_count,
// self.gap_count,
// self.proposed_count,
// duration,
// self.entries.len()
// );
if let Some(metrics) = ckb_metrics::handle() {
metrics
.ckb_tx_pool_entry
Expand Down
24 changes: 14 additions & 10 deletions tx-pool/src/component/tests/proposed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,8 @@ fn test_pool_map_bench() {
let mut pool = PoolMap::new(150);

let mut instant = Instant::now();
for i in 0..500000 {
let mut time_spend = vec![];
for i in 0..20000 {
let lock_script1 = ScriptBuilder::default()
.code_hash(H256(rand::random()).pack())
.hash_type(ScriptHashType::Data.into())
Expand Down Expand Up @@ -777,22 +778,25 @@ fn test_pool_map_bench() {
Capacity::shannons(200),
rng.gen_range(0..1000),
);
let short_id = entry.proposal_short_id();
if i % 1000 == 0 {
if i % 5000 == 0 && i != 0 {
eprintln!("i: {}, time: {:?}", i, instant.elapsed());
time_spend.push(instant.elapsed());
instant = Instant::now();
}
let status = if rng.gen_range(0..100) >= 30 {
Status::Pending
} else {
Status::Gap
};
pool.add_entry(entry, status);
let _ = pool.add_entry(entry, status);
}
// for _i in 0..100 {
// let instant = Instant::now();
// let res = pool.track_entry_statics(None, None);
// let duration = instant.elapsed();
// eprintln!("duration: {:?}", duration);
// }
let first = time_spend[0].as_millis();
let last = time_spend.last().unwrap().as_millis();
let diff = (last as i128 - first as i128).abs();
let expect_diff_range = ((first as f64) * 0.15) as i128;
eprintln!(
"first: {} last: {}, diff: {}, range: {}",
first, last, diff, expect_diff_range
);
assert!(diff < expect_diff_range);
}
9 changes: 0 additions & 9 deletions tx-pool/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,6 @@ impl TxPool {
Arc::clone(&self.snapshot)
}

fn get_by_status(&self, status: Status) -> Vec<&PoolEntry> {
self.pool_map.get_by_status(status)
}

/// Get tx-pool size
pub fn status_size(&self, status: Status) -> usize {
self.get_by_status(status).len()
}

/// Check whether tx-pool enable RBF
pub fn enable_rbf(&self) -> bool {
self.config.min_rbf_rate > self.config.min_fee_rate
Expand Down

0 comments on commit 8463d72

Please sign in to comment.