Fix BSOD MEMORY_MANAGEMENT on low-RAM servers
- Dynamically compute JVM -Xmx based on system RAM instead of hardcoded 32g - Reduce peak memory during session loading (inline JSON string, skip redundant clone) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4b624693ec
commit
0a724aed71
@ -1409,7 +1409,10 @@ export class DownloadManager extends EventEmitter {
|
|||||||
this.appSessionStartedAt = startedAt;
|
this.appSessionStartedAt = startedAt;
|
||||||
this.runtimePersistedTotalMs = Math.max(0, Number(settings.totalRuntimeAllTimeMs || 0));
|
this.runtimePersistedTotalMs = Math.max(0, Number(settings.totalRuntimeAllTimeMs || 0));
|
||||||
this.runtimePersistedAt = startedAt;
|
this.runtimePersistedAt = startedAt;
|
||||||
this.session = cloneSession(session);
|
// loadSession already returns a fresh, standalone object graph — no need to
|
||||||
|
// deep-clone again. This avoids duplicating the entire session in memory at
|
||||||
|
// startup which can spike peak heap on low-RAM servers.
|
||||||
|
this.session = session;
|
||||||
this.itemCount = Object.keys(this.session.items).length;
|
this.itemCount = Object.keys(this.session.items).length;
|
||||||
this.storagePaths = storagePaths;
|
this.storagePaths = storagePaths;
|
||||||
this.debridService = new DebridService(settings, {
|
this.debridService = new DebridService(settings, {
|
||||||
|
|||||||
@ -89,6 +89,14 @@ let resolveExtractorCommandInFlight: Promise<string> | null = null;
|
|||||||
|
|
||||||
const EXTRACTOR_RETRY_AFTER_MS = 30_000;
|
const EXTRACTOR_RETRY_AFTER_MS = 30_000;
|
||||||
const DEFAULT_ZIP_ENTRY_MEMORY_LIMIT_MB = 256;
|
const DEFAULT_ZIP_ENTRY_MEMORY_LIMIT_MB = 256;
|
||||||
|
|
||||||
|
/** Compute a safe JVM -Xmx value based on available physical RAM.
|
||||||
|
* Reserves 4 GB for Windows + Electron + other processes, caps at 16 GB. */
|
||||||
|
function jvmMaxHeapArg(): string {
|
||||||
|
const totalGb = os.totalmem() / (1024 ** 3);
|
||||||
|
const heapGb = Math.max(1, Math.min(Math.floor(totalGb - 4), 16));
|
||||||
|
return `-Xmx${heapGb}g`;
|
||||||
|
}
|
||||||
const EXTRACTOR_PROBE_TIMEOUT_MS = 8_000;
|
const EXTRACTOR_PROBE_TIMEOUT_MS = 8_000;
|
||||||
const DEFAULT_EXTRACT_CPU_BUDGET_PERCENT = 80;
|
const DEFAULT_EXTRACT_CPU_BUDGET_PERCENT = 80;
|
||||||
let currentExtractCpuPriority: string | undefined;
|
let currentExtractCpuPriority: string | undefined;
|
||||||
@ -1392,7 +1400,7 @@ function startDaemon(layout: JvmExtractorLayout): boolean {
|
|||||||
"-Dfile.encoding=UTF-8",
|
"-Dfile.encoding=UTF-8",
|
||||||
`-Djava.io.tmpdir=${jvmTmpDir}`,
|
`-Djava.io.tmpdir=${jvmTmpDir}`,
|
||||||
"-Xms1g",
|
"-Xms1g",
|
||||||
"-Xmx32g",
|
jvmMaxHeapArg(),
|
||||||
"-XX:+UseG1GC",
|
"-XX:+UseG1GC",
|
||||||
"-XX:MaxGCPauseMillis=50",
|
"-XX:MaxGCPauseMillis=50",
|
||||||
"-cp",
|
"-cp",
|
||||||
@ -1640,7 +1648,7 @@ async function runJvmExtractCommand(
|
|||||||
"-Dfile.encoding=UTF-8",
|
"-Dfile.encoding=UTF-8",
|
||||||
`-Djava.io.tmpdir=${jvmTmpDir}`,
|
`-Djava.io.tmpdir=${jvmTmpDir}`,
|
||||||
"-Xms1g",
|
"-Xms1g",
|
||||||
"-Xmx32g",
|
jvmMaxHeapArg(),
|
||||||
"-XX:+UseG1GC",
|
"-XX:+UseG1GC",
|
||||||
"-XX:MaxGCPauseMillis=50",
|
"-XX:MaxGCPauseMillis=50",
|
||||||
"-cp",
|
"-cp",
|
||||||
|
|||||||
@ -721,12 +721,14 @@ export function normalizeLoadedSessionTransientFields(session: SessionState): Se
|
|||||||
|
|
||||||
function readSessionFile(filePath: string): SessionState | null {
|
function readSessionFile(filePath: string): SessionState | null {
|
||||||
try {
|
try {
|
||||||
const raw = fs.readFileSync(filePath, "utf8");
|
// Inline readFileSync into JSON.parse so the raw string is not bound to a
|
||||||
const parsed = JSON.parse(raw) as unknown;
|
// variable and can be GC'd immediately — avoids holding the full JSON text
|
||||||
|
// and the parsed object graph in memory simultaneously.
|
||||||
|
const parsed = JSON.parse(fs.readFileSync(filePath, "utf8")) as unknown;
|
||||||
const session = normalizeLoadedSessionTransientFields(normalizeLoadedSession(parsed));
|
const session = normalizeLoadedSessionTransientFields(normalizeLoadedSession(parsed));
|
||||||
const pkgCount = Object.keys(session.packages).length;
|
const pkgCount = Object.keys(session.packages).length;
|
||||||
const itemCount = Object.keys(session.items).length;
|
const itemCount = Object.keys(session.items).length;
|
||||||
logger.info(`Session geladen: ${filePath} (${pkgCount} Pakete, ${itemCount} Items, ${raw.length} Bytes)`);
|
logger.info(`Session geladen: ${filePath} (${pkgCount} Pakete, ${itemCount} Items)`);
|
||||||
return session;
|
return session;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Session-Datei nicht lesbar: ${filePath}: ${String(error)}`);
|
logger.error(`Session-Datei nicht lesbar: ${filePath}: ${String(error)}`);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user