Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fastest way to connect node.js process with java/scala code

I have a computation library implemented with java/scala. And I also have a little of node.js code serving my application. I need to find a way how to connect this 2 worlds with maximum performance, but also simplicity in mind. I was thinking about inter process communication via shared memory, but don't find any mature way to do that in node.js

This should work mostly as a proxy mechanism to call some java (ideally any) code from node.js code. From node.js to java side it will be only request metadata passing, however from java to node.js sometime it could be significant data returned (let's say 100-200 kb as upper border, and around 600-1000 bytes in 90% of the cases) However amount of that's request could be significant.

Think OpenMP could be an option, but also can't find any openmp protocol implementation for Node. However there is also no clear project for java as well.


Looks like for the current moment there is several alternatives:

  1. Native extension + Java Unsafe (currently extracted via reflection, should be opened in JDK 9) and using shared memory in C/C++ based env (need investigation and development. Looses for Node -> c -> Java could be higher than shared memory benefits)
  2. Use socket (quite fast on linux, not sure about Windows, crossplatform)
  3. FastCGI (still use sockets transfering inside, so will be slower than 1 option)
  4. ZeroMQ/Nanomessage as transport layer (again socket inside, but simplified development)
  5. @David's answer. However can't say anything specific about it. Investigation needed.
like image 735
Ph0en1x Avatar asked Nov 04 '15 14:11

Ph0en1x


People also ask

Which is faster NodeJS or Java?

Speed of CodingNode. js is known for its flexibility and so, fast in development. Yet, Java is the exact opposite of Node. js since the first technology takes much more time to develop due to being a rigid language (though, Java may save time in the long term in some cases).

What makes NodeJS faster?

The virtual machine in Node. js (V8), which is responsible for executing JavaScript, is compiled using JIT. At runtime, the virtual machine can take the source code and compile it into machine code. This means that all frequently used “hot” functions can be compiled to machine code, which speeds up execution.

Can we integrate NodeJS with Java?

Combining Node and the JVM The Node. js core modules have also been compiled in. Running Node. js on the JVM provides an easy migration path for anyone with a large Java stack who wishes to start using Node.


1 Answers

Well, if sockets are too slow for you, why not keep it in-process?

You could try:

  1. running your unmodified Node.js scripts on Nodyn which in turn runs on DynJS on the JVM; -or-
  2. if you've not particular to the Node.js stack, but like the idea of extreme-wait-free throughput on the JVM, code it all up in vert.x.

Note: An alternative to Nodyn/DynJS would have been the Avatar.js project, which uses Nashorn, which in turn is shipped with recent JVM's and uses the latest and greatest bytecode operators. However in late 2015 the Avatar.js project feels abandoned. :-\

like image 63
David Bullock Avatar answered Oct 15 '22 14:10

David Bullock