简体   繁体   中英

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. It's essentially a weird MEAN stack, in that the MongoDB portion is replaced with DocumentDB, Azure's native NoSql DB.

The site's output requires a lot of constant number crunching, and as the site grows, JavaScript is proving to be too slow. 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++?

  2. Is Java a viable alternative as a computing workhorse? This is in terms of compute speed, memory usage, and having to communicate with Javascript.

Some additional info:

  • The website is constantly pulling information from a chrome plugin, and feeding it into the number cruncher.
  • 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. 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.

Edit: Asking a better question.

NodeJS uses an event-driven, single process/thread model. It is not suitable for CPU denseness computation. When you have a number cruncher cost a lot of cpu time in an event request, the event-loop of Node will be blocked.

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. You can refer to https://nodejs.org/api/child_process.html .

There is some simple libraries for NodeJS to do better than API "child_process".

  1. node-compute-cluster: Distributing computation across multiple processes 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

If you just need a backend job, I recommend to use WebJob & ServiceBus on Azure. 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/ .

Certainly, you can use Java( Java WebJob on Azure) as a computing workhorse and use ServiceBus on Azure to communicate with NodeJS.

If you need a lot of number computation, I think Python with NumPy may be the best language choice.

If you need some realtime performance requirement, you need to add more instances to scale up the node service per my experience.

Best Regards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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