forked from wangziqi/gongxue-base
docs: record db-limited capacity findings
This commit is contained in:
@@ -17,7 +17,9 @@ assert.match(script, /BENCHMARK_KEEP_DB_LIMIT/, 'benchmark script should support
|
||||
assert.match(script, /dockerJson\(\['info', '--format', '\{\{json \.\}\}'\]\)/, 'benchmark script should record Docker Desktop resources');
|
||||
assert.match(script, /inspectContainer\(composeServiceContainerId\('api'\)\)/, 'benchmark script should inspect the API container after compose starts');
|
||||
assert.match(script, /inspectContainer\(dbContainerName\)/, 'benchmark script should inspect the Supabase DB container');
|
||||
assert.match(script, /dockerHostRestoreLimit/, 'benchmark script should restore originally-unlimited DB containers to Docker host limits');
|
||||
assert.match(script, /restoreDbLimit\(dbRestore, resourceEvidence\)/, 'benchmark script should restore DB resource limits by default');
|
||||
assert.match(script, /restoreLimit = restore/, 'benchmark script should record the DB restore strategy in evidence');
|
||||
assert.match(script, /readBenchmarkSummary\(report\)/, 'benchmark script should attach benchmark summaries to resource evidence');
|
||||
|
||||
assert.match(runbook, /docker-4c16g-resource-evidence-\*\.json\/md/, 'runbook should document the resource evidence artifact');
|
||||
|
||||
@@ -48,7 +48,6 @@ function runCapture(command, args, options = {}) {
|
||||
return spawnSync(command, args, {
|
||||
cwd: repoRoot,
|
||||
encoding: 'utf8',
|
||||
shell: process.platform === 'win32',
|
||||
env: baseEnv(options.env),
|
||||
});
|
||||
}
|
||||
@@ -118,6 +117,20 @@ function dockerInfoSummary() {
|
||||
};
|
||||
}
|
||||
|
||||
function dockerHostRestoreLimit() {
|
||||
const info = dockerInfoSummary();
|
||||
const ncpu = Number(info.ncpu || 0);
|
||||
const memoryBytes = Number(info.memoryBytes || 0);
|
||||
return {
|
||||
cpus: ncpu > 0 ? String(ncpu) : '0',
|
||||
memory: memoryBytes > 0 ? String(Math.floor(memoryBytes * 0.98)) : '0',
|
||||
memorySwap: memoryBytes > 0 ? String(Math.floor(memoryBytes * 0.98)) : '-1',
|
||||
note: ncpu > 0 && memoryBytes > 0
|
||||
? 'Original DB container was unlimited; Docker Desktop may not clear live memory limits with docker update, so restore uses the Docker Desktop host limit.'
|
||||
: 'Original DB container was unlimited but Docker host resources were unavailable; attempted docker update unlimited restore.',
|
||||
};
|
||||
}
|
||||
|
||||
function resourceSummaryFromHostConfig(hostConfig = {}) {
|
||||
const nanoCpus = Number(hostConfig.NanoCpus || 0);
|
||||
const memoryBytes = Number(hostConfig.Memory || 0);
|
||||
@@ -191,11 +204,14 @@ function maybeApplyDbLimit(resourceEvidence) {
|
||||
}
|
||||
|
||||
const beforeRaw = resourceEvidence.database.before.resources.raw;
|
||||
const restore = {
|
||||
cpus: beforeRaw.nanoCpus > 0 ? String(beforeRaw.nanoCpus / 1_000_000_000) : '0',
|
||||
memory: String(beforeRaw.memory || 0),
|
||||
memorySwap: String(beforeRaw.memorySwap || 0),
|
||||
};
|
||||
const restore = beforeRaw.nanoCpus > 0 || beforeRaw.memory > 0
|
||||
? {
|
||||
cpus: beforeRaw.nanoCpus > 0 ? String(beforeRaw.nanoCpus / 1_000_000_000) : '0',
|
||||
memory: String(beforeRaw.memory || 0),
|
||||
memorySwap: String(beforeRaw.memorySwap || 0),
|
||||
note: 'Restoring DB container resource limits captured before benchmark.',
|
||||
}
|
||||
: dockerHostRestoreLimit();
|
||||
|
||||
try {
|
||||
updateContainerResources(dbContainerName, {
|
||||
@@ -219,6 +235,7 @@ function restoreDbLimit(restore, resourceEvidence) {
|
||||
try {
|
||||
updateContainerResources(dbContainerName, restore);
|
||||
resourceEvidence.database.restored = true;
|
||||
resourceEvidence.database.restoreLimit = restore;
|
||||
resourceEvidence.database.afterRestore = inspectContainer(dbContainerName);
|
||||
} catch (error) {
|
||||
resourceEvidence.database.restored = false;
|
||||
@@ -381,6 +398,7 @@ function resourceEvidenceMarkdown(evidence) {
|
||||
if (evidence.database?.afterRestore) {
|
||||
lines.push(`- DB 恢复后:${evidence.database.afterRestore.resources.cpus ?? 'unlimited'} CPU / ${evidence.database.afterRestore.resources.memory}`);
|
||||
}
|
||||
if (evidence.database?.restoreLimit?.note) lines.push(`- DB 恢复策略:${evidence.database.restoreLimit.note}`);
|
||||
if (evidence.database?.note) lines.push(`- 说明:${evidence.database.note}`);
|
||||
if (evidence.database?.limitError) lines.push(`- DB 限制错误:${evidence.database.limitError}`);
|
||||
if (evidence.database?.restoreError) lines.push(`- DB 恢复错误:${evidence.database.restoreError}`);
|
||||
|
||||
Reference in New Issue
Block a user