message: [safety-rules] Benchmark for vault
  Shows that vault has issues on high demand...
  Closes:
  Approved by: aching
diff: use consensus_types::block::block_test_utils;
  use criterion::{black_box, criterion_group, criterion_main, Criterion};
  use libra_crypto::{ed25519::Ed25519PrivateKey, Uniform};
  -use libra_secure_storage::{InMemoryStorage, OnDiskStorage, Storage};
  +use libra_secure_storage::{InMemoryStorage, KVStorage, OnDiskStorage, Storage, VaultStorage};
  use libra_types::validator_signer::ValidatorSigner;
  -use safety_rules::{
  - test_utils, PersistentSafetyStorage,
  - SafetyRulesManager, TSafetyRules,
  -};
  +use safety_rules::{test_utils, PersistentSafetyStorage, SafetyRulesManager, TSafetyRules};
  use tempfile::NamedTempFile;
  +const VAULT_HOST: &str = "http://localhost:8200";
  +const VAULT_TOKEN: &str = "root_token";
  +
  /// Execute an in order series of blocks (0 <- 1 <- 2 <- 3 and commit 0 and continue to rotate
  /// left, appending new blocks on the right, committing the left most block
  fn lsr(mut safety_rules: Box<dyn TSafetyRules>, signer: ValidatorSigner, n: u64) {
  @@ -114,14 +114,54 @@ fn thread(n: u64) {
  lsr(safety_rules_manager.client(), signer, n);
  }
  +fn vault(n: u64) {
  + let signer = ValidatorSigner::from_int(0);
  + let waypoint = test_utils::validator_signers_to_waypoint(&[&signer]);
  +
  + let mut storage =
  + VaultStorage::new(VAULT_HOST.to_string(), VAULT_TOKEN.to_string(), None, None);
  + storage.reset_and_clear().unwrap();
  +
  + let storage = PersistentSafetyStorage::initialize(
  + Storage::from(storage),
  + signer.author(),
  + signer.private_key().clone(),
  + Ed25519PrivateKey::generate_for_testing(),
  + waypoint,
  + );
  + let safety_rules_manager = SafetyRulesManager::new_thread(storage, false);
  + lsr(safety_rules_manager.client(), signer, n);
  +}
  +
  pub fn benchmark(c: &mut Criterion) {
  let count = 100;
  + let duration_secs = 5;
  + let samples = 10;
  +
  + let storage = VaultStorage::new(VAULT_HOST.to_string(), VAULT_TOKEN.to_string(), None, None);
  +
  + let enable_vault = if storage.available().is_err() {
  + println!(
  + "Vault ({}) is not availble, experiment will not be launched",
  + VAULT_HOST
  + );
  + false
  + } else {
  + true
  + };
  +
  let mut group = c.benchmark_group("SafetyRules");
  - group.measurement_time(std::time::Duration::from_secs(5)).sample_size(10);
  + group
  + .measurement_time(std::time::Duration::from_secs(duration_secs))
  + .sample_size(samples);
  group.bench_function("InMemory", |b| b.iter(|| in_memory(black_box(count))));
  group.bench_function("OnDisk", |b| b.iter(|| on_disk(black_box(count))));
  group.bench_function("Serializer", |b| b.iter(|| serializer(black_box(count))));
  group.bench_function("Thread", |b| b.iter(|| thread(black_box(count))));
  +
  + if enable_vault {
  + group.bench_function("Vault", |b| b.iter(|| vault(black_box(count))));
  + }
  }
  criterion_group!(benches, benchmark);
  