Skip to content

Commit 985f06b

Browse files
Implement the caching of the find_{keys,key_value}_by_prefix operations. (#4576)
## Motivation The `find_keys_by_prefix` has emerged as a choke point for some benchmarks. Considering that it is the only part that is not cached, it is interesting to consider this. ## Proposal The implementation is done in the following way: * The `find_{keys,key_values}_by_prefix` are cached. * The `delete_prefix` leads to a `find_key_values_by_prefix` entry in the cache. * All the information about the operation is used to avoid making some calls to the storage. ## Test Plan The CI. Some unit tests have been added to the `lru_caching.rs` file. ## Release Plan The input file would change because some additional entries have been added. However, this can still be ported to existing DevNet / TestNet. ## Links None.
1 parent 047f390 commit 985f06b

File tree

13 files changed

+2895
-237
lines changed

13 files changed

+2895
-237
lines changed

CLI.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,27 @@ Client implementation and command-line tool for the Linera blockchain
188188
* `--storage-max-cache-size <STORAGE_MAX_CACHE_SIZE>` — The maximal memory used in the storage cache
189189

190190
Default value: `10000000`
191-
* `--storage-max-entry-size <STORAGE_MAX_ENTRY_SIZE>` — The maximal size of an entry in the storage cache
191+
* `--storage-max-value-entry-size <STORAGE_MAX_VALUE_ENTRY_SIZE>` — The maximal size of a value entry in the storage cache
192+
193+
Default value: `1000000`
194+
* `--storage-max-find-keys-entry-size <STORAGE_MAX_FIND_KEYS_ENTRY_SIZE>` — The maximal size of a find-keys entry in the storage cache
195+
196+
Default value: `1000000`
197+
* `--storage-max-find-key-values-entry-size <STORAGE_MAX_FIND_KEY_VALUES_ENTRY_SIZE>` — The maximal size of a find-key-values entry in the storage cache
192198

193199
Default value: `1000000`
194200
* `--storage-max-cache-entries <STORAGE_MAX_CACHE_ENTRIES>` — The maximal number of entries in the storage cache
195201

196202
Default value: `1000`
203+
* `--storage-max-cache-value-size <STORAGE_MAX_CACHE_VALUE_SIZE>` — The maximal memory used in the value cache
204+
205+
Default value: `10000000`
206+
* `--storage-max-cache-find-keys-size <STORAGE_MAX_CACHE_FIND_KEYS_SIZE>` — The maximal memory used in the find_keys_by_prefix cache
207+
208+
Default value: `10000000`
209+
* `--storage-max-cache-find-key-values-size <STORAGE_MAX_CACHE_FIND_KEY_VALUES_SIZE>` — The maximal memory used in the find_key_values_by_prefix cache
210+
211+
Default value: `10000000`
197212
* `--storage-replication-factor <STORAGE_REPLICATION_FACTOR>` — The replication factor for the keyspace
198213

199214
Default value: `1`

linera-indexer/lib/src/rocks_db.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::path::PathBuf;
55

66
use clap::Parser as _;
77
use linera_views::{
8-
lru_caching::StorageCacheConfig,
8+
lru_prefix_cache::StorageCacheConfig,
99
rocks_db::{
1010
PathWithGuard, RocksDbDatabase, RocksDbSpawnMode, RocksDbStoreConfig,
1111
RocksDbStoreInternalConfig,
@@ -36,17 +36,37 @@ pub struct RocksDbConfig {
3636
#[arg(long, default_value = "10")]
3737
pub max_stream_queries: usize,
3838

39-
/// The maximal memory used in the storage cache.
39+
/// The maximal memory used in the storage cache in bytes.
4040
#[arg(long, default_value = "10000000")]
4141
pub max_cache_size: usize,
4242

43-
/// The maximal size of an entry in the storage cache.
43+
/// The maximal size of a value entry in the storage cache in bytes.
4444
#[arg(long, default_value = "1000000")]
45-
pub max_entry_size: usize,
45+
pub max_value_entry_size: usize,
46+
47+
/// The maximal size of a find-keys entry in the storage cache in bytes.
48+
#[arg(long, default_value = "1000000")]
49+
pub max_find_keys_entry_size: usize,
50+
51+
/// The maximal size of a find-key-values entry in the storage cache in bytes.
52+
#[arg(long, default_value = "1000000")]
53+
pub max_find_key_values_entry_size: usize,
4654

4755
/// The maximal number of entries in the storage cache.
4856
#[arg(long, default_value = "1000")]
4957
pub max_cache_entries: usize,
58+
59+
/// The maximal memory used in the value cache in bytes.
60+
#[arg(long, default_value = "10000000")]
61+
pub max_cache_value_size: usize,
62+
63+
/// The maximal memory used in the find_keys_by_prefix cache in bytes.
64+
#[arg(long, default_value = "10000000")]
65+
pub max_cache_find_keys_size: usize,
66+
67+
/// The maximal memory used in the find_key_values_by_prefix cache in bytes.
68+
#[arg(long, default_value = "10000000")]
69+
pub max_cache_find_key_values_size: usize,
5070
}
5171

5272
pub type RocksDbRunner = Runner<RocksDbDatabase, RocksDbConfig>;
@@ -56,8 +76,13 @@ impl RocksDbRunner {
5676
let config = IndexerConfig::<RocksDbConfig>::parse();
5777
let storage_cache_config = StorageCacheConfig {
5878
max_cache_size: config.client.max_cache_size,
59-
max_entry_size: config.client.max_entry_size,
79+
max_value_entry_size: config.client.max_value_entry_size,
80+
max_find_keys_entry_size: config.client.max_find_keys_entry_size,
81+
max_find_key_values_entry_size: config.client.max_find_key_values_entry_size,
6082
max_cache_entries: config.client.max_cache_entries,
83+
max_cache_value_size: config.client.max_cache_value_size,
84+
max_cache_find_keys_size: config.client.max_cache_find_keys_size,
85+
max_cache_find_key_values_size: config.client.max_cache_find_key_values_size,
6186
};
6287
let path_buf = config.client.storage.as_path().to_path_buf();
6388
let path_with_guard = PathWithGuard::new(path_buf);

linera-indexer/lib/src/scylla_db.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use linera_views::{
5-
lru_caching::StorageCacheConfig,
5+
lru_prefix_cache::StorageCacheConfig,
66
scylla_db::{ScyllaDbDatabase, ScyllaDbStoreConfig, ScyllaDbStoreInternalConfig},
77
store::KeyValueDatabase,
88
};
@@ -30,18 +30,38 @@ pub struct ScyllaDbConfig {
3030
#[arg(long, default_value = "10")]
3131
pub max_stream_queries: usize,
3232

33-
/// The maximal memory used in the storage cache.
33+
/// The maximal memory used in the storage cache in bytes.
3434
#[arg(long, default_value = "10000000")]
3535
pub max_cache_size: usize,
3636

37-
/// The maximal size of an entry in the storage cache.
37+
/// The maximal size of a value entry in the storage cache in bytes.
3838
#[arg(long, default_value = "1000000")]
39-
pub max_entry_size: usize,
39+
pub max_value_entry_size: usize,
40+
41+
/// The maximal size of a find-keys entry in the storage cache in bytes.
42+
#[arg(long, default_value = "1000000")]
43+
pub max_find_keys_entry_size: usize,
44+
45+
/// The maximal size of a find-key-values entry in the storage cache in bytes.
46+
#[arg(long, default_value = "1000000")]
47+
pub max_find_key_values_entry_size: usize,
4048

4149
/// The maximal number of entries in the storage cache.
4250
#[arg(long, default_value = "1000")]
4351
pub max_cache_entries: usize,
4452

53+
/// The maximal memory used in the value cache in bytes.
54+
#[arg(long, default_value = "10000000")]
55+
pub max_cache_value_size: usize,
56+
57+
/// The maximal memory used in the find_keys_by_prefix cache in bytes.
58+
#[arg(long, default_value = "10000000")]
59+
pub max_cache_find_keys_size: usize,
60+
61+
/// The maximal memory used in the find_key_values_by_prefix cache in bytes.
62+
#[arg(long, default_value = "10000000")]
63+
pub max_cache_find_key_values_size: usize,
64+
4565
/// The replication factor for the keyspace
4666
#[arg(long, default_value = "1")]
4767
pub replication_factor: u32,
@@ -54,8 +74,13 @@ impl ScyllaDbRunner {
5474
let config = <IndexerConfig<ScyllaDbConfig> as clap::Parser>::parse();
5575
let storage_cache_config = StorageCacheConfig {
5676
max_cache_size: config.client.max_cache_size,
57-
max_entry_size: config.client.max_entry_size,
77+
max_value_entry_size: config.client.max_value_entry_size,
78+
max_find_keys_entry_size: config.client.max_find_keys_entry_size,
79+
max_find_key_values_entry_size: config.client.max_find_key_values_entry_size,
5880
max_cache_entries: config.client.max_cache_entries,
81+
max_cache_value_size: config.client.max_cache_value_size,
82+
max_cache_find_keys_size: config.client.max_cache_find_keys_size,
83+
max_cache_find_key_values_size: config.client.max_cache_find_key_values_size,
5984
};
6085
let inner_config = ScyllaDbStoreInternalConfig {
6186
uri: config.client.uri.clone(),

linera-service/src/storage.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use linera_views::rocks_db::{
2121
RocksDbStoreInternalConfig,
2222
};
2323
use linera_views::{
24-
lru_caching::StorageCacheConfig,
24+
lru_prefix_cache::StorageCacheConfig,
2525
memory::{MemoryDatabase, MemoryStoreConfig},
2626
store::{KeyValueDatabase, KeyValueStore},
2727
};
@@ -54,14 +54,34 @@ pub struct CommonStorageOptions {
5454
#[arg(long, default_value = "10000000", global = true)]
5555
pub storage_max_cache_size: usize,
5656

57-
/// The maximal size of an entry in the storage cache.
57+
/// The maximal size of a value entry in the storage cache.
5858
#[arg(long, default_value = "1000000", global = true)]
59-
pub storage_max_entry_size: usize,
59+
pub storage_max_value_entry_size: usize,
60+
61+
/// The maximal size of a find-keys entry in the storage cache.
62+
#[arg(long, default_value = "1000000", global = true)]
63+
pub storage_max_find_keys_entry_size: usize,
64+
65+
/// The maximal size of a find-key-values entry in the storage cache.
66+
#[arg(long, default_value = "1000000", global = true)]
67+
pub storage_max_find_key_values_entry_size: usize,
6068

6169
/// The maximal number of entries in the storage cache.
6270
#[arg(long, default_value = "1000", global = true)]
6371
pub storage_max_cache_entries: usize,
6472

73+
/// The maximal memory used in the value cache.
74+
#[arg(long, default_value = "10000000", global = true)]
75+
pub storage_max_cache_value_size: usize,
76+
77+
/// The maximal memory used in the find_keys_by_prefix cache.
78+
#[arg(long, default_value = "10000000", global = true)]
79+
pub storage_max_cache_find_keys_size: usize,
80+
81+
/// The maximal memory used in the find_key_values_by_prefix cache.
82+
#[arg(long, default_value = "10000000", global = true)]
83+
pub storage_max_cache_find_key_values_size: usize,
84+
6585
/// The replication factor for the keyspace
6686
#[arg(long, default_value = "1", global = true)]
6787
pub storage_replication_factor: u32,
@@ -71,8 +91,13 @@ impl CommonStorageOptions {
7191
pub fn storage_cache_config(&self) -> StorageCacheConfig {
7292
StorageCacheConfig {
7393
max_cache_size: self.storage_max_cache_size,
74-
max_entry_size: self.storage_max_entry_size,
94+
max_value_entry_size: self.storage_max_value_entry_size,
95+
max_find_keys_entry_size: self.storage_max_find_keys_entry_size,
96+
max_find_key_values_entry_size: self.storage_max_find_key_values_entry_size,
7597
max_cache_entries: self.storage_max_cache_entries,
98+
max_cache_value_size: self.storage_max_cache_value_size,
99+
max_cache_find_keys_size: self.storage_max_cache_find_keys_size,
100+
max_cache_find_key_values_size: self.storage_max_cache_find_key_values_size,
76101
}
77102
}
78103
}

linera-storage-service/src/server.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use linera_views::{
1212
};
1313
#[cfg(with_rocksdb)]
1414
use linera_views::{
15-
lru_caching::StorageCacheConfig,
15+
lru_prefix_cache::StorageCacheConfig,
1616
rocks_db::{
1717
PathWithGuard, RocksDbDatabase, RocksDbSpawnMode, RocksDbStoreConfig,
1818
RocksDbStoreInternalConfig,
@@ -282,12 +282,27 @@ enum StorageServerOptions {
282282
/// The maximum size of the cache, in bytes (keys size + value sizes)
283283
#[arg(long, default_value = "10000000")]
284284
max_cache_size: usize,
285-
/// The maximum size of an entry size, in bytes
285+
/// The maximum size of a value entry, in bytes
286286
#[arg(long, default_value = "1000000")]
287-
max_entry_size: usize,
287+
max_value_entry_size: usize,
288+
/// The maximum size of a find-keys entry, in bytes
289+
#[arg(long, default_value = "1000000")]
290+
max_find_keys_entry_size: usize,
291+
/// The maximum size of a find-key-values entry, in bytes
292+
#[arg(long, default_value = "1000000")]
293+
max_find_key_values_entry_size: usize,
288294
/// The maximum number of entries in the cache.
289295
#[arg(long, default_value = "1000")]
290296
max_cache_entries: usize,
297+
/// The maximum value size of the cache, in bytes
298+
#[arg(long, default_value = "10000000")]
299+
max_cache_value_size: usize,
300+
/// The maximum find_keys_by_prefix size of the cache, in bytes
301+
#[arg(long, default_value = "10000000")]
302+
max_cache_find_keys_size: usize,
303+
/// The maximum find_key_values_by_prefix size of the cache, in bytes
304+
#[arg(long, default_value = "10000000")]
305+
max_cache_find_key_values_size: usize,
291306
},
292307
}
293308

@@ -647,8 +662,13 @@ async fn main() {
647662
path,
648663
max_stream_queries,
649664
max_cache_size,
650-
max_entry_size,
665+
max_value_entry_size,
666+
max_find_keys_entry_size,
667+
max_find_key_values_entry_size,
651668
max_cache_entries,
669+
max_cache_value_size,
670+
max_cache_find_keys_size,
671+
max_cache_find_key_values_size,
652672
} => {
653673
let path_buf = path.into();
654674
let path_with_guard = PathWithGuard::new(path_buf);
@@ -660,8 +680,13 @@ async fn main() {
660680
};
661681
let storage_cache_config = StorageCacheConfig {
662682
max_cache_size,
663-
max_entry_size,
683+
max_value_entry_size,
684+
max_find_keys_entry_size,
685+
max_find_key_values_entry_size,
664686
max_cache_entries,
687+
max_cache_value_size,
688+
max_cache_find_keys_size,
689+
max_cache_find_key_values_size,
665690
};
666691
let config = RocksDbStoreConfig {
667692
inner_config,

0 commit comments

Comments
 (0)