问题
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