How to perform intensive node.js computations

十年热恋 提交于 2019-12-24 04:09:27

问题


I am working on an e-commerce app that has to re-calculate pricing for products every time products are sent from the server to the client (up to thousands of products are sent each time). The calculation piece itself is fairly intensive since it requires multiple database queries to calculate. My naive solution is to abstract the calculation part onto another node.js app/server that is solely dedicated to calculations. Does anyone know of a better or more scalable/optimal way to do this?

Thanks in advance!


回答1:


Defer the computation-heavy task to a dedicated node app is a good idea but beware that this app event loop will be blocked as well and won't be able to serve multiple request in parallel neither.

You will still have to spawn a dedicated process for the computation with either using cluster or child_process.spawn()).

There is a fairly old but still good article about the different possible approaches.



来源:https://stackoverflow.com/questions/40264313/how-to-perform-intensive-node-js-computations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!