简体   繁体   中英

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?
What i know is that, cluster is more useful in case of socket sharing (ex listening on a port) like in a web server.
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).

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).

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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