CPU intensive processing in Node.js application

I have a Node.js web application where I need to do some heavy computing on large matrices. Since Node.js is event driven, I expect this to result in poor performance for my web application. What is the best way to handle the cumbersome processor tasks with Node?

Is it possible to upload calculations to another server built on something like Python?

+7
source share
2 answers

What would you like to do in this case is Addon .

Addons , as described in the Node.js documentation, dynamically linked shared objects. They can provide glue for the C and C ++ libraries.

So, you can write heavy computation in a lower level language (C / C ++) and do it much more efficiently than with JavaScript, no matter how powerful V8 is.

Read the docs on how to use Addons , and I believe that you will find it a fantastic feature of NodeJS.

+8
source share

Yes - you can upload to another server. Just use your usual query methods to publish the data you need to "compute". Since requests are asynchronous, it will not block the normal Node thread. When the request returns, you have the data that you need, and you can make changes at the last minute before pumping it to the client.

Then you can have a "server farm" that handles these things - for example, on EC2 you can create a load balancer, and then just node make a request for this balancer. There is no need to do anything in the node, for example, remember which server was the last, or something like that.

Alternatively, if it is more command line related and does not need scalable scalability, you can use node exec to make a system call, then the callback will be called again with any return.

Whatever you do, do not perform these calculations inside node :) - your expectations are true. This will bomb your speech, as I studied hard a couple of times. Asink is your friend.

+1
source share

All Articles