compilerThreads

tcmts.core.ts.compilerThreads · #pyfvofij · term · runs on the server

uses process

How many threads (GOMAXPROCS) a compiler process gets, where the container caps how many processes and threads it may have (cgroups' pids.max: Railway's is 1000): each of TypeScript 7's compiler processes otherwise runs a thread per core it sees, so a server running many (each tcm process has one, a push's checkers one each) hits the cap, and the one asking for a thread then dies (fatal error: newosproc). Two for a cap of a thousand or less, more for a larger one, eight at most; undefined where nothing caps it (or GOMAXPROCS is set already: what was asked stays). pidsMax is the cap as cgroups say it (max, or a number).

import { readPidsMax } from "#codebase/tcmts/core/ts";

export function compilerThreads(
  pidsMax = readPidsMax(),
  asked = process.env.GOMAXPROCS,
): number | undefined {
  if (asked) return undefined;
  const cap = Number(pidsMax?.trim());
  if (!Number.isFinite(cap) || cap <= 0) return undefined;
  return Math.max(2, Math.min(8, Math.floor(cap / 500)));
}

uses

used by