如何保留共享节点集群中所有节点进程的变量? [英] how to keep variables that share all node processes in node cluster?

查看:100
本文介绍了如何保留共享节点集群中所有节点进程的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎所有节点woker进程都在运行,就像它正在执行同一应用程序的新副本一样。但是希望保留节点集群中所有节点工作者(子进程)共享的一些变量。有一个简单的方法吗?

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 node workers (child processes) in node cluster. Is there a simple way to do this?

推荐答案

所有工作进程确实是应用程序的新副本。每个worker都是使用child_process.spawn创建的全功能进程。
所以不,他们不共享变量。这可能是最好的方式。
如果您想在工作进程(通常是会话)之间共享信息,您应该考虑将这些信息存储在数据库中。

All worker processes are indeed new copies of your application. Each worker is a full featured process created with child_process.spawn. So no, they don't share variables. And it's probably best this way. If you want to share information between worker processes (typically sessions) you should look into storing these information in a database.

如果您准备好了从节点开始,您可以使用 dnode 之类的工具让您的工作人员向主进程请求数据。

If you're ready to go node all the way, you could use something like dnode to have your workers ask the master process for data.

这篇关于如何保留共享节点集群中所有节点进程的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆