I am trying to pick a right web technology both for I/O heavy and CPU heavy tasks. NodeJs is perfect for handling large load and it also can be scaled out. However, I am stuck with the cpu heavy part. Is it possible to integrate another technology (e.g. Java) into node, so that I will have it running my algorithms in other threads and then use the results again in node. Is there any existing solution? Any other suggestions will be very good.
-
2Easiest thing to do is test it out and see how various technologies perform against your requirements. Also keep in mind that infrastructure is not as expensive as it was 10 years ago. Spinnning up new server instances to support load is trivial these days. – Mahesh Guruswamy Aug 02 '13 at 13:39
-
1Why choose some other technology, when you can outsource the cpu-heavy JS code to another thread? Check out threads-a-gogo https://github.com/xk/node-threads-a-gogo and other nodejs threading tools :) – randunel Aug 02 '13 at 14:35
-
Thanks a lot guys, the nodejs threading tools seems what I was looking for. I will try that for sure. :) – gev Aug 02 '13 at 15:11
-
2You could also look into native c++ extensions. A lot of use cases that would run better in Java than Node, C++ will run even better than Java. http://syskall.com/how-to-write-your-own-native-nodejs-extension/index.html/ – MobA11y Aug 02 '13 at 17:20
4 Answers
You can intergrate NodeJS with Java using node-java.

- 13,813
- 7
- 53
- 71
-
Hi is this module still in maintained? no publish or commit for over a year . . . – Tornike Shavishvili Oct 21 '22 at 07:53
As mentioned in a previous answer, you can use node-java which is an npm module that talks to Java. You can also use J2V8 which wraps Node.js as a Java library and provides a Node.js API in Java.

- 2,490
- 2
- 20
- 28
-
1Thanks for the answer. The question was asked 3 years ago. Current conclusion: the message brokers like rabbit mq, or kafka (as a distributed solution) can actually help to avoid doing these kinds of integrations. Also, the computationally heavy tasks can be delegated to specialized modules like apache spark. In general, at this stage, lambda architecture is the answer to the question I believe. – gev Aug 26 '16 at 09:19
-
On what Java version does J2V8 runs? What's the minimum Java version requirements? – dryleaf Oct 09 '18 at 02:34
The answer is lambda architecture.
NodeJs is nice by itself - handling fast queries in a lightweight manner, not doing any extra computations on data.
The CPU heavy tasks can be easily delegated to specialized components based on JVM (well, the most famous ones are on JVM). This is nicely implemented by using message brokers and microservices.
An event-based architecture, where nodejs can be hooked up to databases like Cassandra or Mongodb and cluster computing frameworks like Apache Spark (not necessarily, though, it depends on the problem) to handle the cpu-heavy parts of the system. And lightweight containers add an icing to the cake by providing nice isolated runtime environments for each of the components to live in.
That's my conclusion so far regarding this question. I think the suggestions above sort of eliminate the need to wrap node under java or other JVM based solution for cpu-heavy tasks.

- 170,088
- 45
- 397
- 571

- 215
- 1
- 2
- 7
NodeJS is based on the v8 javascript engine which is written in c++.
It is therefore possible to write fully native addons in c++ for NodeJS. Check out some of these resources:

- 565
- 5
- 19