add o11y for multiget

This commit is contained in:
darshanime 2026-07-14 17:37:59 +05:30
parent 48babd5495
commit 8ffbcf0559
2 changed files with 53 additions and 14 deletions

29
dist/index.js vendored
View file

@ -41990,8 +41990,9 @@ async function contribute(settings) {
// nothing is extracted into .git directly. // nothing is extracted into .git directly.
async function seedBundle(repoPath, url, refNs) { async function seedBundle(repoPath, url, refNs) {
const tmp = tempBundlePath('seed'); const tmp = tempBundlePath('seed');
const what = refNs === BASE_REFNS ? 'base' : 'branch';
try { try {
await downloadTo(url, tmp); await downloadTo(url, tmp, what);
await exec_exec('git', [ await exec_exec('git', [
'-C', '-C',
repoPath, repoPath,
@ -42150,18 +42151,22 @@ async function hasBaseRefs(repoPath) {
// Download a presigned GET to dest with concurrent HTTP range requests, so the base bundle // Download a presigned GET to dest with concurrent HTTP range requests, so the base bundle
// (tens/hundreds of MiB) transfers at link rate instead of the single-stream ~15 MB/s ceiling. // (tens/hundreds of MiB) transfers at link rate instead of the single-stream ~15 MB/s ceiling.
// Falls back to a single stream when the server doesn't support ranges. // Falls back to a single stream when the server doesn't support ranges.
async function downloadTo(url, dest) { async function downloadTo(url, dest, what) {
const started = Date.now();
const total = await probeRangeSize(url); const total = await probeRangeSize(url);
if (total === null) { if (total === null) {
await downloadSingleStream(url, dest); await downloadSingleStream(url, dest);
const bytes = (await external_fs_namespaceObject.promises.stat(dest)).size;
info(`Mirror download [${what}]: ${fmtSize(bytes)} single-stream, no range support, ${fmtElapsed(started, bytes)}`);
return; return;
} }
const segments = [];
for (let off = 0; off < total; off += SEGMENT_SIZE) {
segments.push([off, Math.min(SEGMENT_SIZE, total - off)]);
}
const width = Math.min(SEGMENT_CONCURRENCY, segments.length);
const fh = await external_fs_namespaceObject.promises.open(dest, 'w'); const fh = await external_fs_namespaceObject.promises.open(dest, 'w');
try { try {
const segments = [];
for (let off = 0; off < total; off += SEGMENT_SIZE) {
segments.push([off, Math.min(SEGMENT_SIZE, total - off)]);
}
let next = 0; let next = 0;
const worker = async () => { const worker = async () => {
for (;;) { for (;;) {
@ -42175,7 +42180,7 @@ async function downloadTo(url, dest) {
} }
}; };
const pool = []; const pool = [];
for (let k = 0; k < Math.min(SEGMENT_CONCURRENCY, segments.length); k++) { for (let k = 0; k < width; k++) {
pool.push(worker()); pool.push(worker());
} }
await Promise.all(pool); await Promise.all(pool);
@ -42183,6 +42188,16 @@ async function downloadTo(url, dest) {
finally { finally {
await fh.close(); await fh.close();
} }
info(`Mirror download [${what}]: ${fmtSize(total)} in ${segments.length} ranged segments ×${width}, ${fmtElapsed(started, total)}`);
}
// Size + elapsed/throughput for the mirror download o11y line.
function fmtSize(bytes) {
return `${(bytes / 1e6).toFixed(1)} MB`;
}
function fmtElapsed(startedMs, bytes) {
const secs = (Date.now() - startedMs) / 1000;
const rate = secs > 0 ? (bytes / 1e6 / secs).toFixed(1) : 'n/a';
return `${secs.toFixed(2)}s (${rate} MB/s)`;
} }
// GET bytes=0-0 to learn the total size and confirm range support; null → not supported. // GET bytes=0-0 to learn the total size and confirm range support; null → not supported.
async function probeRangeSize(url) { async function probeRangeSize(url) {

View file

@ -257,8 +257,9 @@ async function seedBundle(
refNs: string refNs: string
): Promise<void> { ): Promise<void> {
const tmp = tempBundlePath('seed') const tmp = tempBundlePath('seed')
const what = refNs === BASE_REFNS ? 'base' : 'branch'
try { try {
await downloadTo(url, tmp) await downloadTo(url, tmp, what)
await exec.exec('git', [ await exec.exec('git', [
'-C', '-C',
repoPath, repoPath,
@ -442,18 +443,28 @@ async function hasBaseRefs(repoPath: string): Promise<boolean> {
// Download a presigned GET to dest with concurrent HTTP range requests, so the base bundle // Download a presigned GET to dest with concurrent HTTP range requests, so the base bundle
// (tens/hundreds of MiB) transfers at link rate instead of the single-stream ~15 MB/s ceiling. // (tens/hundreds of MiB) transfers at link rate instead of the single-stream ~15 MB/s ceiling.
// Falls back to a single stream when the server doesn't support ranges. // Falls back to a single stream when the server doesn't support ranges.
async function downloadTo(url: string, dest: string): Promise<void> { async function downloadTo(
url: string,
dest: string,
what: string
): Promise<void> {
const started = Date.now()
const total = await probeRangeSize(url) const total = await probeRangeSize(url)
if (total === null) { if (total === null) {
await downloadSingleStream(url, dest) await downloadSingleStream(url, dest)
const bytes = (await fs.promises.stat(dest)).size
core.info(
`Mirror download [${what}]: ${fmtSize(bytes)} single-stream, no range support, ${fmtElapsed(started, bytes)}`
)
return return
} }
const segments: [number, number][] = []
for (let off = 0; off < total; off += SEGMENT_SIZE) {
segments.push([off, Math.min(SEGMENT_SIZE, total - off)])
}
const width = Math.min(SEGMENT_CONCURRENCY, segments.length)
const fh = await fs.promises.open(dest, 'w') const fh = await fs.promises.open(dest, 'w')
try { try {
const segments: [number, number][] = []
for (let off = 0; off < total; off += SEGMENT_SIZE) {
segments.push([off, Math.min(SEGMENT_SIZE, total - off)])
}
let next = 0 let next = 0
const worker = async (): Promise<void> => { const worker = async (): Promise<void> => {
for (;;) { for (;;) {
@ -467,13 +478,26 @@ async function downloadTo(url: string, dest: string): Promise<void> {
} }
} }
const pool: Promise<void>[] = [] const pool: Promise<void>[] = []
for (let k = 0; k < Math.min(SEGMENT_CONCURRENCY, segments.length); k++) { for (let k = 0; k < width; k++) {
pool.push(worker()) pool.push(worker())
} }
await Promise.all(pool) await Promise.all(pool)
} finally { } finally {
await fh.close() await fh.close()
} }
core.info(
`Mirror download [${what}]: ${fmtSize(total)} in ${segments.length} ranged segments ×${width}, ${fmtElapsed(started, total)}`
)
}
// Size + elapsed/throughput for the mirror download o11y line.
function fmtSize(bytes: number): string {
return `${(bytes / 1e6).toFixed(1)} MB`
}
function fmtElapsed(startedMs: number, bytes: number): string {
const secs = (Date.now() - startedMs) / 1000
const rate = secs > 0 ? (bytes / 1e6 / secs).toFixed(1) : 'n/a'
return `${secs.toFixed(2)}s (${rate} MB/s)`
} }
// GET bytes=0-0 to learn the total size and confirm range support; null → not supported. // GET bytes=0-0 to learn the total size and confirm range support; null → not supported.