updates to address review feedback

This commit is contained in:
Pankaj Garg
2022-02-05 11:46:09 -08:00
parent dfef68f985
commit c5d8560cdb

View File

@ -312,57 +312,50 @@ fn execute_batches(
let cost_model = CostModel::new(); let cost_model = CostModel::new();
let mut minimal_tx_cost = u64::MAX; let mut minimal_tx_cost = u64::MAX;
let total_cost: u64 = sanitized_txs let mut total_cost: u64 = 0;
let tx_costs = sanitized_txs
.iter() .iter()
.map(|tx| { .map(|tx| {
let cost = cost_model.calculate_cost(tx).sum(); let cost = cost_model.calculate_cost(tx).sum();
minimal_tx_cost = std::cmp::min(minimal_tx_cost, cost); minimal_tx_cost = std::cmp::min(minimal_tx_cost, cost);
total_cost = total_cost.saturating_add(cost);
cost cost
}) })
.sum(); .collect::<Vec<_>>();
let target_batch_count = get_thread_count() as u64; let target_batch_count = get_thread_count() as u64;
if total_cost > target_batch_count.saturating_mul(minimal_tx_cost) {
let target_batch_cost = total_cost / target_batch_count;
let mut batch_cost = 0;
let mut index = 0;
let mut tx_batches: Vec<TransactionBatch> = vec![]; let mut tx_batches: Vec<TransactionBatch> = vec![];
let mut slice_range = 0..0; let rebatched_txs = if total_cost > target_batch_count.saturating_mul(minimal_tx_cost) {
while index < sanitized_txs.len() { let target_batch_cost = total_cost / target_batch_count;
batch_cost += cost_model.calculate_cost(&sanitized_txs[index]).sum(); let mut batch_cost: u64 = 0;
index += 1; let mut slice_start = 0;
if batch_cost >= target_batch_cost || sanitized_txs.len() == index { tx_costs.into_iter().enumerate().for_each(|(index, cost)| {
slice_range.end = index; let next_index = index + 1;
let txs = &sanitized_txs[slice_range.clone()]; batch_cost = batch_cost.saturating_add(cost);
let results = &lock_results[slice_range.clone()]; if batch_cost >= target_batch_cost || next_index == sanitized_txs.len() {
let txs = &sanitized_txs[slice_start..=index];
let results = &lock_results[slice_start..=index];
let tx_batch = TransactionBatch::new(results.to_vec(), bank, Cow::from(txs)); let tx_batch = TransactionBatch::new(results.to_vec(), bank, Cow::from(txs));
slice_range.start = index; slice_start = next_index;
tx_batches.push(tx_batch); tx_batches.push(tx_batch);
batch_cost = 0; batch_cost = 0;
} }
} });
&tx_batches[..]
} else {
batches
};
execute_batches_internal( execute_batches_internal(
bank, bank,
&tx_batches, rebatched_txs,
entry_callback, entry_callback,
transaction_status_sender, transaction_status_sender,
replay_vote_sender, replay_vote_sender,
timings, timings,
cost_capacity_meter, cost_capacity_meter,
) )
} else {
execute_batches_internal(
bank,
batches,
entry_callback,
transaction_status_sender,
replay_vote_sender,
timings,
cost_capacity_meter,
)
}
} }
/// Process an ordered list of entries in parallel /// Process an ordered list of entries in parallel