Skip to content

Commit a9f8087

Browse files
authored
Add vector-picture to benchmark tool, and show io/execution gas split (aptos-labs#10692)
1 parent f287e82 commit a9f8087

File tree

9 files changed

+584
-249
lines changed

9 files changed

+584
-249
lines changed

aptos-move/move-examples/token_objects/ambassador/Move.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
name = 'ambassador'
33
version = '1.0.0'
44

5+
# do not change to "_", concrete address needed for module-publish testing framework
56
[addresses]
6-
ambassador = "_"
7+
ambassador = "0xCAFE"
78

89
[dependencies]
910
AptosFramework = { local = "../../../framework/aptos-framework" }

crates/transaction-generator-lib/src/args.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub enum TransactionTypeArg {
3030
TokenV1FTMintAndStore,
3131
TokenV1FTMintAndTransfer,
3232
TokenV2AmbassadorMint,
33+
VectorPicture30k,
3334
}
3435

3536
impl TransactionTypeArg {
@@ -157,6 +158,11 @@ impl TransactionTypeArg {
157158
num_modules: module_working_set_size,
158159
use_account_pool: sender_use_account_pool,
159160
},
161+
TransactionTypeArg::VectorPicture30k => TransactionType::CallCustomModules {
162+
entry_point: EntryPoints::VectorPicture { length: 30 * 1024 },
163+
num_modules: module_working_set_size,
164+
use_account_pool: sender_use_account_pool,
165+
},
160166
}
161167
}
162168

crates/transaction-generator-lib/src/publishing/module_simple.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@ pub enum EntryPoints {
168168
TokenV1MintAndTransferFT,
169169

170170
TokenV2AmbassadorMint,
171+
172+
InitializeVectorPicture {
173+
length: u64,
174+
},
175+
VectorPicture {
176+
length: u64,
177+
},
171178
}
172179

173180
impl EntryPoints {
@@ -201,6 +208,9 @@ impl EntryPoints {
201208
| EntryPoints::TokenV1MintAndStoreFT
202209
| EntryPoints::TokenV1MintAndTransferFT => "framework_usecases",
203210
EntryPoints::TokenV2AmbassadorMint => "ambassador_token",
211+
EntryPoints::InitializeVectorPicture { .. } | EntryPoints::VectorPicture { .. } => {
212+
"complex"
213+
},
204214
}
205215
}
206216

@@ -234,6 +244,9 @@ impl EntryPoints {
234244
| EntryPoints::TokenV1MintAndStoreFT
235245
| EntryPoints::TokenV1MintAndTransferFT => "token_v1",
236246
EntryPoints::TokenV2AmbassadorMint => "ambassador",
247+
EntryPoints::InitializeVectorPicture { .. } | EntryPoints::VectorPicture { .. } => {
248+
"vector_picture"
249+
},
237250
}
238251
}
239252

@@ -373,6 +386,22 @@ impl EntryPoints {
373386
],
374387
)
375388
},
389+
EntryPoints::InitializeVectorPicture { length } => {
390+
get_payload(module_id, ident_str!("create").to_owned(), vec![
391+
bcs::to_bytes(&length).unwrap(), // length
392+
])
393+
},
394+
EntryPoints::VectorPicture { length } => {
395+
let rng: &mut StdRng = rng.expect("Must provide RNG");
396+
get_payload(module_id, ident_str!("update").to_owned(), vec![
397+
bcs::to_bytes(&other.expect("Must provide other")).unwrap(),
398+
bcs::to_bytes(&0u64).unwrap(), // palette_index
399+
bcs::to_bytes(&rng.gen_range(0u64, length)).unwrap(), // index
400+
bcs::to_bytes(&rng.gen_range(0u8, 255u8)).unwrap(), // color R
401+
bcs::to_bytes(&rng.gen_range(0u8, 255u8)).unwrap(), // color G
402+
bcs::to_bytes(&rng.gen_range(0u8, 255u8)).unwrap(), // color B
403+
])
404+
},
376405
}
377406
}
378407

@@ -386,6 +415,9 @@ impl EntryPoints {
386415
| EntryPoints::TokenV1MintAndTransferFT => {
387416
Some(EntryPoints::TokenV1InitializeCollection)
388417
},
418+
EntryPoints::VectorPicture { length } => {
419+
Some(EntryPoints::InitializeVectorPicture { length: *length })
420+
},
389421
_ => None,
390422
}
391423
}

crates/transaction-generator-lib/src/publishing/raw_module_data.rs

Lines changed: 291 additions & 175 deletions
Large diffs are not rendered by default.

execution/executor-benchmark/src/lib.rs

Lines changed: 59 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::{
1919
db_access::DbAccessUtil, pipeline::Pipeline, transaction_committer::TransactionCommitter,
2020
transaction_executor::TransactionExecutor, transaction_generator::TransactionGenerator,
2121
};
22-
use aptos_block_executor::counters as block_executor_counters;
22+
use aptos_block_executor::counters::{self as block_executor_counters, GasType};
2323
use aptos_block_partitioner::v2::counters::BLOCK_PARTITIONING_SECONDS;
2424
use aptos_config::config::{NodeConfig, PrunerConfig};
2525
use aptos_db::AptosDB;
@@ -191,7 +191,7 @@ pub fn run_benchmark<V>(
191191
);
192192

193193
let mut start_time = Instant::now();
194-
let start_gas_measurement = GasMesurement::start();
194+
let start_gas_measurement = GasMeasuring::start();
195195

196196
let start_partitioning_total = BLOCK_PARTITIONING_SECONDS.get_sample_sum();
197197
let start_execution_total = APTOS_EXECUTOR_EXECUTE_BLOCK_SECONDS.get_sample_sum();
@@ -248,7 +248,7 @@ pub fn run_benchmark<V>(
248248

249249
let elapsed = start_time.elapsed().as_secs_f64();
250250
let delta_v = (db.reader.get_latest_version().unwrap() - version) as f64;
251-
let (delta_gas, delta_gas_count) = start_gas_measurement.end();
251+
let delta_gas = start_gas_measurement.end();
252252

253253
let delta_vm_time = APTOS_EXECUTOR_VM_EXECUTE_BLOCK_SECONDS.get_sample_sum() - start_vm_time;
254254
info!(
@@ -266,10 +266,15 @@ pub fn run_benchmark<V>(
266266
}
267267
);
268268
info!("Overall TPS: {} txn/s", delta_v / elapsed);
269-
info!("Overall GPS: {} gas/s", delta_gas / elapsed);
269+
info!("Overall GPS: {} gas/s", delta_gas.gas / elapsed);
270+
info!("Overall ioGPS: {} gas/s", delta_gas.io_gas / elapsed);
271+
info!(
272+
"Overall executionGPS: {} gas/s",
273+
delta_gas.execution_gas / elapsed
274+
);
270275
info!(
271276
"Overall GPT: {} gas/txn",
272-
delta_gas / (delta_gas_count as f64).max(1.0)
277+
delta_gas.gas / (delta_gas.gas_count as f64).max(1.0)
273278
);
274279

275280
let time_in_partitioning =
@@ -494,46 +499,66 @@ fn add_accounts_impl<V>(
494499
);
495500
}
496501

497-
struct GasMesurement {
498-
start_gas: f64,
499-
start_gas_count: u64,
502+
struct GasMeasurement {
503+
pub gas: f64,
504+
505+
pub io_gas: f64,
506+
pub execution_gas: f64,
507+
508+
pub gas_count: u64,
500509
}
501510

502-
impl GasMesurement {
503-
pub fn sequential_gas_counter() -> Histogram {
504-
block_executor_counters::TXN_GAS.with_label_values(&[
505-
block_executor_counters::Mode::SEQUENTIAL,
506-
block_executor_counters::GasType::NON_STORAGE_GAS,
507-
])
511+
impl GasMeasurement {
512+
pub fn sequential_gas_counter(gas_type: &str) -> Histogram {
513+
block_executor_counters::TXN_GAS
514+
.with_label_values(&[block_executor_counters::Mode::SEQUENTIAL, gas_type])
508515
}
509516

510-
pub fn parallel_gas_counter() -> Histogram {
511-
block_executor_counters::TXN_GAS.with_label_values(&[
512-
block_executor_counters::Mode::PARALLEL,
513-
block_executor_counters::GasType::NON_STORAGE_GAS,
514-
])
517+
pub fn parallel_gas_counter(gas_type: &str) -> Histogram {
518+
block_executor_counters::TXN_GAS
519+
.with_label_values(&[block_executor_counters::Mode::PARALLEL, gas_type])
515520
}
516521

517-
pub fn start() -> Self {
518-
let start_gas = Self::sequential_gas_counter().get_sample_sum()
519-
+ Self::parallel_gas_counter().get_sample_sum();
520-
let start_gas_count = Self::sequential_gas_counter().get_sample_count()
521-
+ Self::parallel_gas_counter().get_sample_count();
522+
pub fn now() -> GasMeasurement {
523+
let gas = Self::sequential_gas_counter(GasType::NON_STORAGE_GAS).get_sample_sum()
524+
+ Self::parallel_gas_counter(GasType::NON_STORAGE_GAS).get_sample_sum();
525+
let io_gas = Self::sequential_gas_counter(GasType::IO_GAS).get_sample_sum()
526+
+ Self::parallel_gas_counter(GasType::IO_GAS).get_sample_sum();
527+
let execution_gas = Self::sequential_gas_counter(GasType::EXECUTION_GAS).get_sample_sum()
528+
+ Self::parallel_gas_counter(GasType::EXECUTION_GAS).get_sample_sum();
529+
530+
let gas_count = Self::sequential_gas_counter(GasType::NON_STORAGE_GAS).get_sample_count()
531+
+ Self::parallel_gas_counter(GasType::NON_STORAGE_GAS).get_sample_count();
532+
533+
Self {
534+
gas,
535+
io_gas,
536+
execution_gas,
537+
gas_count,
538+
}
539+
}
540+
}
541+
542+
struct GasMeasuring {
543+
start: GasMeasurement,
544+
}
522545

546+
impl GasMeasuring {
547+
pub fn start() -> Self {
523548
Self {
524-
start_gas,
525-
start_gas_count,
549+
start: GasMeasurement::now(),
526550
}
527551
}
528552

529-
pub fn end(self) -> (f64, u64) {
530-
let delta_gas = (Self::sequential_gas_counter().get_sample_sum()
531-
+ Self::parallel_gas_counter().get_sample_sum())
532-
- self.start_gas;
533-
let delta_gas_count = (Self::sequential_gas_counter().get_sample_count()
534-
+ Self::parallel_gas_counter().get_sample_count())
535-
- self.start_gas_count;
536-
(delta_gas, delta_gas_count)
553+
pub fn end(self) -> GasMeasurement {
554+
let end = GasMeasurement::now();
555+
556+
GasMeasurement {
557+
gas: end.gas - self.start.gas,
558+
io_gas: end.io_gas - self.start.io_gas,
559+
execution_gas: end.execution_gas - self.start.execution_gas,
560+
gas_count: end.gas_count - self.start.gas_count,
561+
}
537562
}
538563
}
539564

execution/executor-benchmark/src/pipeline.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use crate::{
55
block_preparation::BlockPreparationStage, ledger_update_stage::LedgerUpdateStage,
6-
metrics::NUM_TXNS, GasMesurement, TransactionCommitter, TransactionExecutor,
6+
metrics::NUM_TXNS, GasMeasuring, TransactionCommitter, TransactionExecutor,
77
};
88
use aptos_block_partitioner::v2::config::PartitionerV2Config;
99
use aptos_crypto::HashValue;
@@ -143,7 +143,7 @@ where
143143
start_execution_rx.map(|rx| rx.recv());
144144
let start_time = Instant::now();
145145
let mut executed = 0;
146-
let start_gas_measurement = GasMesurement::start();
146+
let start_gas_measurement = GasMeasuring::start();
147147
while let Ok(msg) = executable_block_receiver.recv() {
148148
let ExecuteBlockMessage {
149149
current_block_start_time,
@@ -160,7 +160,7 @@ where
160160
info!("Finished executing block");
161161
}
162162

163-
let (delta_gas, delta_gas_count) = start_gas_measurement.end();
163+
let delta_gas = start_gas_measurement.end();
164164

165165
let elapsed = start_time.elapsed().as_secs_f64();
166166
info!(
@@ -171,12 +171,22 @@ where
171171
);
172172
info!(
173173
"Overall execution GPS: {} gas/s (over {} txns)",
174-
delta_gas / elapsed,
174+
delta_gas.gas / elapsed,
175+
executed
176+
);
177+
info!(
178+
"Overall execution ioGPS: {} gas/s (over {} txns)",
179+
delta_gas.io_gas / elapsed,
180+
executed
181+
);
182+
info!(
183+
"Overall execution executionGPS: {} gas/s (over {} txns)",
184+
delta_gas.execution_gas / elapsed,
175185
executed
176186
);
177187
info!(
178188
"Overall execution GPT: {} gas/txn (over {} txns)",
179-
delta_gas / (delta_gas_count as f64).max(1.0),
189+
delta_gas.gas / (delta_gas.gas_count as f64).max(1.0),
180190
executed
181191
);
182192

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = 'complex'
3+
version = '1.0.0'
4+
5+
[dependencies]
6+
AptosFramework = { local = "../../../../../aptos-move/framework/aptos-framework" }
7+
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Copyright Aptos Foundation
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
module 0xABCD::vector_picture {
5+
use std::error;
6+
use std::signer;
7+
use std::vector;
8+
use aptos_std::object::{Self, Object};
9+
10+
/// The caller tried to mutate an item outside the bounds of the vector.
11+
const E_INDEX_OUT_OF_BOUNDS: u64 = 1;
12+
13+
/// The caller tried to create palette for non-initialized account.
14+
const E_ALL_PALETTES_NOT_INIT: u64 = 2;
15+
16+
struct AllPalettes has key {
17+
all: vector<address>,
18+
}
19+
20+
#[resource_group_member(group = aptos_framework::object::ObjectGroup)]
21+
struct Palette has key {
22+
vec: vector<Color>,
23+
}
24+
25+
struct Color has copy, drop, store {
26+
r: u8,
27+
g: u8,
28+
b: u8,
29+
}
30+
31+
fun init_module(publisher: &signer) {
32+
move_to<AllPalettes>(
33+
publisher,
34+
AllPalettes {
35+
all: vector::empty(),
36+
},
37+
);
38+
}
39+
40+
/// Create a new Palette
41+
public entry fun create(
42+
caller: &signer,
43+
// Length of the vector to create.
44+
length: u64,
45+
) acquires AllPalettes {
46+
let caller_addr = signer::address_of(caller);
47+
48+
// Just a dummy color.
49+
let color = Color {
50+
r: 124,
51+
g: 213,
52+
b: 37,
53+
};
54+
55+
// Build vec and palette.
56+
let vec = vector::empty();
57+
let i = 0;
58+
while (i < length) {
59+
vector::push_back(&mut vec, color);
60+
i = i + 1;
61+
};
62+
let palette = Palette { vec };
63+
64+
// Create the object we'll store the Palette in.
65+
let constructor_ref = object::create_object(caller_addr);
66+
67+
// Move the Palette resource into the object.
68+
let object_signer = object::generate_signer(&constructor_ref);
69+
move_to(&object_signer, palette);
70+
71+
assert!(exists<AllPalettes>(caller_addr), error::invalid_argument(E_ALL_PALETTES_NOT_INIT));
72+
73+
let all_palettes = borrow_global_mut<AllPalettes>(caller_addr);
74+
vector::push_back(&mut all_palettes.all, object::address_from_constructor_ref(&constructor_ref));
75+
}
76+
77+
/// Update an element in the vector.
78+
public entry fun update(
79+
palette_addr: address,
80+
palette_index: u64,
81+
index: u64,
82+
r: u8,
83+
g: u8,
84+
b: u8,
85+
) acquires Palette, AllPalettes {
86+
let all_palettes = borrow_global<AllPalettes>(palette_addr);
87+
let palette_addr = vector::borrow(&all_palettes.all, palette_index);
88+
89+
let palette_ = borrow_global_mut<Palette>(*palette_addr);
90+
91+
// Confirm the index is not out of bounds.
92+
assert!(index < vector::length(&palette_.vec), error::invalid_argument(E_INDEX_OUT_OF_BOUNDS));
93+
94+
// Write the pixel.
95+
let color = Color { r, g, b };
96+
*vector::borrow_mut(&mut palette_.vec, index) = color;
97+
}
98+
}

0 commit comments

Comments
 (0)