2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#![feature(test)]
							 | 
						
					
						
							
								
									
										
										
										
											2018-12-08 22:44:20 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use rand;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								extern crate test;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-26 17:11:26 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#[macro_use]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								extern crate solana;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-12-05 14:12:10 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use rand::seq::SliceRandom;
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								use rand::{thread_rng, Rng};
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 20:52:39 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use solana::blocktree::{get_tmp_ledger_path, Blocktree};
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-09 14:33:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use solana::entry::{make_large_test_entries, make_tiny_test_entries, EntrySlice};
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								use solana::packet::{Blob, BLOB_HEADER_SIZE};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								use test::Bencher;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// Given some blobs and a ledger at ledger_path, benchmark writing the blobs to the ledger
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-08 15:53:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								fn bench_write_blobs(bench: &mut Bencher, blobs: &mut Vec<Blob>, ledger_path: &str) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 20:52:39 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let blocktree =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Blocktree::open(&ledger_path).expect("Expected to be able to open database ledger");
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-08 15:53:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let num_blobs = blobs.len();
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-08 15:53:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bench.iter(move || {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        for blob in blobs.iter_mut() {
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-30 20:18:28 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            let index = blob.index();
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-08 15:53:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 20:52:39 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            blocktree
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-08 15:53:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                .put_data_blob_bytes(
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-30 20:18:28 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    blob.slot(),
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-08 15:53:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    index,
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-30 20:18:28 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    &blob.data[..BLOB_HEADER_SIZE + blob.size()],
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-08 15:53:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                )
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                .unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-08 15:53:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-30 20:18:28 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            blob.set_index(index + num_blobs as u64);
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 20:52:39 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    Blocktree::destroy(&ledger_path).expect("Expected successful database destruction");
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// Insert some blobs into the ledger in preparation for read benchmarks
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn setup_read_bench(
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 20:52:39 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    blocktree: &mut Blocktree,
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    num_small_blobs: u64,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    num_large_blobs: u64,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    slot: u64,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Make some big and small entries
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let mut entries = make_large_test_entries(num_large_blobs as usize);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    entries.extend(make_tiny_test_entries(num_small_blobs as usize));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-12-14 17:05:41 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // Convert the entries to blobs, write the blobs to the ledger
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-08 15:53:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut blobs = entries.to_blobs();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for (index, b) in blobs.iter_mut().enumerate() {
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-30 20:18:28 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        b.set_index(index as u64);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        b.set_slot(slot);
							 | 
						
					
						
							
								
									
										
										
										
											2018-12-14 17:05:41 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 20:52:39 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    blocktree
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-08 15:53:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        .write_blobs(&blobs)
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .expect("Expectd successful insertion of blobs into ledger");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// Write small blobs to the ledger
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[bench]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[ignore]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn bench_write_small(bench: &mut Bencher) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-26 17:11:26 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let ledger_path = get_tmp_ledger_path!();
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let num_entries = 32 * 1024;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let entries = make_tiny_test_entries(num_entries);
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-08 15:53:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut blobs = entries.to_blobs();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for (index, b) in blobs.iter_mut().enumerate() {
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-30 20:18:28 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        b.set_index(index as u64);
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-08 15:53:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bench_write_blobs(bench, &mut blobs, &ledger_path);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// Write big blobs to the ledger
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[bench]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[ignore]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn bench_write_big(bench: &mut Bencher) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-26 17:11:26 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let ledger_path = get_tmp_ledger_path!();
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let num_entries = 32 * 1024;
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-08 15:53:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let entries = make_large_test_entries(num_entries);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let mut blobs = entries.to_blobs();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for (index, b) in blobs.iter_mut().enumerate() {
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-30 20:18:28 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        b.set_index(index as u64);
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-08 15:53:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bench_write_blobs(bench, &mut blobs, &ledger_path);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[bench]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[ignore]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn bench_read_sequential(bench: &mut Bencher) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-26 17:11:26 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let ledger_path = get_tmp_ledger_path!();
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 20:52:39 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut blocktree =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Blocktree::open(&ledger_path).expect("Expected to be able to open database ledger");
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Insert some big and small blobs into the ledger
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let num_small_blobs = 32 * 1024;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let num_large_blobs = 32 * 1024;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let total_blobs = num_small_blobs + num_large_blobs;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let slot = 0;
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 20:52:39 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    setup_read_bench(&mut blocktree, num_small_blobs, num_large_blobs, slot);
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let num_reads = total_blobs / 15;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let mut rng = rand::thread_rng();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bench.iter(move || {
							 | 
						
					
						
							
								
									
										
										
										
											2018-12-05 14:12:10 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        // Generate random starting point in the range [0, total_blobs - 1], read num_reads blobs sequentially
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        let start_index = rng.gen_range(0, num_small_blobs + num_large_blobs);
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        for i in start_index..start_index + num_reads {
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 20:52:39 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            let _ = blocktree.get_data_blob(slot, i as u64 % total_blobs);
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 20:52:39 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    Blocktree::destroy(&ledger_path).expect("Expected successful database destruction");
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[bench]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[ignore]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn bench_read_random(bench: &mut Bencher) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-26 17:11:26 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let ledger_path = get_tmp_ledger_path!();
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 20:52:39 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut blocktree =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Blocktree::open(&ledger_path).expect("Expected to be able to open database ledger");
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Insert some big and small blobs into the ledger
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let num_small_blobs = 32 * 1024;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let num_large_blobs = 32 * 1024;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let total_blobs = num_small_blobs + num_large_blobs;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let slot = 0;
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 20:52:39 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    setup_read_bench(&mut blocktree, num_small_blobs, num_large_blobs, slot);
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let num_reads = total_blobs / 15;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // Generate a num_reads sized random sample of indexes in range [0, total_blobs - 1],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    // simulating random reads
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let mut rng = rand::thread_rng();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let indexes: Vec<usize> = (0..num_reads)
							 | 
						
					
						
							
								
									
										
										
										
											2018-12-05 14:12:10 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        .map(|_| rng.gen_range(0, total_blobs) as usize)
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        .collect();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bench.iter(move || {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        for i in indexes.iter() {
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 20:52:39 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            let _ = blocktree.get_data_blob(slot, *i as u64);
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 20:52:39 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    Blocktree::destroy(&ledger_path).expect("Expected successful database destruction");
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[bench]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[ignore]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn bench_insert_data_blob_small(bench: &mut Bencher) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-26 17:11:26 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let ledger_path = get_tmp_ledger_path!();
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 20:52:39 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let blocktree =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Blocktree::open(&ledger_path).expect("Expected to be able to open database ledger");
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let num_entries = 32 * 1024;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let entries = make_tiny_test_entries(num_entries);
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-08 15:53:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut blobs = entries.to_blobs();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    blobs.shuffle(&mut thread_rng());
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bench.iter(move || {
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-08 15:53:44 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        for blob in blobs.iter_mut() {
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-30 20:18:28 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            let index = blob.index();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            blob.set_index(index + num_entries as u64);
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 20:52:39 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        blocktree.write_blobs(&blobs).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 20:52:39 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    Blocktree::destroy(&ledger_path).expect("Expected successful database destruction");
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[bench]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#[ignore]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fn bench_insert_data_blob_big(bench: &mut Bencher) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-26 17:11:26 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let ledger_path = get_tmp_ledger_path!();
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 20:52:39 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let blocktree =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        Blocktree::open(&ledger_path).expect("Expected to be able to open database ledger");
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let num_entries = 32 * 1024;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let entries = make_large_test_entries(num_entries);
							 | 
						
					
						
							
								
									
										
										
										
											2018-12-22 19:30:30 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let mut shared_blobs = entries.to_shared_blobs();
							 | 
						
					
						
							
								
									
										
										
										
											2018-12-19 16:11:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    shared_blobs.shuffle(&mut thread_rng());
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    bench.iter(move || {
							 | 
						
					
						
							
								
									
										
										
										
											2018-12-19 16:11:47 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        for blob in shared_blobs.iter_mut() {
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-30 20:18:28 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            let index = blob.read().unwrap().index();
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 20:52:39 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            blocktree.write_shared_blobs(vec![blob.clone()]).unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2019-01-30 20:18:28 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            blob.write().unwrap().set_index(index + num_entries as u64);
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 20:52:39 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    Blocktree::destroy(&ledger_path).expect("Expected successful database destruction");
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-23 06:12:43 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |