Skip to content

Commit

Permalink
Outline of scalable key value store interface (#13083)
Browse files Browse the repository at this point in the history
  • Loading branch information
mystenmark authored Jul 21, 2023
1 parent 0666bb0 commit 86549f8
Show file tree
Hide file tree
Showing 6 changed files with 474 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 89 additions & 0 deletions crates/sui-core/src/authority/authority_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::ops::Not;
use std::sync::Arc;
use std::{iter, mem, thread};

use async_trait::async_trait;
use either::Either;
use fastcrypto::hash::{HashFunction, MultisetHash, Sha3_256};
use futures::stream::FuturesUnordered;
Expand Down Expand Up @@ -42,6 +43,7 @@ use crate::authority::epoch_start_configuration::{EpochFlag, EpochStartConfigura
use super::authority_store_tables::LiveObject;
use super::{authority_store_tables::AuthorityPerpetualTables, *};
use mysten_common::sync::notify_read::NotifyRead;
use sui_storage::key_value_store;
use sui_storage::package_object_cache::PackageObjectCache;
use sui_types::effects::{TransactionEffects, TransactionEvents};
use sui_types::gas_coin::TOTAL_SUPPLY_MIST;
Expand Down Expand Up @@ -1932,6 +1934,93 @@ impl GetModule for AuthorityStore {
}
}

#[async_trait]
impl key_value_store::TransactionKeyValueStore for AuthorityStore {
/// Generic multi_get, allows implementors to get heterogenous values with a single round trip.
async fn multi_get(
&self,
keys: &[key_value_store::Key],
) -> SuiResult<Vec<Option<key_value_store::Value>>> {
let mut tx_keys = Vec::new();
let mut fx_keys = Vec::new();
let mut events_keys = Vec::new();

for key in keys {
match key {
key_value_store::Key::Tx(digest) => tx_keys.push(*digest),
key_value_store::Key::Fx(digest) => fx_keys.push(*digest),
key_value_store::Key::Events(digest) => events_keys.push(*digest),
}
}

let tx_results = if !tx_keys.is_empty() {
self.multi_get_tx(&tx_keys).await?
} else {
Vec::new()
};

let fx_results = if !fx_keys.is_empty() {
self.multi_get_fx(&fx_keys).await?
} else {
Vec::new()
};

let events_results = if !events_keys.is_empty() {
key_value_store::TransactionKeyValueStore::multi_get_events(self, &events_keys).await?
} else {
Vec::new()
};

// re-assemble original order
let mut tx_iter = tx_results.into_iter();
let mut fx_iter = fx_results.into_iter();
let mut events_iter = events_results.into_iter();

let mut results = Vec::new();

for key in keys {
match key {
key_value_store::Key::Tx(_) => {
results.push(tx_iter.next().unwrap().map(|tx| tx.into()))
}
key_value_store::Key::Fx(_) => {
results.push(fx_iter.next().unwrap().map(|fx| fx.into()))
}
key_value_store::Key::Events(_) => {
results.push(events_iter.next().unwrap().map(|e| e.into()))
}
}
}

Ok(results)
}

async fn multi_get_tx(
&self,
keys: &[TransactionDigest],
) -> SuiResult<Vec<Option<Transaction>>> {
Ok(self
.multi_get_transaction_blocks(keys)?
.into_iter()
.map(|t| t.map(|t| t.into_inner()))
.collect())
}

async fn multi_get_fx(
&self,
keys: &[TransactionEffectsDigest],
) -> SuiResult<Vec<Option<TransactionEffects>>> {
Ok(self.multi_get_effects(keys.iter())?)
}

async fn multi_get_events(
&self,
keys: &[TransactionEventsDigest],
) -> SuiResult<Vec<Option<TransactionEvents>>> {
Ok(self.multi_get_events(keys)?)
}
}

/// A wrapper to make Orphan Rule happy
pub struct ResolverWrapper<T: ModuleResolver> {
pub resolver: Arc<T>,
Expand Down
2 changes: 2 additions & 0 deletions crates/sui-storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ tempfile.workspace = true
num_cpus.workspace = true
pretty_assertions.workspace = true
once_cell.workspace = true
sui-test-transaction-builder.workspace = true
sui-types = { workspace = true, features = ["test-utils"] }
Loading

1 comment on commit 86549f8

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 Validators 500/s Owned Transactions Benchmark Results

Benchmark Report:
+-------------+-----+-----+--------+---------------+---------------+---------------+-----------------------+----------------------------+
| duration(s) | tps | cps | error% | latency (min) | latency (p50) | latency (p99) | gas used (MIST total) | gas used/hr (MIST approx.) |
+=======================================================================================================================================+
| 60          | 597 | 597 | 0      | 20            | 8255          | 8583          | 466,226,112,000       | 27,973,566,720,000         |
Stress Performance Report:
+-----------+-----+-----+
| metric    | p50 | p99 |
+=======================+
| cpu usage | 12  | 100 |

4 Validators 500/s Shared Transactions Benchmark Results

Benchmark Report:
+-------------+-----+-----+--------+---------------+---------------+---------------+-----------------------+----------------------------+
| duration(s) | tps | cps | error% | latency (min) | latency (p50) | latency (p99) | gas used (MIST total) | gas used/hr (MIST approx.) |
+=======================================================================================================================================+
| 60          | 490 | 490 | 0      | 21            | 9311          | 13215         | 454,799,024,400       | 27,287,941,464,000         |
Stress Performance Report:
+-----------+-----+-----+
| metric    | p50 | p99 |
+=======================+
| cpu usage | 12  | 100 |

20 Validators 50/s Owned Transactions Benchmark Results

Benchmark Report:
+-------------+-----+-----+--------+---------------+---------------+---------------+-----------------------+----------------------------+
| duration(s) | tps | cps | error% | latency (min) | latency (p50) | latency (p99) | gas used (MIST total) | gas used/hr (MIST approx.) |
+=======================================================================================================================================+
| 60          | 200 | 200 | 0      | 21            | 65            | 91            | 145,300,224,000       | 8,718,013,440,000          |
Stress Performance Report:
+-----------+-----+-----+
| metric    | p50 | p99 |
+=======================+
| cpu usage | 27  | 51  |

20 Validators 50/s Shared Transactions Benchmark Results

Benchmark Report:
+-------------+-----+-----+--------+---------------+---------------+---------------+-----------------------+----------------------------+
| duration(s) | tps | cps | error% | latency (min) | latency (p50) | latency (p99) | gas used (MIST total) | gas used/hr (MIST approx.) |
+=======================================================================================================================================+
| 60          | 194 | 194 | 0      | 67            | 1398          | 2069          | 180,334,257,600       | 10,820,055,456,000         |
Stress Performance Report:
+-----------+-----+-----+
| metric    | p50 | p99 |
+=======================+
| cpu usage | 25  | 57  |

Narwhal Benchmark Results

 SUMMARY:
-----------------------------------------
 + CONFIG:
 Faults: 0 node(s)
 Committee size: 4 node(s)
 Worker(s) per node: 1 worker(s)
 Collocate primary and workers: True
 Input rate: 50,000 tx/s
 Transaction size: 512 B
 Execution time: 0 s

 Header number of batches threshold: 32 digests
 Header maximum number of batches: 1,000 digests
 Max header delay: 2,000 ms
 GC depth: 50 round(s)
 Sync retry delay: 10,000 ms
 Sync retry nodes: 3 node(s)
 batch size: 500,000 B
 Max batch delay: 200 ms
 Max concurrent requests: 500,000 

 + RESULTS:
 Batch creation avg latency: 202 ms
 Header creation avg latency: -1 ms
 	Batch to header avg latency: -1 ms
 Header to certificate avg latency: 1 ms
 	Request vote outbound avg latency: 0 ms
 Certificate commit avg latency: 705 ms

 Consensus TPS: 0 tx/s
 Consensus BPS: 0 B/s
 Consensus latency: 0 ms

 End-to-end TPS: 0 tx/s
 End-to-end BPS: 0 B/s
 End-to-end latency: 0 ms
-----------------------------------------

Please sign in to comment.