Skip to content

Commit 535d9c9

Browse files
pin cores but give tokio workers more
1 parent 929decb commit 535d9c9

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

crates/standalone/src/main.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use clap::Command;
22

3+
use spacetimedb::startup;
34
use spacetimedb::util::jobs::JobCores;
45
use tokio::runtime::Builder;
56

@@ -59,6 +60,8 @@ static GLOBAL: Jemalloc = Jemalloc;
5960
pub static _rjem_malloc_conf: &[u8] = b"prof:true,prof_active:false,lg_prof_sample:19\0";
6061

6162
fn 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

Comments
 (0)