-1

Every single book, tutorial and course out there says that node.js doesn't handle heavy CPU computation very well but I haven't crossed one that suggest any solution.

Do you think it is good idea to deal with said computation problem by writing separate worker in technology that better handles it and consume results from node via - say - REST API?

  • Any suggestions on how to handle this?
  • What is that you usually do?
  • Did somebody already solved this problem?
Ketus
  • 123
  • 1
  • 11
  • 2
    It depends on different factors. node.js isn't good at CPU-heavy work because the event-dispatch model is (effectively) single-threaded - ie. work blocks all other requests. In the simple case this is a 'solved problem' as there *are* multiprocessing/threading modules for node these days; these hide the complexity of 'creating additional threads/processing' and allow consuming the results within node's event-based model. Of course, depending on the cause/scope of the workload, a larger design might need to be considered.. – user2864740 Feb 08 '16 at 19:13
  • See http://stackoverflow.com/questions/22644328/when-is-the-thread-pool-used – user2864740 Feb 08 '16 at 19:15

1 Answers1

1

The main advantages of Node.js as a platform is that it was written from to support asynchronous IO right from the beginning. it is also gives the productivity of JavaScript into Server-side development.

This has being said, since the language has dynamic type system and runtime JIT compililing , specific static-compile time optimization which are extremly helpfull for CPU-bound tasks simply cannot be done.

I initially wrote it as a joke, but when I thought about it again, there is nothing wrong rewiting specific CPU bound tasks in C/C++ and link with the addon mechanism. The platform itself direct to there

further read: https://nodejs.org/api/addons.html

David Haim
  • 25,446
  • 3
  • 44
  • 78