Skip to content

Commit

Permalink
fix: ensure the pool counter's always decremented via scopeguard (#1604)
Browse files Browse the repository at this point in the history
also report machine parallelism @ startup

Issue SYNC-4421
  • Loading branch information
pjenvey authored Sep 26, 2024
1 parent e9934b5 commit 4259183
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions syncserver-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ serde_json.workspace = true
slog.workspace = true
slog-scope.workspace = true
hkdf.workspace = true

scopeguard = "1.2"
13 changes: 7 additions & 6 deletions syncserver-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,17 @@ impl BlockingThreadpool {
E: fmt::Debug + Send + InternalError + 'static,
{
self.spawned_tasks.fetch_add(1, Ordering::Relaxed);
// Ensure the counter's always decremented (whether the task completed,
// was cancelled or panicked)
scopeguard::defer! {
self.spawned_tasks.fetch_sub(1, Ordering::Relaxed);
}

let result = web::block(f).await.unwrap_or_else(|_| {
web::block(f).await.unwrap_or_else(|_| {
Err(E::internal_error(
"Blocking threadpool operation canceled".to_owned(),
))
});

self.spawned_tasks.fetch_sub(1, Ordering::Relaxed);

result
})
}

pub fn active_threads(&self) -> u64 {
Expand Down
11 changes: 10 additions & 1 deletion syncserver-settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,16 @@ impl Settings {
let db = Url::parse(&self.syncstorage.database_url)
.map(|url| url.scheme().to_owned())
.unwrap_or_else(|_| "<invalid db>".to_owned());
format!("http://{}:{} ({}) {}", self.host, self.port, db, quota)
let parallelism = format!(
"available_parallelism: {:?} num_cpus: {} num_cpus (phys): {}",
std::thread::available_parallelism(),
num_cpus::get(),
num_cpus::get_physical()
);
format!(
"http://{}:{} ({db}) ({parallelism}) {quota}",
self.host, self.port
)
}
}

Expand Down

0 comments on commit 4259183

Please sign in to comment.