I am trying to run some code across multiple CPUs. Each cpu is given some tasks and then they return the result to the main thread which aggregates everything together.
What I don't understand is that whenever I send a message containing a Date Object, that Date Object is converted to a string. It seems ridiculous to have to parse these to dates both in the worker threads and in the main thread. I am working with a lot of dates, so this will have a huge performance hit.
Is there anything I can do to get around this? I am using node version v10.13.0.
const cluster = require('cluster');
if (cluster.isMaster) {
// init cluster
require('os').cpus().forEach(() => {
cluster.fork();
});
// add eventlisteners
Object.values(cluster.workers).forEach(worker => {
worker.on('message', message => {
console.log(typeof message); // string
});
});
} else {
process.send(new Date());
}