1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
use aptos_crypto::hash::HashValue;
use aptos_logger::prelude::*;
use aptos_types::{
block_info::BlockInfo,
ledger_info::{LedgerInfo, LedgerInfoWithSignatures},
transaction::Version,
};
use aptos_vm::AptosVM;
use aptosdb::metrics::API_LATENCY_SECONDS;
use executor::{
block_executor::BlockExecutor,
metrics::{
APTOS_EXECUTOR_COMMIT_BLOCKS_SECONDS, APTOS_EXECUTOR_EXECUTE_BLOCK_SECONDS,
APTOS_EXECUTOR_VM_EXECUTE_BLOCK_SECONDS,
},
};
use executor_types::BlockExecutorTrait;
use std::{
collections::BTreeMap,
sync::{mpsc, Arc},
time::{Duration, Instant},
};
pub(crate) fn gen_li_with_sigs(
block_id: HashValue,
root_hash: HashValue,
version: Version,
) -> LedgerInfoWithSignatures {
let block_info = BlockInfo::new(
1,
0,
block_id,
root_hash, version, 0,
None,
);
let ledger_info = LedgerInfo::new(
block_info,
HashValue::zero(),
);
LedgerInfoWithSignatures::new(ledger_info, BTreeMap::new() )
}
pub struct TransactionCommitter {
executor: Arc<BlockExecutor<AptosVM>>,
version: Version,
block_receiver: mpsc::Receiver<(HashValue, HashValue, Instant, Instant, Duration, usize)>,
}
impl TransactionCommitter {
pub fn new(
executor: Arc<BlockExecutor<AptosVM>>,
version: Version,
block_receiver: mpsc::Receiver<(HashValue, HashValue, Instant, Instant, Duration, usize)>,
) -> Self {
Self {
version,
executor,
block_receiver,
}
}
pub fn run(&mut self) {
let start_version = self.version;
info!("Start with version: {}", start_version);
while let Ok((
block_id,
root_hash,
global_start_time,
execution_start_time,
execution_time,
num_txns,
)) = self.block_receiver.recv()
{
self.version += num_txns as u64;
let commit_start = std::time::Instant::now();
let ledger_info_with_sigs = gen_li_with_sigs(block_id, root_hash, self.version);
self.executor
.commit_blocks(vec![block_id], ledger_info_with_sigs)
.unwrap();
report_block(
start_version,
self.version,
global_start_time,
execution_start_time,
execution_time,
Instant::now().duration_since(commit_start),
num_txns,
);
}
}
}
fn report_block(
start_version: Version,
version: Version,
global_start_time: Instant,
execution_start_time: Instant,
execution_time: Duration,
commit_time: Duration,
block_size: usize,
) {
let total_versions = (version - start_version) as f64;
info!(
"Version: {}. latency: {} ms, execute time: {} ms. commit time: {} ms. TPS: {:.0}. Accumulative TPS: {:.0}",
version,
Instant::now().duration_since(execution_start_time).as_millis(),
execution_time.as_millis(),
commit_time.as_millis(),
block_size as f64 / (std::cmp::max(execution_time, commit_time)).as_secs_f64(),
total_versions / global_start_time.elapsed().as_secs_f64(),
);
info!(
"Accumulative total: VM time: {:.0} secs, executor time: {:.0} secs, commit time: {:.0} secs, DB commit time: {:.0} secs",
APTOS_EXECUTOR_VM_EXECUTE_BLOCK_SECONDS.get_sample_sum(),
APTOS_EXECUTOR_EXECUTE_BLOCK_SECONDS.get_sample_sum() - APTOS_EXECUTOR_VM_EXECUTE_BLOCK_SECONDS.get_sample_sum(),
APTOS_EXECUTOR_COMMIT_BLOCKS_SECONDS.get_sample_sum(),
API_LATENCY_SECONDS.get_metric_with_label_values(&["save_transactions", "Ok"]).expect("must exist.").get_sample_sum(),
);
const NANOS_PER_SEC: f64 = 1_000_000_000.0;
info!(
"Accumulative per transaction: VM time: {:.0} ns, executor time: {:.0} ns, commit time: {:.0} ns, DB commit time: {:.0} ns",
APTOS_EXECUTOR_VM_EXECUTE_BLOCK_SECONDS.get_sample_sum() * NANOS_PER_SEC
/ total_versions,
(APTOS_EXECUTOR_EXECUTE_BLOCK_SECONDS.get_sample_sum() - APTOS_EXECUTOR_VM_EXECUTE_BLOCK_SECONDS.get_sample_sum()) * NANOS_PER_SEC
/ total_versions,
APTOS_EXECUTOR_COMMIT_BLOCKS_SECONDS.get_sample_sum() * NANOS_PER_SEC
/ total_versions,
API_LATENCY_SECONDS.get_metric_with_label_values(&["save_transactions", "Ok"]).expect("must exist.").get_sample_sum() * NANOS_PER_SEC
/ total_versions,
);
}