From da655a1859744deec9f558effa5c9981ef5fd6d3 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Tue, 30 Apr 2024 19:14:13 +0100 Subject: [PATCH] Reduce default concurrency for musl thread over-subscription https://github.com/lovell/sharp-libvips/issues/229 --- docs/changelog.md | 2 ++ lib/utility.js | 3 +++ 2 files changed, 5 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index 1b07a15b2..2df84e5cb 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -8,6 +8,8 @@ Requires libvips v8.15.2 * Remove experimental status from `pipelineColourspace`. +* Reduce default concurrency when musl thread over-subscription detected. + * TypeScript: add missing definitions for `OverlayOptions`. [#4048](https://github.com/lovell/sharp/pull/4048) [@ike-gg](https://github.com/ike-gg) diff --git a/lib/utility.js b/lib/utility.js index 3af1b69ac..32738a635 100644 --- a/lib/utility.js +++ b/lib/utility.js @@ -153,6 +153,9 @@ function concurrency (concurrency) { if (detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) { // Reduce default concurrency to 1 when using glibc memory allocator sharp.concurrency(1); +} else if (detectLibc.familySync() === detectLibc.MUSL && sharp.concurrency() === 1024) { + // Reduce default concurrency when musl thread over-subscription detected + sharp.concurrency(require('node:os').availableParallelism()); } /**