🎥 Make videos programmatically with React
align cpu count
Jonny Burgercd41ac277635
diff --git a/packages/renderer/src/get-concurrency.ts b/packages/renderer/src/get-concurrency.tsindex 73fa8f6e10..bf849d77be 100644--- a/packages/renderer/src/get-concurrency.ts+++ b/packages/renderer/src/get-concurrency.ts@@ -1,32 +1,9 @@-import {execSync} from 'node:child_process';-import os from 'node:os';--// Kubernetes uses the following command to spawn Docker containers:-// docker run --cpuset-cpus="0,1" to assign only 2 CPUs.-// However, Node.js returns the core count of the host system (up to 96!)-// We also get it from nproc and use the minimum of the two.-const getConcurrencyFromNProc = (): number | null => {- try {- return parseInt(execSync('nproc').toString().trim(), 10);- } catch (error) {- return null;- }-};--const getMaxCpus = () => {- const node = os.cpus().length;- const nproc = getConcurrencyFromNProc();- if (nproc === null) {- return node;- }-- return Math.min(nproc, node);-};+import {getCpuCount} from './get-cpu-count';export const getActualConcurrency = (userPreference: number | string | null,) => {- const maxCpus = getMaxCpus();+ const maxCpus = getCpuCount();if (userPreference === null) {return Math.round(Math.min(8, Math.max(1, maxCpus / 2)));diff --git a/packages/renderer/src/get-cpu-count.ts b/packages/renderer/src/get-cpu-count.tsnew file mode 100644index 0000000000..673a687dda--- /dev/null+++ b/packages/renderer/src/get-cpu-count.ts@@ -0,0 +1,25 @@+// Kubernetes uses the following command to spawn Docker containers:+// docker run --cpuset-cpus="0,1" to assign only 2 CPUs.+// However, Node.js returns the core count of the host system (up to 96!)++import {execSync} from 'node:child_process';+import {cpus} from 'node:os';++// We also get it from nproc and use the minimum of the two.+const getConcurrencyFromNProc = (): number | null => {+ try {+ return parseInt(execSync('nproc').toString().trim(), 10);+ } catch (error) {+ return null;+ }+};++export const getCpuCount = () => {+ const node = cpus().length;+ const nproc = getConcurrencyFromNProc();+ if (nproc === null) {+ return node;+ }++ return Math.min(nproc, node);+};diff --git a/packages/renderer/src/get-video-threads-flag.ts b/packages/renderer/src/get-video-threads-flag.tsindex 2cadf6ff44..699bf09bb4 100644--- a/packages/renderer/src/get-video-threads-flag.ts+++ b/packages/renderer/src/get-video-threads-flag.ts@@ -1,10 +1,11 @@import os from 'node:os';+import {getCpuCount} from './get-cpu-count';const MEMORY_USAGE_PER_THREAD = 400_000_000; // 400MBconst RESERVED_MEMORY = 2_000_000_000;export const getIdealVideoThreadsFlag = () => {const freeMemory = os.freemem();- const cpus = os.cpus().length;+ const cpus = getCpuCount();const maxRecommendedBasedOnCpus = (cpus * 2) / 3;const maxRecommendedBasedOnMemory =diff --git a/packages/renderer/src/validate-concurrency.ts b/packages/renderer/src/validate-concurrency.tsindex cc3b6392d8..14c51837eb 100644--- a/packages/renderer/src/validate-concurrency.ts+++ b/packages/renderer/src/validate-concurrency.ts@@ -1,3 +1,5 @@+import {getCpuCount} from './get-cpu-count';+export const validateConcurrency = ({setting,value,@@ -49,7 +51,7 @@ export const validateConcurrency = ({};export const getMaxConcurrency = () => {- return require('os').cpus().length;+ return getCpuCount();};export const getMinConcurrency = () => 1;