Skip to content

Commit 1e7e2b5

Browse files
committed
add max workers cfg
1 parent 9223f85 commit 1e7e2b5

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

packages/cubejs-backend-shared/src/env.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,12 @@ const variables: Record<string, (...args: any) => any> = {
196196
nativeOrchestrator: () => get('CUBEJS_TESSERACT_ORCHESTRATOR')
197197
.default('false')
198198
.asBoolStrict(),
199-
workerThreadsTranspilation: () => get('CUBEJS_WORKER_THREADS_TRANSPILATION')
199+
transpilationWorkerThreads: () => get('CUBEJS_TRANSPILATION_WORKER_THREADS')
200200
.default('false')
201201
.asBoolStrict(),
202+
transpilationWorkerThreadsCount: () => get('CUBEJS_TRANSPILATION_WORKER_THREADS_COUNT')
203+
.default('0')
204+
.asInt(),
202205

203206
/** ****************************************************************
204207
* Common db options *

packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,19 @@ export class DataSchemaCompiler {
9494
const errorsReport = new ErrorReporter(null, [], this.errorReport);
9595
this.errorsReport = errorsReport;
9696

97-
if (getEnv('workerThreadsTranspilation')) {
98-
this.workerPool = workerpool.pool(path.join(__dirname, 'transpilers/transpiler_worker'));
97+
if (getEnv('transpilationWorkerThreads')) {
98+
const wc = getEnv('transpilationWorkerThreadsCount');
99+
this.workerPool = workerpool.pool(
100+
path.join(__dirname, 'transpilers/transpiler_worker'),
101+
wc > 0 ? { maxWorkers: wc } : undefined,
102+
);
99103
}
100104

101105
const transpile = async () => {
102106
let cubeNames;
103107
let cubeSymbolsNames;
104108

105-
if (getEnv('workerThreadsTranspilation')) {
109+
if (getEnv('transpilationWorkerThreads')) {
106110
cubeNames = Object.keys(this.cubeDictionary.byId);
107111
// We need only cubes and all its member names for transpiling.
108112
// Cubes doesn't change during transpiling, but are changed during compilation phase,
@@ -119,16 +123,8 @@ export class DataSchemaCompiler {
119123
),
120124
);
121125
}
122-
// const results = await Promise.all(toCompile.map(f => this.transpileFile(f, errorsReport, { cubeNames, cubeSymbolsNames })));
123-
const results = [];
124-
for (const f of toCompile) {
125-
const result = await this.transpileFile(f, errorsReport, { cubeNames, cubeSymbolsNames });
126-
if (result) {
127-
results.push(result);
128-
}
129-
}
130-
// return results.filter(f => !!f);
131-
return results;
126+
const results = await Promise.all(toCompile.map(f => this.transpileFile(f, errorsReport, { cubeNames, cubeSymbolsNames })));
127+
return results.filter(f => !!f);
132128
};
133129

134130
const compilePhase = async (compilers) => this.compileCubeFiles(compilers, await transpile(), errorsReport);
@@ -189,7 +185,7 @@ export class DataSchemaCompiler {
189185

190186
async transpileJsFile(file, errorsReport, { cubeNames, cubeSymbolsNames }) {
191187
try {
192-
if (getEnv('workerThreadsTranspilation')) {
188+
if (getEnv('transpilationWorkerThreads')) {
193189
const data = {
194190
fileName: file.fileName,
195191
content: file.content,

0 commit comments

Comments
 (0)