简体   繁体   English

如何将更快的语言与Express.js后端集成在一起?

[英]How can I integrate a faster language with an Express.js backend?

Some background: I'm currently working on a website that runs on an Azure server. 一些背景:我目前正在一个在Azure服务器上运行的网站上工作。 It's essentially a weird MEAN stack, in that the MongoDB portion is replaced with DocumentDB, Azure's native NoSql DB. 本质上,这是一个奇怪的MEAN堆栈,其中MongoDB部分已被Azure的本机NoSql DB DocumentDB取代。

The site's output requires a lot of constant number crunching, and as the site grows, JavaScript is proving to be too slow. 网站的输出需要进行大量的常数运算,并且随着网站的发展,JavaScript变得太慢了。 So, 所以,

  1. If I use node-gyp to compile C++ into Javascript , does the code ultimately run as Javascript, and detract from the speed benefits of using C++? 如果我使用node-gypC ++编译为Javascript ,那么代码是否最终会以Javascript运行,并且降低了使用C ++的速度优势?

  2. Is Java a viable alternative as a computing workhorse? Java是否可以替代计算主力? This is in terms of compute speed, memory usage, and having to communicate with Javascript. 这是从计算速度,内存使用情况以及必须与Javascript进行通信的角度来看的。

Some additional info: 一些其他信息:

  • The website is constantly pulling information from a chrome plugin, and feeding it into the number cruncher. 该网站不断从chrome插件中获取信息,并将其提供给号码处理程序。
  • The values being evaluated encompass floating point numbers, integers, strings, and booleans, and are coming from both the DB and running values, as well as writing to the DB. 被评估的值包括浮点数,整数,字符串和布尔值,并且来自数据库和运行值,以及写入数据库。

PS Please don't suggest C# instead of Java. PS:请不要建议使用C#而不是Java。 I know it's been integrated into Azure very nicely, but I don't use it, and haven't the time to learn right now. 我知道它已经很好地集成到了Azure中,但是我不使用它,并且现在没有时间学习。

Edit: Asking a better question. 编辑:问一个更好的问题。

NodeJS uses an event-driven, single process/thread model. NodeJS使用事件驱动的单进程/线程模型。 It is not suitable for CPU denseness computation. 它不适用于CPU密度计算。 When you have a number cruncher cost a lot of cpu time in an event request, the event-loop of Node will be blocked. 当事件处理程序中的数字处理程序花费大量cpu时间时,Node的事件循环将被阻止。

So if you need to do CPU denseness computation, I think you can use Node API 'child_process.spawn' to fork a child process as worker to do it. 因此,如果您需要进行CPU密度计算,我认为您可以使用Node API'child_process.spawn'派生一个子进程作为工作人员。 You can refer to https://nodejs.org/api/child_process.html . 您可以参考https://nodejs.org/api/child_process.html

There is some simple libraries for NodeJS to do better than API "child_process". 有一些简单的库可以使NodeJS比API“ child_process”更好。

  1. node-compute-cluster: Distributing computation across multiple processes https://github.com/lloyd/node-compute-cluster node-compute-cluster:在多个进程之间分布计算https://github.com/lloyd/node-compute-cluster
  2. neuron: The simplest possible event driven job manager, FIFO queue, and "task based cache" https://github.com/flatiron/neuron 神经元:最简单的事件驱动的作业管理器,FIFO队列和“基于任务的缓存” https://github.com/flatiron/neuron

If you just need a backend job, I recommend to use WebJob & ServiceBus on Azure. 如果您只需要后端工作,则建议在Azure上使用WebJob和ServiceBus。 Please refer to https://azure.microsoft.com/en-us/documentation/articles/web-sites-create-web-jobs/ and https://azure.microsoft.com/en-us/documentation/articles/service-bus-nodejs-how-to-use-queues/ . 请参考https://azure.microsoft.com/en-us/documentation/articles/web-sites-create-web-jobs/https://azure.microsoft.com/en-us/documentation/articles/ service-bus-nodejs如何使用队列/

Certainly, you can use Java( Java WebJob on Azure) as a computing workhorse and use ServiceBus on Azure to communicate with NodeJS. 当然,您可以将Java(Azure上的Java WebJob)用作计算工具,并在Azure上使用ServiceBus与NodeJS进行通信。

If you need a lot of number computation, I think Python with NumPy may be the best language choice. 如果您需要大量的数字计算,我认为带有NumPy的Python可能是最佳的语言选择。

If you need some realtime performance requirement, you need to add more instances to scale up the node service per my experience. 如果您需要一些实时性能要求,那么根据我的经验,您需要添加更多实例以扩展节点服务。

Best Regards. 最好的祝福。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM