forked from mirrors/relay
Split available signature threads between sign & verify
This commit is contained in:
parent
f24685e700
commit
f3ff8ae5f7
2 changed files with 28 additions and 8 deletions
|
@ -259,12 +259,14 @@ impl Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn signature_threads(&self) -> usize {
|
pub(crate) fn signature_threads(&self) -> usize {
|
||||||
self.signature_threads.unwrap_or_else(|| {
|
self.signature_threads
|
||||||
|
.unwrap_or_else(|| {
|
||||||
std::thread::available_parallelism()
|
std::thread::available_parallelism()
|
||||||
.map(usize::from)
|
.map(usize::from)
|
||||||
.map_err(|e| tracing::warn!("Failed to get parallelism, {e}"))
|
.map_err(|e| tracing::warn!("Failed to get parallelism, {e}"))
|
||||||
.unwrap_or(1)
|
.unwrap_or(1)
|
||||||
})
|
})
|
||||||
|
.max(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn client_timeout(&self) -> u64 {
|
pub(crate) fn client_timeout(&self) -> u64 {
|
||||||
|
|
22
src/main.rs
22
src/main.rs
|
@ -242,6 +242,8 @@ fn server_main(
|
||||||
actix_rt::spawn(do_server_main(db, actors, media, collector, config))
|
actix_rt::spawn(do_server_main(db, actors, media, collector, config))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const VERIFY_RATIO: usize = 7;
|
||||||
|
|
||||||
async fn do_server_main(
|
async fn do_server_main(
|
||||||
db: Db,
|
db: Db,
|
||||||
actors: ActorCache,
|
actors: ActorCache,
|
||||||
|
@ -259,8 +261,24 @@ async fn do_server_main(
|
||||||
|
|
||||||
let keys = config.open_keys()?;
|
let keys = config.open_keys()?;
|
||||||
|
|
||||||
let spawner = Spawner::build("signature-thread", config.signature_threads())?;
|
let (signature_threads, verify_threads) = match config.signature_threads() {
|
||||||
let verify_spawner = Spawner::build("verify-thread", (config.signature_threads() / 8).max(1))?;
|
0 | 1 => (1, 1),
|
||||||
|
n if n <= VERIFY_RATIO => {
|
||||||
|
let verify_threads = (n / VERIFY_RATIO).max(1);
|
||||||
|
let signature_threads = n.saturating_sub(verify_threads).max(n);
|
||||||
|
|
||||||
|
(signature_threads, verify_threads)
|
||||||
|
}
|
||||||
|
n => {
|
||||||
|
let verify_threads = (n / VERIFY_RATIO).max(1);
|
||||||
|
let signature_threads = n.saturating_sub(verify_threads).max(VERIFY_RATIO);
|
||||||
|
|
||||||
|
(signature_threads, verify_threads)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let spawner = Spawner::build("signature-thread", signature_threads)?;
|
||||||
|
let verify_spawner = Spawner::build("verify-thread", verify_threads)?;
|
||||||
|
|
||||||
let bind_address = config.bind_address();
|
let bind_address = config.bind_address();
|
||||||
let server = HttpServer::new(move || {
|
let server = HttpServer::new(move || {
|
||||||
|
|
Loading…
Reference in a new issue