11use clap:: Command ;
22
3+ use spacetimedb:: startup;
34use spacetimedb:: util:: jobs:: JobCores ;
45use tokio:: runtime:: Builder ;
56
@@ -59,6 +60,8 @@ static GLOBAL: Jemalloc = Jemalloc;
5960pub static _rjem_malloc_conf: & [ u8 ] = b"prof:true,prof_active:false,lg_prof_sample:19\0 " ;
6061
6162fn main ( ) -> anyhow:: Result < ( ) > {
63+ const RESERVED_DATABASE_CORES : usize = 2 ;
64+
6265 // take_hook() returns the default hook in case when a custom one is not set
6366 let orig_hook = panic:: take_hook ( ) ;
6467 panic:: set_hook ( Box :: new ( move |panic_info| {
@@ -70,8 +73,22 @@ fn main() -> anyhow::Result<()> {
7073 // Create a multi-threaded run loop
7174 let mut builder = Builder :: new_multi_thread ( ) ;
7275 builder. enable_all ( ) ;
76+ let database_cores = if let Some ( core_ids) = startup:: Cores :: get_core_ids ( ) {
77+ let reserved_database_cores = RESERVED_DATABASE_CORES . min ( core_ids. len ( ) ) ;
78+ let database_fraction = reserved_database_cores as f64 / core_ids. len ( ) as f64 ;
79+ let cores = startup:: pin_threads_with_reservations ( startup:: CoreReservations {
80+ databases : database_fraction,
81+ tokio_workers : 1.0 ,
82+ rayon : 0.0 ,
83+ irq : 0 ,
84+ reserved : 0 ,
85+ } ) ;
86+ cores. tokio . configure ( & mut builder) ;
87+ cores. databases . make_database_runners ( )
88+ } else {
89+ JobCores :: without_pinned_cores ( )
90+ } ;
7391 let rt = builder. build ( ) . unwrap ( ) ;
74- let database_cores = JobCores :: without_pinned_cores ( ) ;
7592
7693 // Keep a handle on the `database_cores` alive outside of `async_main`
7794 // and explicitly drop it to avoid dropping it from an `async` context -
0 commit comments