Advantages of node.js addon vs child_process

不打扰是莪最后的温柔 提交于 2019-12-12 15:13:34

问题


What would be the advantages, if any, of using a node.js addon written in C/C++ compared to calling a binary with arguments through child_process?

More specifically, I have a small program, which accepts possibly up to a few hundred arguments and returns a boolean.


回答1:


There is a huge difference.

C++ Addon is native code which is running as part of main application (on the same level as JS does). But if you use child_process, node will start new process and there is a huge overhead (spawning processes is much more complicated than running native code in one thread).

If you are deciding, which approach to use, it heavily depends on your situation. If you are familiar with C++ and you want to handle thousands of requests, you probably should consider writing an addon. But if you are writing a small app for personal use and your additional program is already functional as stand-alone app, I would use child_process and it can also provide great results with less effort.



来源:https://stackoverflow.com/questions/28267794/advantages-of-node-js-addon-vs-child-process

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