In NodeJS, how to share a JS Object amongst children threads?

Viewed 11

I code NodeJS for a long time but I never had to deal with this low level CPU/memory challenges, thus I am bit lost. I read the Node worker_threads module doc. or even tested NPM multithreading modules like piscina and workerpool.

What I want is basically to have a normal JS Object created by a parent thread that is shared (read-only) amongst all children threads. I don't want to clone this JS Object nor even transfer it, I want to share it because this JS Object is huge in terms of size in memory.

That is, in low-level terms, I would say a huge portion of the memory is allocated and set by the parent thread and accesible read-only by all children threads.

Can I achieve that? Can you show me an example?

0 Answers
Related