Skip to content
This repository was archived by the owner on Jan 27, 2026. It is now read-only.

Commit 2b28bf8

Browse files
committed
optimizing Cardano and Ergo
1 parent c8ace2c commit 2b28bf8

File tree

7 files changed

+51
-38
lines changed

7 files changed

+51
-38
lines changed

chains/cardano/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ sudo apt-get install rustup
1010

1111
### Requirements
1212

13-
With current [setup](src/model_v1.rs) you need at least 16 cores CPU and 32GB RAM to run both Cardano Node and Redbit without crashing.
13+
With current [setup](src/model_v1.rs) you need at least 16 cores CPU and 32GB RAM to run both Cardano Node (needs 24GB) and Redbit but remaining RAM
14+
is used for page caching so it might swap or kernel with throttle our process. If you don't have enough RAM, set :
15+
16+
```
17+
db_cache_size_gb = "low"
18+
min_entity_batch_size = 200_000
19+
```
1420

1521
### Usage
1622

chains/cardano/src/model_v1.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,33 @@ pub struct Timestamp(pub u32);
2828

2929
#[entity]
3030
pub struct Block {
31-
#[pk]
31+
#[pk(db_cache = 1)]
3232
pub height: Height,
3333
pub header: BlockHeader,
3434
pub transactions: Vec<Transaction>,
3535
}
3636

3737
#[entity]
3838
pub struct BlockHeader {
39-
#[fk(one2one)]
39+
#[fk(one2one, db_cache = 1)]
4040
pub height: Height,
41-
#[column(index)]
41+
#[column(index, db_cache = 1)]
4242
pub hash: BlockHash,
43-
#[column(index)]
43+
#[column(index, db_cache = 1)]
4444
pub prev_hash: BlockHash,
45-
#[column(range)]
45+
#[column(range, db_cache = 1)]
4646
pub slot: Slot,
47-
#[column(range)]
47+
#[column(range, db_cache = 1)]
4848
pub timestamp: Timestamp,
4949
#[column(transient)]
5050
pub weight: Weight,
5151
}
5252

5353
#[entity]
5454
pub struct Transaction {
55-
#[fk(one2many, db_cache = 1)]
55+
#[fk(one2many, db_cache = 2)]
5656
pub id: BlockPointer,
57-
#[column(index, used, shards = 4, db_cache = 4, lru_cache = 12)]
57+
#[column(index, used, db_cache = 20, lru_cache = 20)]
5858
pub hash: TxHash,
5959
pub utxos: Vec<Utxo>,
6060
#[write_from_using(input_refs, hash)] // implement custom write_from_using function, see hook.rs
@@ -71,9 +71,9 @@ pub struct Utxo {
7171
pub id: TransactionPointer,
7272
#[column(db_cache = 1)]
7373
pub amount: u64,
74-
#[column(dictionary, shards = 4, db_cache = 4, lru_cache = 8)]
74+
#[column(dictionary, db_cache = 20, lru_cache = 20)]
7575
pub script_hash: ScriptHash,
76-
#[column(dictionary, shards = 4, db_cache = 4, lru_cache = 8)]
76+
#[column(dictionary, db_cache = 20, lru_cache = 20)]
7777
pub address: Address,
7878
pub assets: Vec<Asset>,
7979
}
@@ -84,11 +84,11 @@ pub struct Asset {
8484
pub id: UtxoPointer,
8585
#[column(db_cache = 1)]
8686
pub amount: u64,
87-
#[column(index, shards = 3, db_cache = 2)]
87+
#[column(index, db_cache = 2)]
8888
pub asset_action: AssetAction,
89-
#[column(dictionary, shards = 5, db_cache = 4, lru_cache = 6)]
89+
#[column(dictionary, db_cache = 20, lru_cache = 20)]
9090
pub name: AssetName,
91-
#[column(dictionary, shards = 5, db_cache = 4, lru_cache = 6)]
91+
#[column(dictionary, db_cache = 20, lru_cache = 20)]
9292
pub policy_id: PolicyId,
9393
}
9494

chains/ergo/README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ sudo apt-get install rustup
1010

1111
### Requirements
1212

13-
With current [setup](src/model_v1.rs) you need at least 8 cores CPU and 16GB RAM to run both Ergo Node and Redbit without crashing.
13+
With current [setup](src/model_v1.rs) you need at least 8 cores CPU and 12GB RAM to run both Ergo Node and Redbit but remaining RAM is used for page caching
14+
so it might swap or kernel with throttle our process. If you don't have enough RAM, set :
15+
16+
```
17+
db_cache_size_gb = "low"
18+
min_entity_batch_size = 200_000
19+
```
1420

1521
### Usage
1622

@@ -20,8 +26,8 @@ export ERGO__API_KEY="foo" # not needed for syncing
2026
cargo run --release
2127
```
2228

23-
Indexing might crash especially on laptops with Node running locally and not being synced yet.
24-
In that case, set `fetching_parallelism = "low"` to not put the Node and Laptop under heavy pressure.
29+
Do not use more than `fetching_parallelism = "mild"` or sharding as Ergo node reading is quite CPU intensive and increasing
30+
fetching parallelism eats all runtime.
2531

2632
### Rest API
2733

chains/ergo/config/ergo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
api_host = "http://127.0.0.1:9053"
22
api_key = "foo"
3-
fetching_parallelism = "high" # low / mild / high
3+
fetching_parallelism = "mild" # low / mild / high

chains/ergo/config/settings.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
name = "ergo"
33
db_path = "/opt/.chain"
44
enable = true
5-
node_sync_interval_s = 1 # 0 means only chatching up but no periodic sync
6-
fork_detection_heights = 100 # max 255, how many blocks from tip to check for forks
7-
db_cache_size_gb = "mild" # off / tiny / low / mild / high / ultra
8-
min_entity_batch_size = 1_000_000 # Sum of : inputs + outputs
9-
non_durable_batches = 50 # how many batches to commit non-durably before forcing a durable commit
10-
processing_parallelism = "high" # off / tiny / low / mild / high / ultra
5+
node_sync_interval_s = 1 # 0 means only chatching up but no periodic sync
6+
fork_detection_heights = 100 # max 255, how many blocks from tip to check for forks
7+
db_cache_size_gb = "mild" # off / tiny / low / mild / high / ultra
8+
min_entity_batch_size = 500_000 # Sum of : inputs + outputs
9+
non_durable_batches = 50 # how many batches to commit non-durably before forcing a durable commit
10+
processing_parallelism = "high" # off / tiny / low / mild / high / ultra
1111
validation_from_height = 0
1212

1313
[http]

chains/ergo/src/model_v1.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,31 @@ pub use chain::*;
2121

2222
#[entity]
2323
pub struct Block {
24-
#[pk]
24+
#[pk(db_cache = 1)]
2525
pub height: Height,
2626
pub header: BlockHeader,
2727
pub transactions: Vec<Transaction>,
2828
}
2929

3030
#[entity]
3131
pub struct BlockHeader {
32-
#[fk(one2one)]
32+
#[fk(one2one, db_cache = 1)]
3333
pub height: Height,
34-
#[column(index)]
34+
#[column(index, db_cache = 1)]
3535
pub hash: BlockHash,
36-
#[column(index)]
36+
#[column(index, db_cache = 1)]
3737
pub prev_hash: BlockHash,
38-
#[column(range)]
38+
#[column(range, db_cache = 1)]
3939
pub timestamp: Timestamp,
4040
#[column(transient)]
4141
pub weight: Weight,
4242
}
4343

4444
#[entity]
4545
pub struct Transaction {
46-
#[fk(one2many, db_cache = 1)]
46+
#[fk(one2many, db_cache = 2)]
4747
pub id: BlockPointer,
48-
#[column(index, db_cache = 2)]
48+
#[column(index, db_cache = 4)]
4949
pub hash: TxHash,
5050
pub utxos: Vec<Utxo>,
5151
#[write_from_using(input_refs, utxos)] // implement custom write_from_using function, see hook.rs
@@ -62,13 +62,13 @@ pub struct Utxo {
6262
pub id: TransactionPointer,
6363
#[column(db_cache = 1)]
6464
pub amount: u64,
65-
#[column(index, used, shards = 4, db_cache = 5)]
65+
#[column(index, used, db_cache = 30)]
6666
pub box_id: BoxId,
67-
#[column(dictionary, shards = 4, db_cache = 5)]
67+
#[column(dictionary, lru_cache = 20, db_cache = 30)]
6868
pub address: Address,
69-
#[column(dictionary, shards = 4, db_cache = 5)]
69+
#[column(dictionary, lru_cache = 20, db_cache = 30)]
7070
pub tree: Tree,
71-
#[column(dictionary, shards = 4, db_cache = 5)]
71+
#[column(dictionary, lru_cache = 10, db_cache = 20)]
7272
pub tree_template: TreeTemplate,
7373
pub assets: Vec<Asset>,
7474
}
@@ -79,9 +79,9 @@ pub struct Asset {
7979
pub id: UtxoPointer,
8080
#[column(db_cache = 1)]
8181
pub amount: u64,
82-
#[column(index, shards = 3, db_cache = 2)]
82+
#[column(index, lru_cache = 10, db_cache = 10)]
8383
pub asset_action: AssetAction,
84-
#[column(dictionary, shards = 4, db_cache = 2)]
84+
#[column(dictionary, lru_cache = 10, db_cache = 10)]
8585
pub name: AssetName,
8686
}
8787

redbit/src/storage/table_writer_api.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ pub enum WriterCommand<K: CopyOwnedValue + Send + 'static, V: Key + Send + 'stat
199199
Remove(K, Sender<Result<bool, AppError>>),
200200
QueryAndWrite {
201201
last_shards: Option<usize>,
202-
values: Vec<(usize, V)>, sink: Arc<dyn Fn(Option<usize>, Vec<(usize, Option<ValueOwned<K>>)>) -> Result<(), AppError> + Send + Sync + 'static>
202+
values: Vec<(usize, V)>,
203+
sink: Arc<dyn Fn(Option<usize>, Vec<(usize, Option<ValueOwned<K>>)>) -> Result<(), AppError> + Send + Sync + 'static>
203204
},
204205
Range(K, K, Sender<Result<Vec<(ValueBuf<K>, ValueBuf<V>)>, AppError>>),
205206
Flush(Sender<Result<TaskResult, AppError>>), // commit current tx, stay alive (idle)

0 commit comments

Comments
 (0)