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
我有一个用java / scala实现的计算库。我还有一些node.js代码服务于我的应用程序。我需要找到一种方法,如何以最大的性能连接这2个世界,同时还要考虑简单性。我正在考虑通过共享内存进行进程间通信,但是在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.
这应该主要作为代理机制从node.js代码调用一些java(理想情况下是任何)代码。从node.js到java方面,它只是请求元数据传递,但是从java到node.js有时它可能会返回重要的数据(假设100-200 kb为上边界,大约600-1000字节为90%)案件)然而,这个请求的数量可能很大。
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.
认为OpenMP可能是一个选项,但也找不到Node的任何openmp协议实现。但是,对于java也没有明确的项目。
Looks like for the current moment there is several alternatives:
看起来目前的时刻有几种选择:
- 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)
- Use socket (quite fast on linux, not sure about Windows, crossplatform)
- FastCGI (still use sockets transfering inside, so will be slower than 1 option)
- ZeroMQ/Nanomessage as transport layer (again socket inside, but simplified development)
- @David's answer. However can't say anything specific about it. Investigation needed.
原生扩展+ Java不安全(目前通过反射提取,应该在JDK 9中打开)并在基于C / C ++的env中使用共享内存(需要调查和开发。节点的松散 - > c - > Java可能高于共享内存的好处)
使用socket(在linux上相当快,不确定Windows,跨平台)
FastCGI(仍然使用套接字在内部传输,因此将慢于1个选项)
ZeroMQ / Nanomessage作为传输层(再次插入内部,但简化了开发)
@大卫的回答。但是不能说具体一点。需要调查。
1 个解决方案
#1
1
Well, if sockets are too slow for you, why not keep it in-process?
好吧,如果套接字对你来说太慢了,为什么不把它保持在进程中呢?
You could try:
你可以尝试:
- running your unmodified Node.js scripts on Nodyn which in turn runs on DynJS on the JVM; -or-
- 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.
在Nodyn上运行未经修改的Node.js脚本,然后在JVM上运行DynJS; -要么-
如果您没有特定于Node.js堆栈,但是就像JVM上极端等待吞吐量的想法一样,请在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. :-\
注意:Nodyn / DynJS的替代方案是Avatar.js项目,该项目使用Nashorn,而Nashorn又附带最新的JVM并使用最新和最好的字节码运算符。然而,在2015年底,Avatar.js项目感到被遗弃。 : - \
#1
1
Well, if sockets are too slow for you, why not keep it in-process?
好吧,如果套接字对你来说太慢了,为什么不把它保持在进程中呢?
You could try:
你可以尝试:
- running your unmodified Node.js scripts on Nodyn which in turn runs on DynJS on the JVM; -or-
- 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.
在Nodyn上运行未经修改的Node.js脚本,然后在JVM上运行DynJS; -要么-
如果您没有特定于Node.js堆栈,但是就像JVM上极端等待吞吐量的想法一样,请在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. :-\
注意:Nodyn / DynJS的替代方案是Avatar.js项目,该项目使用Nashorn,而Nashorn又附带最新的JVM并使用最新和最好的字节码运算符。然而,在2015年底,Avatar.js项目感到被遗弃。 : - \