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

I have a calculation library implemented using java / scala. And I also have some node.js code serving my application. I need to find a way to connect these two worlds with maximum performance, but also simplicity. I thought about the interaction between processes through shared memory, but did not find a mature way to do this in node.js

This should work mainly as a proxy mechanism for calling some java code (ideally any) from node.js. From node.js to the java side, this will only be the transfer of request metadata, however, from java to node.js, a significant amount of data can sometimes be obtained (say, 100-200 kb as the upper bound and about 600-1000 bytes in 90% of cases). However, the volume of this request may be significant.

Think that OpenMP may be an option, but also cannot find an implementation of the openmp protocol for node. However, there is also no clear design for java.


It seems that at the moment there are several alternatives:

  • The internal Java + Unsafe extension (currently extracted via reflection, must be open in JDK 9) and the use of shared memory in a C / C ++ -based environment (research and development required. Exceptions for Node -> c -> Java may be higher than benefits shared memory)
  • Use a socket (pretty fast on Linux, not sure about Windows cross-platform)
  • FastCGI (still uses sockets that go inside, so it will be slower than option 1)
  • ZeroMQ / Nanomessage as a transport layer (again a socket inside, but simplified development)
  • @ David answer. However, I can not say anything specific about this. Investigation required.
+6
source share
1 answer

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

You can try:

  • Run your unmodified Node.js scripts on Nodyn , which in turn runs on DynJS on the JVM; -or -
  • if you are not private to the Node.js stack, but like the idea of ​​extreme lifeless bandwidth on the JVM, enter the code in vert.x.

Note An alternative to Nodyn / DynJS was the Avatar.js project, which uses Nashorn , which in turn comes with the recent JVM and uses the latest and greatest bytecode operators. However, at the end of 2015, the Avatar.js project feels abandoned.: - \

+1
source