how to keep variables that share all node processes in node cluster?

前端 未结 6 1952
离开以前
离开以前 2021-02-02 12:17

It seems like all the node woker processes are working as if it is executing a new copy of the same application. But would like to keep some variables that are shared by all nod

6条回答
  •  无人共我
    2021-02-02 12:49

    If you're looking to share things on a read-only basis, check out mmap-object. I use it for large in-memory lookup tables.

    Checking just now on a server, a 346M file is taking up a total of 156M of memory (mmap only pages in what's accessed) and mmap-object sharing it among 44 processes for a per-process overhead of 3.5M.

    Because it's read-only I don't have to worry about inter-process locking and the messiness that can bring along.

提交回复
热议问题