Skip to content

Commit 287dc29

Browse files
committed
restore: parallel snapshot decompression
1 parent 9deac34 commit 287dc29

File tree

16 files changed

+907
-112
lines changed

16 files changed

+907
-112
lines changed

src/app/firedancer-dev/commands/snapshot_load.c

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ snapshot_load_topo( config_t * config,
3737
fd_topob_new( &config->topo, config->name );
3838
topo->max_page_size = fd_cstr_to_shmem_page_sz( config->hugetlbfs.max_page_size );
3939

40+
#define FOR(cnt) for( ulong i=0UL; i<cnt; i++ )
41+
4042
fd_topob_wksp( topo, "txncache" );
4143
fd_topo_obj_t * txncache_obj = setup_topo_txncache( topo, "txncache",
4244
config->firedancer.runtime.max_live_slots,
@@ -51,6 +53,7 @@ snapshot_load_topo( config_t * config,
5153

5254
int snapshot_lthash_disabled = config->development.snapshots.disable_lthash_verification;
5355
ulong lta_tile_cnt = config->firedancer.layout.snapla_tile_count;
56+
ulong dc_tile_cnt = config->development.snapshots.decompress_tile_count;
5457

5558
if( config->firedancer.vinyl.enabled ) {
5659
setup_topo_vinyl_meta( topo, &config->firedancer );
@@ -81,8 +84,7 @@ snapshot_load_topo( config_t * config,
8184

8285
/* "snapdc": Zstandard decompress tile */
8386
fd_topob_wksp( topo, "snapdc" );
84-
fd_topo_tile_t * snapdc_tile = fd_topob_tile( topo, "snapdc", "snapdc", "metric_in", ULONG_MAX, 0, 0 );
85-
snapdc_tile->allow_shutdown = 1;
87+
FOR( dc_tile_cnt ) fd_topob_tile( topo, "snapdc", "snapdc", "metric_in", ULONG_MAX, 0, 0 )->allow_shutdown = 1;
8688
8789
/* "snapin": Snapshot parser tile */
8890
fd_topob_wksp( topo, "snapin" );
@@ -122,16 +124,14 @@ snapshot_load_topo( config_t * config,
122124
fd_topob_wksp( topo, "snapls_ct" );
123125
}
124126

125-
#define FOR(cnt) for( ulong i=0UL; i<cnt; i++ )
126-
127127
if( FD_LIKELY( !snapshot_lthash_disabled ) ) {
128128
FOR(lta_tile_cnt) fd_topob_tile( topo, "snapla", "snapla", "metric_in", ULONG_MAX, 0, 0 )->allow_shutdown = 1;
129129
/**/ fd_topob_tile( topo, "snapls", "snapls", "metric_in", ULONG_MAX, 0, 0 )->allow_shutdown = 1;
130130
}
131131

132132
fd_topob_link( topo, "snapct_ld", "snapct_ld", 128UL, sizeof(fd_ssctrl_init_t), 1UL );
133133
fd_topob_link( topo, "snapld_dc", "snapld_dc", 16384UL, USHORT_MAX, 1UL );
134-
fd_topob_link( topo, "snapdc_in", "snapdc_in", 16384UL, USHORT_MAX, 1UL );
134+
FOR( dc_tile_cnt ) fd_topob_link( topo, "snapdc_in", "snapdc_in", 16384UL, USHORT_MAX, 1UL );
135135
if( FD_UNLIKELY( snapshot_lthash_disabled ) ) {
136136
fd_topob_link( topo, "snapin_ct", "snapin_ct", 128UL, 0UL, 1UL );
137137
}
@@ -159,9 +159,9 @@ snapshot_load_topo( config_t * config,
159159
fd_topob_tile_out( topo, "snapct", 0UL, "snapct_repr", 0UL );
160160
fd_topob_tile_in ( topo, "snapld", 0UL, "metric_in", "snapct_ld", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
161161
fd_topob_tile_out( topo, "snapld", 0UL, "snapld_dc", 0UL );
162-
fd_topob_tile_in ( topo, "snapdc", 0UL, "metric_in", "snapld_dc", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
163-
fd_topob_tile_out( topo, "snapdc", 0UL, "snapdc_in", 0UL );
164-
fd_topob_tile_in ( topo, "snapin", 0UL, "metric_in", "snapdc_in", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
162+
FOR( dc_tile_cnt ) fd_topob_tile_in ( topo, "snapdc", i, "metric_in", "snapld_dc", 0UL, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
163+
FOR( dc_tile_cnt ) fd_topob_tile_out( topo, "snapdc", i, "snapdc_in", i );
164+
FOR( dc_tile_cnt ) fd_topob_tile_in ( topo, "snapin", 0UL, "metric_in", "snapdc_in", i, FD_TOPOB_RELIABLE, FD_TOPOB_POLLED );
165165
if( FD_UNLIKELY( snapshot_lthash_disabled ) ) {
166166
fd_topob_tile_out( topo, "snapin", 0UL, "snapin_ct", 0UL );
167167
} else {
@@ -262,6 +262,7 @@ snapshot_load_args( int * pargc,
262262
" --fsck After loading, run database integrity checks\n"
263263
" --lthash After loading, recompute the account DB lthash\n"
264264
" --accounts-hist After loading, analyze account size distribution\n"
265+
" --dc-tiles Number of snapdc tiles\n"
265266
"\n"
266267
"Vinyl database flags:\n"
267268
" --vinyl-server After loading, indefinitely run a vinyl DB server\n"
@@ -295,6 +296,7 @@ snapshot_load_args( int * pargc,
295296
char const * vinyl_io = fd_env_strip_cmdline_cstr ( pargc, pargv, "--vinyl-io", NULL, "bd" );
296297
float cache_sz = fd_env_strip_cmdline_float ( pargc, pargv, "--cache-sz", NULL, 0.0f );
297298
float cache_rec_max = fd_env_strip_cmdline_float ( pargc, pargv, "--cache-rec-max",NULL, 0.0f );
299+
uint dc_tile_cnt = fd_env_strip_cmdline_uint ( pargc, pargv, "--dc-tiles", NULL, 1U );
298300

299301
fd_cstr_ncpy( args->snapshot_load.snapshot_dir, snapshot_dir, sizeof(args->snapshot_load.snapshot_dir) );
300302
args->snapshot_load.fsck = fsck;
@@ -314,6 +316,7 @@ snapshot_load_args( int * pargc,
314316
args->snapshot_load.db_rec_max = (ulong)db_rec_max;
315317
args->snapshot_load.cache_sz = (ulong)cache_sz;
316318
args->snapshot_load.cache_rec_max = (ulong)cache_rec_max;
319+
args->snapshot_load.dc_tile_cnt = (uint)dc_tile_cnt;
317320

318321
fd_cstr_ncpy( args->snapshot_load.vinyl_path, vinyl_path, sizeof(args->snapshot_load.vinyl_path) );
319322

@@ -595,6 +598,7 @@ fixup_config( config_t * config,
595598
}
596599

597600
config->development.snapshots.disable_lthash_verification = !args->snapshot_load.lthash;
601+
config->development.snapshots.decompress_tile_count = args->snapshot_load.dc_tile_cnt;
598602

599603
/* FIXME Unfortunately, the fdctl boot procedure constructs the
600604
topology before parsing command-line arguments. So, here,
@@ -658,8 +662,6 @@ snapshot_load_cmd_fn( args_t * args,
658662
ulong total_off_old = 0UL;
659663
ulong decomp_off_old = 0UL;
660664
ulong vinyl_off_old = 0UL;
661-
ulong snapct_backp_old = 0UL;
662-
ulong snapct_wait_old = 0UL;
663665
ulong snapld_backp_old = 0UL;
664666
ulong snapld_wait_old = 0UL;
665667
ulong snapdc_backp_old = 0UL;
@@ -684,8 +686,8 @@ snapshot_load_cmd_fn( args_t * args,
684686
puts( "" );
685687
fputs( "--------------------------------------------", stdout );
686688
if( snapwr_tile ) fputs( "--------------", stdout );
687-
if( snapls_tile ) fputs( "[ct],[ld],[dc],[in],[lts]--------[ct],[ld],[dc],[in],[lts]", stdout );
688-
else fputs( "[ct],[ld],[dc],[in]--------[ct],[ld],[dc],[in]", stdout );
689+
if( snapls_tile ) fputs( "[ld],[dc],[in],[lts]--------[ld],[dc],[in],[lts]", stdout );
690+
else fputs( "[ld],[dc],[in]--------[ld],[dc],[in]", stdout );
689691
if( snapwr_tile ) fputs( ",[wh],[wr]" , stdout );
690692
puts( "--------------" );
691693
}
@@ -712,8 +714,6 @@ snapshot_load_cmd_fn( args_t * args,
712714
ulong decomp_off = snapdc_metrics[ MIDX( GAUGE, SNAPDC, FULL_DECOMPRESSED_BYTES_WRITTEN ) ] +
713715
snapdc_metrics[ MIDX( GAUGE, SNAPDC, INCREMENTAL_DECOMPRESSED_BYTES_WRITTEN ) ];
714716
ulong vinyl_off = snapwr_tile ? snapwr_metrics[ MIDX( GAUGE, SNAPWR, VINYL_BYTES_WRITTEN ) ] : 0UL;
715-
ulong snapct_backp = snapct_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_BACKPRESSURE_PREFRAG ) ];
716-
ulong snapct_wait = snapct_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_CAUGHT_UP_POSTFRAG ) ] + snapct_backp;
717717
ulong snapld_backp = snapld_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_BACKPRESSURE_PREFRAG ) ];
718718
ulong snapld_wait = snapld_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_CAUGHT_UP_POSTFRAG ) ] + snapld_backp;
719719
ulong snapdc_backp = snapdc_metrics[ MIDX( COUNTER, TILE, REGIME_DURATION_NANOS_BACKPRESSURE_PREFRAG ) ];
@@ -744,29 +744,25 @@ snapshot_load_cmd_fn( args_t * args,
744744
printf( " vinyl=%4.0fMB/s", (double)( vinyl_off - vinyl_off_old )/1e6 );
745745
}
746746
if( !snapls_tile ) {
747-
printf( " backp=(%3.0f%%,%3.0f%%,%3.0f%%,%3.0f%%",
748-
( (double)( snapct_backp-snapct_backp_old )*ns_per_tick )/1e7,
747+
printf( " backp=(%3.0f%%,%3.0f%%,%3.0f%%",
749748
( (double)( snapld_backp-snapld_backp_old )*ns_per_tick )/1e7,
750749
( (double)( snapdc_backp-snapdc_backp_old )*ns_per_tick )/1e7,
751750
( (double)( snapin_backp-snapin_backp_old )*ns_per_tick )/1e7 );
752751
}
753752
else {
754-
printf( " backp=(%3.0f%%,%3.0f%%,%3.0f%%,%3.0f%%,%3.0f%%",
755-
( (double)( snapct_backp-snapct_backp_old )*ns_per_tick )/1e7,
753+
printf( " backp=(%3.0f%%,%3.0f%%,%3.0f%%,%3.0f%%",
756754
( (double)( snapld_backp-snapld_backp_old )*ns_per_tick )/1e7,
757755
( (double)( snapdc_backp-snapdc_backp_old )*ns_per_tick )/1e7,
758756
( (double)( snapin_backp-snapin_backp_old )*ns_per_tick )/1e7,
759757
( (double)( snapls_backp-snapls_backp_old )*ns_per_tick )/1e7 );
760758
}
761759
if( !snapls_tile ) {
762-
printf( ") busy=(%3.0f%%,%3.0f%%,%3.0f%%,%3.0f%%",
763-
100-( ( (double)( snapct_wait-snapct_wait_old )*ns_per_tick )/1e7 ),
760+
printf( ") busy=(%3.0f%%,%3.0f%%,%3.0f%%",
764761
100-( ( (double)( snapld_wait-snapld_wait_old )*ns_per_tick )/1e7 ),
765762
100-( ( (double)( snapdc_wait-snapdc_wait_old )*ns_per_tick )/1e7 ),
766763
100-( ( (double)( snapin_wait-snapin_wait_old )*ns_per_tick )/1e7 ) );
767764
} else {
768-
printf( ") busy=(%3.0f%%,%3.0f%%,%3.0f%%,%3.0f%%,%3.0f%%",
769-
100-( ( (double)( snapct_wait-snapct_wait_old )*ns_per_tick )/1e7 ),
765+
printf( ") busy=(%3.0f%%,%3.0f%%,%3.0f%%,%3.0f%%",
770766
100-( ( (double)( snapld_wait-snapld_wait_old )*ns_per_tick )/1e7 ),
771767
100-( ( (double)( snapdc_wait-snapdc_wait_old )*ns_per_tick )/1e7 ),
772768
100-( ( (double)( snapin_wait-snapin_wait_old )*ns_per_tick )/1e7 ),
@@ -784,8 +780,6 @@ snapshot_load_cmd_fn( args_t * args,
784780
total_off_old = total_off;
785781
decomp_off_old = decomp_off;
786782
vinyl_off_old = vinyl_off;
787-
snapct_backp_old = snapct_backp;
788-
snapct_wait_old = snapct_wait;
789783
snapld_backp_old = snapld_backp;
790784
snapld_wait_old = snapld_wait;
791785
snapdc_backp_old = snapdc_backp;

src/app/firedancer/config/default.toml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,12 +1778,18 @@ user = ""
17781778
[development.udpecho]
17791779
affinity = "auto"
17801780

1781-
# Set to true to disable verification of the lthash in the
1782-
# snapshot loader. This is not safe or supported in production
1783-
# and should only be used for development and testing purposes.
1784-
#
1785-
# If lthash verification is disabled, the validator will not
1786-
# start any lthash tiles and the value of `snapla_tile_count`
1787-
# in the layout will be ignored.
1781+
# Experimental snapshot loading options
17881782
[development.snapshots]
1783+
# Set to true to disable verification of the lthash in the
1784+
# snapshot loader. This is not safe or supported in production
1785+
# and should only be used for development and testing purposes.
1786+
#
1787+
# If lthash verification is disabled, the validator will not
1788+
# start any lthash tiles and the value of `snapla_tile_count`
1789+
# in the layout will be ignored.
17891790
disable_lthash_verification = true
1791+
1792+
# Set numebr of decompression threads. Values other than 1 only
1793+
# have an effect with snapshot files with an experimental
1794+
# compression format. See src/discof/restore/fd_snapmk_para.c
1795+
decompress_tile_count = 1

src/app/shared/fd_action.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ union fdctl_args {
136136
ulong db_rec_max;
137137
ulong cache_sz;
138138
ulong cache_rec_max;
139+
uint dc_tile_cnt;
139140
} snapshot_load;
140141

141142
};

src/app/shared/fd_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ struct fd_config {
348348

349349
struct {
350350
int disable_lthash_verification;
351+
uint decompress_tile_count;
351352
} snapshots;
352353

353354
struct {

src/app/shared/fd_config_parse.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ fd_config_extract_pod( uchar * pod,
315315

316316
CFG_POP ( cstr, development.udpecho.affinity );
317317
CFG_POP ( bool, development.snapshots.disable_lthash_verification );
318+
CFG_POP ( uint, development.snapshots.decompress_tile_count );
318319

319320
if( FD_UNLIKELY( !config->is_firedancer ) ) {
320321
CFG_POP ( bool, development.gui.websocket_compression );

src/disco/stem/fd_stem.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@
194194
#define STEM_LAZY (0L)
195195
#endif
196196

197+
#ifndef STEM_CUSTOM_IN_SELECT
198+
#define STEM_CUSTOM_IN_SELECT 0
199+
#endif
200+
197201
#define STEM_SHUTDOWN_SEQ (ULONG_MAX-1UL)
198202

199203
static inline void
@@ -473,6 +477,7 @@ STEM_(run1)( ulong in_cnt,
473477
if( FD_UNLIKELY( event_seq>=event_cnt ) ) {
474478
event_seq = 0UL;
475479

480+
# if !STEM_CUSTOM_IN_SELECT
476481
/* Randomize the order of event processing for the next event
477482
event_cnt events to avoid lighthousing effects causing input
478483
credit starvation at extreme fan in/fan out, extreme in load
@@ -494,6 +499,7 @@ STEM_(run1)( ulong in_cnt,
494499
in[ swap_idx ] = in[ 0 ];
495500
in[ 0 ] = in_tmp;
496501
}
502+
# endif
497503
}
498504

499505
/* Reload housekeeping timer */
@@ -581,9 +587,15 @@ STEM_(run1)( ulong in_cnt,
581587
}
582588
#endif
583589

590+
# if STEM_CUSTOM_IN_SELECT
591+
in_seq = stem.next_in_idx;
592+
# endif
593+
584594
fd_stem_tile_in_t * this_in = &in[ in_seq ];
595+
# if !STEM_CUSTOM_IN_SELECT
585596
in_seq++;
586597
if( in_seq>=in_cnt ) in_seq = 0UL; /* cmov */
598+
# endif
587599

588600
/* Check if this in has any new fragments to mux */
589601

@@ -824,3 +836,4 @@ STEM_(run)( fd_topo_t * topo,
824836
#undef STEM_CALLBACK_RETURNABLE_FRAG
825837
#undef STEM_CALLBACK_AFTER_FRAG
826838
#undef STEM_CALLBACK_AFTER_POLL_OVERRUN
839+
#undef STEM_CUSTOM_IN_SELECT

src/disco/stem/fd_stem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ struct fd_stem_context {
1313
ulong * cr_avail;
1414
ulong * min_cr_avail;
1515
ulong cr_decrement_amount;
16+
17+
ulong next_in_idx;
1618
};
1719

1820
typedef struct fd_stem_context fd_stem_context_t;

src/discof/restore/Local.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ $(call make-unit-test,test_sspeer_selector,utils/test_sspeer_selector,fd_discof
2828
$(call run-unit-test,test_slot_delta_parser)
2929
$(call run-unit-test,test_sspeer_selector)
3030
endif
31+
ifdef FD_HAS_ZSTD
32+
$(call add-objs,utils/fd_zstd_dskip,fd_discof)
33+
ifdef FD_HAS_HOSTED
34+
$(call make-unit-test,test_zstd_dskip,utils/test_zstd_dskip,fd_discof fd_flamenco fd_ballet fd_util)
35+
endif
36+
endif
3137

3238
ifdef FD_HAS_HOSTED
3339
$(call make-fuzz-test,fuzz_snapshot_parser,utils/fuzz_snapshot_parser,fd_discof fd_flamenco fd_ballet fd_util)

0 commit comments

Comments
 (0)