Files
anonymous_github/test/fixtures/performance-streamer.js
T
Thomas Durieux 6434337923 perf: bound request work and resource usage (#866)
* perf: bound request work and resource usage

* fix: address performance review regressions

* fix: guard content expiration and dashboard state

* fix: tolerate cache outages and retire derived paths

* fix: revalidate expiration claims and status pagination

* fix: retry interrupted repository metadata cleanup

* fix: retire obsolete content cache storage

* fix: activate tree metadata and recheck expiration claims

* fix: fence cache publication across expiration

* fix: recover staged trees and enforce cache lifecycle cleanup

* fix: prune expired transforms during database outages

* fix: finish conference removals and reload expiration candidates
2026-10-08 03:38:19 +01:00

43 lines
2.0 KiB
JavaScript

const { Readable } = require("node:stream");
const path = require("node:path");
const compiled = process.env.PERFORMANCE_STREAMER_COMPILED === "1";
if (!compiled) require("ts-node/register/transpile-only");
const base = path.join(__dirname, compiled ? "../../build" : "../../src");
const GitHubStream = require(path.join(base, "core/source/GitHubStream")).default;
const FileSystem = require(path.join(base, "core/storage/FileSystem")).default;
const maintenance = require(path.join(base, "core/temporary-storage"));
const startMaintenance = maintenance.startTemporaryStorageMaintenance;
// Exercise the real startup/timer wiring without waiting a production minute.
maintenance.startTemporaryStorageMaintenance = () => startMaintenance(25);
GitHubStream.prototype.downloadWithFallback = async function () {
process.send({ download: true });
return Readable.from([Buffer.alloc(300000, "x")]);
};
const write = FileSystem.prototype.write;
let release, releaseConnection;
if (process.env.PERFORMANCE_HOLD_CONNECT === "1") {
const database = require(path.join(base, "server/database")), connect = database.connect;
database.connect = async (...args) => {
const held = new Promise(resolve => { releaseConnection = resolve; });
process.send({ connectionHeld: true }); await held;
return connect(...args);
};
}
FileSystem.prototype.write = async function (...args) {
if (args[1].endsWith("/hold.txt")) {
const held = new Promise(resolve => { release = resolve; });
process.send({ held: true }); await held;
}
return write.apply(this, args);
};
if (process.env.CREDENTIAL_KEYS !== "invalid") process.on("message", message => {
if (message === "release") release?.();
if (message === "connect") releaseConnection?.();
if (message === "inspect") {
const options = require("mongoose").connection.getClient().options;
process.send({ connected: require(path.join(base, "server/database")).isConnected,
maxPoolSize: options.maxPoolSize, minPoolSize: options.minPoolSize });
}
});
require(path.join(base, "streamer/index"));