简体   繁体   中英

Creating resource in nodejs Cluster Master : good or bad?

All examples on node cluster api I have seen so far create express apps (for example) in the worker part.

Is there any reason why one should not create that express app in master and fork after initialization is done ?

The reason I'd like to do this is that at start up I might connect to the database, make some initial changes (say create mongodb collections, save boot status...etc) and having workers do that on their own might lead to duplicate actions on the database.

It may not be wise to put more on cluster master. Node cluster master shares the load to the other processes. If somehow V8 garbage collects on master, it will keep it from sharing the load during the GC. In such a case, there is no point having the cluster. Let master free and do whatever want you to do on workers.

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