File tree 2 files changed +20
-12
lines changed
components/chainhook-event-observer/src/hord
2 files changed +20
-12
lines changed Original file line number Diff line number Diff line change @@ -714,7 +714,7 @@ pub async fn fetch_and_cache_blocks_in_hord_db(
714
714
let mut cursor = start_block as usize ;
715
715
let mut inbox = HashMap :: new ( ) ;
716
716
let mut num_writes = 0 ;
717
- let traversals_cache = Arc :: new ( new_traversals_lazy_cache ( ) ) ;
717
+ let traversals_cache = Arc :: new ( new_traversals_lazy_cache ( hord_config . cache_size ) ) ;
718
718
719
719
while let Ok ( Some ( ( block_height, compacted_block, raw_block) ) ) = block_compressed_rx. recv ( ) {
720
720
insert_entry_in_blocks ( block_height, & compacted_block, & blocks_db_rw, & ctx) ;
@@ -792,18 +792,20 @@ pub async fn fetch_and_cache_blocks_in_hord_db(
792
792
return Ok ( ( ) ) ;
793
793
}
794
794
795
- if num_writes % 24 == 0 {
796
- ctx. try_log ( |logger| {
797
- slog:: info!(
798
- logger,
799
- "Flushing traversals cache (#{} entries)" ,
800
- traversals_cache. len( )
801
- ) ;
802
- } ) ;
803
- traversals_cache. clear ( ) ;
795
+ if !traversals_cache. is_empty ( ) {
796
+ if num_writes % 128 == 0 {
797
+ ctx. try_log ( |logger| {
798
+ slog:: info!(
799
+ logger,
800
+ "Flushing traversals cache (#{} entries)" ,
801
+ traversals_cache. len( )
802
+ ) ;
803
+ } ) ;
804
+ traversals_cache. shrink_to_fit ( ) ;
805
+ }
804
806
}
805
807
806
- if num_writes % 128 == 0 {
808
+ if num_writes % 512 == 0 {
807
809
ctx. try_log ( |logger| {
808
810
slog:: info!( logger, "Flushing DB to disk ({num_writes} inserts)" ) ;
809
811
} ) ;
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ use rocksdb::DB;
18
18
use rusqlite:: Connection ;
19
19
use std:: collections:: { BTreeMap , HashMap , VecDeque } ;
20
20
use std:: hash:: BuildHasherDefault ;
21
+ use std:: ops:: Div ;
21
22
use std:: path:: PathBuf ;
22
23
use std:: sync:: mpsc:: channel;
23
24
use std:: sync:: Arc ;
@@ -208,9 +209,14 @@ pub fn new_traversals_cache(
208
209
}
209
210
210
211
pub fn new_traversals_lazy_cache (
212
+ cache_size : usize ,
211
213
) -> DashMap < ( u32 , [ u8 ; 8 ] ) , LazyBlockTransaction , BuildHasherDefault < FxHasher > > {
212
214
let hasher = FxBuildHasher :: default ( ) ;
213
- DashMap :: with_hasher ( hasher)
215
+ DashMap :: with_capacity_and_hasher (
216
+ ( ( cache_size. saturating_sub ( 500 ) ) * 1000 * 1000 )
217
+ . div ( LazyBlockTransaction :: get_average_bytes_size ( ) ) ,
218
+ hasher,
219
+ )
214
220
}
215
221
216
222
pub fn retrieve_inscribed_satoshi_points_from_block (
You can’t perform that action at this time.
0 commit comments