Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Budget DSL in terms of Call and PageTable #739

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ unstable = []
ipv6 = []
cuda = []
erasure = []
parex = []

[dependencies]
rayon = "1.0.0"
Expand Down Expand Up @@ -91,6 +92,9 @@ reqwest = "0.8.6"
influx_db_client = "0.3.4"
dirs = "1.0.2"

[profile.release]
debug = true

[dev-dependencies]
criterion = "0.2"

Expand Down
22 changes: 15 additions & 7 deletions benches/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ extern crate solana;

use bincode::serialize;
use criterion::{Bencher, Criterion};
use rayon::prelude::*;
use solana::bank::*;
use solana::hash::hash;
use solana::mint::Mint;
Expand All @@ -18,20 +17,28 @@ fn bench_process_transaction(bencher: &mut Bencher) {
let bank = Bank::new(&mint);

// Create transactions between unrelated parties.
// page_table requires sequential debits from the same account
let mut version: u64 = 0;
let transactions: Vec<_> = (0..4096)
.into_par_iter()
.into_iter()
.map(|i| {
// Seed the 'from' account.
let rando0 = KeyPair::new();
let tx = Transaction::new(&mint.keypair(), rando0.pubkey(), 10_000, mint.last_id());
let tx = Transaction::new(
&mint.keypair(),
rando0.pubkey(),
10_000,
mint.last_id(),
i as u64,
);
assert!(bank.process_transaction(&tx).is_ok());

// Seed the 'to' account and a cell for its signature.
let last_id = hash(&serialize(&i).unwrap()); // Unique hash
bank.register_entry_id(&last_id);

let rando1 = KeyPair::new();
let tx = Transaction::new(&rando0, rando1.pubkey(), 1, last_id);
let tx = Transaction::new(&rando0, rando1.pubkey(), 1, last_id, version);
assert!(bank.process_transaction(&tx).is_ok());

// Finally, return the transaction to the benchmark.
Expand All @@ -41,9 +48,10 @@ fn bench_process_transaction(bencher: &mut Bencher) {

bencher.iter_with_setup(
|| {
// Since benchmarker runs this multiple times, we need to clear the signatures.
bank.clear_signatures();
transactions.clone()
let mut txs = transactions.clone();
version += 1;
txs.iter_mut().for_each(|tx| tx.call.data.version = version);
txs
},
|transactions| {
let results = bank.process_transactions(transactions);
Expand Down
171 changes: 86 additions & 85 deletions benches/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ extern crate rayon;
extern crate solana;

use criterion::{Bencher, Criterion};
use rayon::prelude::*;
use solana::bank::Bank;
use solana::banking_stage::BankingStage;
use solana::mint::Mint;
use solana::packet::{to_packets_chunked, PacketRecycler};
use solana::packet::{to_packets_chunked, PacketRecycler, NUM_PACKETS};
use solana::record_stage::Signal;
use solana::signature::{KeyPair, KeyPairUtil};
use solana::transaction::Transaction;
Expand Down Expand Up @@ -93,7 +92,7 @@ fn check_txs(batches: usize, receiver: &Receiver<Signal>, ref_tx_count: usize) {
}

fn bench_banking_stage_multi_accounts(bencher: &mut Bencher) {
let tx = 10_000_usize;
let tx = NUM_PACKETS;
let mint_total = 1_000_000_000_000;
let mint = Mint::new(mint_total);
let num_dst_accounts = 8 * 1024;
Expand All @@ -111,6 +110,7 @@ fn bench_banking_stage_multi_accounts(bencher: &mut Bencher) {
dstkeys[i % num_dst_accounts],
i as i64,
mint.last_id(),
0,
)
})
.collect();
Expand All @@ -119,103 +119,104 @@ fn bench_banking_stage_multi_accounts(bencher: &mut Bencher) {
let (signal_sender, signal_receiver) = channel();
let packet_recycler = PacketRecycler::default();

let setup_transactions: Vec<_> = (0..num_src_accounts)
.map(|i| {
Transaction::new(
&mint.keypair(),
srckeys[i].pubkey(),
mint_total / num_src_accounts as i64,
mint.last_id(),
)
})
.collect();

bencher.iter(move || {
let bank = Arc::new(Bank::new(&mint));
let bank = Arc::new(Bank::new(&mint));
(0..num_src_accounts).for_each(|i| {
let t = Transaction::new(
&mint.keypair(),
srckeys[i].pubkey(),
mint_total / num_src_accounts as i64,
mint.last_id(),
i as u64,
);
let tx = bank.process_transaction(&t);
if tx.is_err() {
println!("{:?}", tx);
}
assert!(tx.is_ok());
});

let verified_setup: Vec<_> =
to_packets_chunked(&packet_recycler, &setup_transactions.clone(), tx)
let mut version: u64 = 0;
bencher.iter_with_setup(
|| {
let mut txs = transactions.clone();
txs.iter_mut().for_each(|tx| tx.call.data.version = version);
version += 1;
txs
},
|transactions| {
let verified: Vec<_> = to_packets_chunked(&packet_recycler, &transactions, 192)
.into_iter()
.map(|x| {
let len = (*x).read().unwrap().packets.len();
(x, iter::repeat(1).take(len).collect())
})
.collect();

let verified_setup_len = verified_setup.len();
verified_sender.send(verified_setup).unwrap();
BankingStage::process_packets(&bank, &verified_receiver, &signal_sender, &packet_recycler)
.unwrap();

check_txs(verified_setup_len, &signal_receiver, num_src_accounts);

let verified: Vec<_> = to_packets_chunked(&packet_recycler, &transactions.clone(), 192)
.into_iter()
.map(|x| {
let len = (*x).read().unwrap().packets.len();
(x, iter::repeat(1).take(len).collect())
})
.collect();

let verified_len = verified.len();
verified_sender.send(verified).unwrap();
BankingStage::process_packets(&bank, &verified_receiver, &signal_sender, &packet_recycler)
.unwrap();

check_txs(verified_len, &signal_receiver, tx);
});
let verified_len = verified.len();
verified_sender.send(verified).unwrap();
BankingStage::process_packets(
&bank,
&verified_receiver,
&signal_sender,
&packet_recycler,
).unwrap();

check_txs(verified_len, &signal_receiver, tx);
},
);
}

fn bench_banking_stage_single_from(bencher: &mut Bencher) {
let tx = 10_000_usize;
let mint = Mint::new(1_000_000_000_000);
let mut pubkeys = Vec::new();
let num_keys = 8;
for _ in 0..num_keys {
pubkeys.push(KeyPair::new().pubkey());
}

let transactions: Vec<_> = (0..tx)
.into_par_iter()
.map(|i| {
Transaction::new(
&mint.keypair(),
pubkeys[i % num_keys],
i as i64,
mint.last_id(),
)
})
.collect();

let (verified_sender, verified_receiver) = channel();
let (signal_sender, signal_receiver) = channel();
let packet_recycler = PacketRecycler::default();

bencher.iter(move || {
let bank = Arc::new(Bank::new(&mint));
let verified: Vec<_> = to_packets_chunked(&packet_recycler, &transactions.clone(), tx)
.into_iter()
.map(|x| {
let len = (*x).read().unwrap().packets.len();
(x, iter::repeat(1).take(len).collect())
})
.collect();
let verified_len = verified.len();
verified_sender.send(verified).unwrap();
BankingStage::process_packets(&bank, &verified_receiver, &signal_sender, &packet_recycler)
.unwrap();

check_txs(verified_len, &signal_receiver, tx);
});
}
//fn bench_banking_stage_single_from(bencher: &mut Bencher) {
// let tx = 10_000_usize;
// let mint = Mint::new(1_000_000_000_000);
// let mut pubkeys = Vec::new();
// let num_keys = 8;
// for _ in 0..num_keys {
// pubkeys.push(KeyPair::new().pubkey());
// }
//
// let transactions: Vec<_> = (0..tx)
// .into_par_iter()
// .map(|i| {
// Transaction::new(
// &mint.keypair(),
// pubkeys[i % num_keys],
// i as i64,
// mint.last_id(),
// i as u64,
// )
// })
// .collect();
//
// let (verified_sender, verified_receiver) = channel();
// let (signal_sender, signal_receiver) = channel();
// let packet_recycler = PacketRecycler::default();
//
// bencher.iter(move || {
// let bank = Arc::new(Bank::new(&mint));
// let verified: Vec<_> = to_packets_chunked(&packet_recycler, &transactions.clone(), tx)
// .into_iter()
// .map(|x| {
// let len = (*x).read().unwrap().packets.len();
// (x, iter::repeat(1).take(len).collect())
// })
// .collect();
// let verified_len = verified.len();
// verified_sender.send(verified).unwrap();
// BankingStage::process_packets(&bank, &verified_receiver, &signal_sender, &packet_recycler)
// .unwrap();
//
// check_txs(verified_len, &signal_receiver, tx);
// });
//}

fn bench(criterion: &mut Criterion) {
criterion.bench_function("bench_banking_stage_multi_accounts", |bencher| {
bench_banking_stage_multi_accounts(bencher);
});
criterion.bench_function("bench_process_stage_single_from", |bencher| {
bench_banking_stage_single_from(bencher);
});
//criterion.bench_function("bench_process_stage_single_from", |bencher| {
// bench_banking_stage_single_from(bencher);
//});
}

criterion_group!(
Expand Down
2 changes: 1 addition & 1 deletion benches/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn bench_block_to_blobs_to_block(bencher: &mut Bencher) {
let zero = Hash::default();
let one = hash(&zero.as_ref());
let keypair = KeyPair::new();
let tx0 = Transaction::new(&keypair, keypair.pubkey(), 1, one);
let tx0 = Transaction::new(&keypair, keypair.pubkey(), 1, one, 0);
let transactions = vec![tx0; 10];
let entries = next_entries(&zero, 1, transactions);

Expand Down
Loading