简体   繁体   English

Node.js集群

[英]Node.js Cluster

I am writing an application in Node.js which serves dynamic web pages. 我正在Node.js中编写一个提供动态网页的应用程序。 I would like this application to scale over multiple CPU cores, so I have decided to use cluster to create a worker for each CPU core. 我希望这个应用程序可以扩展到多个CPU核心,所以我决定使用集群为每个CPU核心创建一个worker。

I also use a 3rd party API which needs to be polled frequently checking for changes, and often needs to be queried and cached based on user input. 我还使用第三方API,需要经常轮询检查更改,并且通常需要根据用户输入进行查询和缓存。 As there are rate limits on this API, I would like to have a single instance of the API and cache between all workers. 由于此API有速率限制,我希望在所有工作者之间有一个API实例和缓存。

What is the best way to share and communicate with a resource (cache and 3rd party API) between multiple workers? 与多个工作人员之间的资源(缓存和第三方API)共享和通信的最佳方式是什么? Should I create a separate worker for the resource, or use the master one? 我应该为资源创建一个单独的工作者,还是使用主工作者?

As there are rate limits on this API, I would like to have a single instance of the API and cache between all workers. 由于此API有速率限制,我希望在所有工作者之间有一个API实例和缓存。

Ideally you would make these API queries from the master and then use process.send to send them to the workers if you want. 理想情况下,您可以从主服务器进行这些API查询,然后使用process.send将它们发送给工作人员(如果需要)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM