How to utilize cluster processing on loops?

我们两清 提交于 2019-12-12 02:52:28

问题


Okay, I made this example on JSfiddle to mimic (really bad job), of my dilemma: https://jsfiddle.net/Dillybob/7zkL097q/2/

In the cluster module for nodejs, I want to utilize my child workers (processing power) as much as I can to help accomplish and complete my setInterval MonsterLoop faster. In my example above if I were to run that code inside my cluster's isWorker block, it would run 6 times every second.

That seems counter-intuitive and would seem like it would use more processing power? And since I'm manipulating that object while looping, I'm sure once another process get's a hold of it, there will be data that becomes undefined? Seems like 6 times every second is just not the right way instead of just once.

So I am trying a different way. I stuck that loop inside the isMaster block instead. This way, it only gets run once every second, but still only utilizes 1 core. Is it possible to have that loop run once, but grab power from the child processes to make it perform faster?

来源:https://stackoverflow.com/questions/32366595/how-to-utilize-cluster-processing-on-loops

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!