2

Hi im currently developing a MEAN stack project and i found out the nodejs cluster module which is recommended before you deploy the the project.

I've applied it and done some ApacheBenchmark, the thing is, it's only responding to 1 worker, it's not rotating around my other 7 workers.

I've google about this and yeah windows default can't do round-robin, but is there a way to enable round-robin in windows?

Thank you!

John
  • 470
  • 9
  • 23

1 Answers1

6

In node v4.x and newer you can set the default scheduling policy by setting cluster.schedulingPolicy or by setting the NODE_CLUSTER_SCHED_POLICY environment variable. However, as the documentation describes, round-robin scheduling is disabled by default on Windows for performance reasons.

mscdex
  • 104,356
  • 15
  • 192
  • 153
  • so there's no way to enable round-robin in windows? hmm ok ok.. thanks! – John May 15 '17 at 04:21
  • 1
    @John: FWIW, out of 4 projects where I tried out clustering only one improved performance. The other 3 projects had the same performance (in request per second) regardless of weather clustering is turned on or off. It's not because clustering in node is bad, it's just with async I/O only certain types of app with heavier than usual CPU usage benefit from running on multiple cores. – slebetman May 15 '17 at 04:41
  • I see, thanks slebetman, but it's a best practice to implement the cluster module at the start just in case the project becomes big? – John May 15 '17 at 04:51
  • I've edited my answer to clarify that it's disabled *by default* on Windows. You *should* be able to override it as mentioned. As far as adding `cluster` goes, it's probably only worth looking into either once you've determined you've hit the max I/O throughput for a single process or you have code that does a lot of computations that are CPU bound. Also, introducing clustering later on should be pretty easy because node handles a lot of the complexities transparently, so it's basically just usually a matter of adding a few lines of code. – mscdex May 15 '17 at 06:10