I created a worker using the worker_threads. Like this:
const WorkerThreads = require('worker_threads');
const worker = new WorkerThreads.Worker('./path/to/a.js');
if (countMemory(worker) > 100 * 1024 * 1024) {
worker.terminate();
}
function countMemory(worker) {
// some code I don't know
}
And I knew that the ./path/to/a.js
has a little bit memory leak, so I have to destory the Worker when it leak a lot. How can I get how many memory did the Worker use?
You can use process.memoryUsage to get the info from all the threads. Check this question. I think you can use the same approach for worker_threads