Getting Started
A walkthrough of the worker.js and testbatch.js pattern for the VIESUS Node.js module — worker thread pool, batch processing, and GPU scaling.
The module uses a worker thread pool pattern. The main thread dispatches enhancement jobs to a pool of workers; each worker holds one persistent MyViesusObject instance initialized with your GUID.
The two files you need
worker.js
Each worker thread initializes VIESUS once on startup and then processes jobs as they arrive:
const { parentPort, workerData } = require('worker_threads');
const viesus = require('viesus');
// Initialize once — workerData is the GUID passed from the pool
const viesusObj = new viesus.MyViesusObject(workerData);
parentPort.on('message', (job) => {
const result = viesusObj.Enhance(
job.fromPath, // input image — absolute path
job.toPath, // output image — absolute path
job.iniPath, // viesusini.json — absolute path
job.resPath // result JSON — absolute path
);
// result > 0: processing time in ms
// result < 0: error code (see API Reference)
parentPort.postMessage(result);
});testbatch.js
The main thread creates the pool and dispatches all images in a folder:
Running the batch
Each line of output is either OK <ms>: <path> (success) or ERR <code>: <path> (failure).
Scaling to multiple GPUs
To use GPU acceleration, set nGPUs to the number of available NVIDIA GPUs. The pool is then limited to that count — one worker per GPU:
One worker per GPU avoids VRAM contention. Running more workers than GPUs does not improve throughput and may cause OOM errors on the GPU.
Express server integration example
This pattern integrates the pool into an Express upload endpoint:
Pass the GUID as an environment variable — don't hardcode it:
Last updated
Was this helpful?
