diff --git a/deploy/clowdapp.yml b/deploy/clowdapp.yml index 0c4f086..b2700f7 100644 --- a/deploy/clowdapp.yml +++ b/deploy/clowdapp.yml @@ -110,3 +110,6 @@ parameters: - description: Retention time span for pdf in MS (8 hours default) name: ENTRY_TIMEOUT value: "28800000" +- description: Amount of worker threads that puppeteer-cluster will use + name: MAX_CONCURRENCY + value: 2 diff --git a/src/common/pdfCache.ts b/src/common/pdfCache.ts index ce26de9..f14835f 100644 --- a/src/common/pdfCache.ts +++ b/src/common/pdfCache.ts @@ -154,8 +154,13 @@ class PdfCache { return []; } - // Function to sort PDFComponents by order + // Sort the components by their internal `order` and + // return the sorted components in ascending order private sortComponents(components: PDFComponent[]): PDFComponent[] { + // No point in sorting a slice of length 1 + if (components.length < 2) { + return components; + } return components.slice().sort((a, b) => { const orderA = a.order || Number.MAX_VALUE; const orderB = b.order || Number.MAX_VALUE; @@ -163,6 +168,7 @@ class PdfCache { return orderA - orderB; }); } + private updateCollectionState( collectionId: string, status: PdfStatus, diff --git a/src/server/cluster.ts b/src/server/cluster.ts index b8aa5a5..9299599 100644 --- a/src/server/cluster.ts +++ b/src/server/cluster.ts @@ -5,9 +5,10 @@ const BROWSER_TIMEOUT = 60_000; import { CHROMIUM_PATH } from '../browser/helpers'; export const GetPupCluster = async () => { + const CONCURRENCY_DEFAULT = 2; const cluster = await Cluster.launch({ concurrency: Cluster.CONCURRENCY_CONTEXT, - maxConcurrency: 3, + maxConcurrency: Number(process.env.MAX_CONCURRENCY) || CONCURRENCY_DEFAULT, // If a queued task fails, how many times will it retry before returning an error retryLimit: 2, puppeteerOptions: {