3
0
Fork 0
mirror of https://code.forgejo.org/actions/cache.git synced 2025-12-25 14:26:57 +00:00

better defaults

This commit is contained in:
Cyril Rohr 2024-02-15 16:00:07 +00:00
parent 8f9e839eda
commit ede15a2f5d
No known key found for this signature in database
GPG key ID: 4F06363B8C22B3B9
13 changed files with 86 additions and 254 deletions

View file

@ -31,6 +31,13 @@ const region =
process.env.AWS_REGION ||
process.env.AWS_DEFAULT_REGION;
const uploadQueueSize = Number(process.env.UPLOAD_QUEUE_SIZE || "4");
const uploadPartSize =
Number(process.env.UPLOAD_PART_SIZE || "32") * 1024 * 1024;
const downloadQueueSize = Number(process.env.DOWNLOAD_QUEUE_SIZE || "8");
const downloadPartSize =
Number(process.env.DOWNLOAD_PART_SIZE || "16") * 1024 * 1024;
export function getCacheVersion(
paths: string[],
compressionMethod?: CompressionMethod,
@ -140,12 +147,12 @@ export async function downloadCache(
const url = await getSignedUrl(s3Client, command, {
expiresIn: 3600
});
const downloadOptions = getDownloadOptions({
await downloadCacheHttpClientConcurrent(url, archivePath, {
...options,
downloadConcurrency: 14,
concurrentBlobDownloads: true
downloadConcurrency: downloadQueueSize,
concurrentBlobDownloads: true,
partSize: downloadPartSize
});
await downloadCacheHttpClientConcurrent(url, archivePath, downloadOptions);
}
export async function saveCache(
@ -176,12 +183,10 @@ export async function saveCache(
Key: s3Key,
Body: createReadStream(archivePath)
},
// Part size in bytes
partSize: 32 * 1024 * 1024,
partSize: uploadPartSize,
// Max concurrency
queueSize: 14
queueSize: uploadQueueSize
});
// Commit Cache
@ -192,9 +197,10 @@ export async function saveCache(
)} MB (${cacheSize} B)`
);
const totalParts = Math.ceil(cacheSize / uploadPartSize);
core.info(`Uploading cache from ${archivePath} to ${bucketName}/${s3Key}`);
multipartUpload.on("httpUploadProgress", progress => {
core.info(`Uploaded ${progress.part}/${progress.total}.`);
core.info(`Uploaded part ${progress.part}/${totalParts}.`);
});
await multipartUpload.done();

View file

@ -6,6 +6,10 @@ import * as fs from "fs";
import { DownloadOptions } from "@actions/cache/lib/options";
import { retryHttpClientResponse } from "@actions/cache/lib/internal/requestUtils";
export interface RunsOnDownloadOptions extends DownloadOptions {
partSize: number;
}
/**
* Class for tracking the download state and displaying stats.
*/
@ -149,7 +153,7 @@ export class DownloadProgress {
export async function downloadCacheHttpClientConcurrent(
archiveLocation: string,
archivePath: fs.PathLike,
options: DownloadOptions
options: RunsOnDownloadOptions
): Promise<void> {
const archiveDescriptor = await fs.promises.open(archivePath, "w");
const httpClient = new HttpClient("actions/cache", undefined, {
@ -185,7 +189,7 @@ export async function downloadCacheHttpClientConcurrent(
promiseGetter: () => Promise<DownloadSegment>;
}[] = [];
const blockSize = 32 * 1024 * 1024;
const blockSize = options.partSize;
for (let offset = 0; offset < length; offset += blockSize) {
const count = Math.min(blockSize, length - offset);