简体   繁体   English

将 node.js 作为作业工作者运行时是否需要集群?

[英]is cluster for node.js required when running it as a job worker?

Do we need cluster module for a node.js script which just fetches some job from gearman server or from a rest api like in AWS SQS and performs it?我们是否需要用于 node.js 脚本的集群模块,该脚本只是从齿轮服务器或像 AWS SQS 中的 rest api 获取一些作业并执行它?
What i know is that, cluster is more useful in case of socket sharing (ex listening on a port) like in a web server.我所知道的是,集群在套接字共享(例如侦听端口)的情况下更有用,例如在 Web 服务器中。
PS: I am already using monit to monitor and restart these daemon process in case of a crash and in future planning to use pm2 (in non cluster mode, ie without -i flag). PS:我已经在使用 monit 来监视和重新启动这些守护进程,以防万一崩溃,并且将来计划使用 pm2(在非集群模式下,即没有 -i 标志)。

No, you do not have to use the cluster module in order to service multiple operations from some sort of work queue.不,您不必使用集群模块来为某种工作队列中的多个操作提供服务。 You should use the cluster module when it's specific features match up well with the type of work you are doing (load balancing multiple incoming connections).当其特定功能与您正在执行的工作类型(负载平衡多个传入连接)匹配时,您应该使用 cluster 模块。

In fact, if the operations to be done are mostly asynchronous things (such as sending an update to an external database), you may not even need multiple processes.事实上,如果要做的操作大多是异步的事情(比如向外部数据库发送更新),你甚至可能不需要多个进程。 But, if you do need multiple processes, then you can use the various options in the process module to start other work processes to carry out individual tasks and use the main central server to monitor and coordinate these other processes.但是,如果您确实需要多个流程,那么您可以使用process模块中的各种选项来启动其他工作流程来执行单独的任务,并使用主中央服务器来监视和协调这些其他流程。 This is part of what the cluster module does, but it's use is more specialized than just something that starts other external processes that you could code yourself.这是 cluster 模块所做的一部分,但它的用途更专业,而不仅仅是启动您可以自己编码的其他外部进程的东西。

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

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