Performance of nodejs-opencv - node.js

I have got a use case in which I have to do image search in node JS application. I have image hash stored in database, so I need to calculate hash in nodeJS application. I may have more computer vision use cases in future. I came across nodejs-opencv module, but none of the blogs talk about its performance. As nodeJS is not supposed to be used for CPU intensive tasks and computer vision algorithms may need heavy processing I am not sure how well it will scale. Has someone used it in production and provide some details ?

Which nodejs OpenCV library are you talking about? If you pick one that provides javascript bindings from a native node module then you will have the same performance as with C++. I am currently working on an OpenCV 3.x native node addon to use OpenCV with javascript and can tell you that there is really no difference in performance. However there are also implementations in pure javascript without the need of setting up the OpenCV c++ library on your server or local system but most of the CV tasks will be significantly slower if implemented in javascript as you already guessed.

The most performant way to use computer vision in NodeJS project is move the calculations into C++ codespace (native addon) and apply Workers for multithreading

Related

Node native add-on, dependent on V8

I’m in the early design phases of an application and trying to reason about expectations and requirements, to make sure I don’t spend substantial time down a dead-end. I’ve never worked with V8 or node native add-ons, so bear with me.
Suppose I were building an Electron application. For performance reasons some functionality would be written in native code in an independent library, which would be invoked from a native Node add-on. The native library needs to execute JavaScript. So:
Electron App -> Native add-on -> Native library -> V8
First, is this feasible? For example, will trying to construct/run a V8 context fail due to its execution inside an Electron V8 context? I’m thinking deadlocks, aborts, etc.
I've come up with my plan-of-action from comments to the main question. Unfortunately that makes it hard to credit any specific user or comment for the answer. Specifically:
Restructure the data flow. Allow the Native Add-on to use its copy of V8 to execute any necessary JavaScript, instead of introducing it as a dependency to the Native Library. (comment)
Entering a separate V8 Isolate within another is supported. (comment) (docs)
The Native Library component was conceived because the document type to be supported is large (file-size) and needs JavaScript processing and expensive rendering. Initially I had conceived this to be one large monolithic library for supporting the document type, but in actuality it can be (and probably should be) broken up.
Parsing the binary file. Due to V8's speed, this can probably be done in my Node.js app itself, and may be faster than marshaling data across language barriers. If not, I may consider an N-API Native Add-on for parsing the document and returning a JS object representing the parsed data. (comment)
Executing document-level JavaScript. This should be doable in a Native Add-on by entering a separate V8 Isolate. (See above.)
Rendering the document to a canvas/bitmap. This is an unknown as it is dictated by drawing performance consisting of complex paths, etc. I will probably try to do this directly in the Node.js app first, and if it isn't performant enough then I will consider something like an N-API Native Add-On with e.g. Skia as a dependency to render the data.

node-opencv npm - will it do multithreaded calculations even though node is single threaded?

Can a node.js implementation of openCV exploit multithreaded capable hosts and/or Nvidida GPUs?
I'm new to Node JS and noticed there is are openCV bindings.
I've done a little bit of openCV for a uni project and was interested in using node.js for image processing.
Node is single threaded and I believe openCV leverages multicores especially if they are Nvidia GPUs?
JavaScript is single threaded, nodejs is not. There are nodejs bindings to the OpenCV C++ library, meaning you basically get all the performance benefits of OpenCV, just use it with a Javascript API.
You get multithreading out of it, if the bindings provide async methods via AsyncWorkers. You can give my npm package opencv4nodejs a try, which provides an async API, that makes multithreading pretty simple via Promises.
For GPU acceleration OpenCV has different modules, with a seperate API, as you probably know. In case you wanted to use this API with nodejs, one would have to come up with bindings for that as well.

Node.js and MPI (Message Passing Interface)

Are there any javascript libraries for MPI? I am new to MPI and am learning about intensive parallel processing. We have a supercomputer at school that we are using that only uses MPI and I was wondering if I could code my programs using Node.js instead of c++.
Thanks.
A quick search on NPM doesn't reveal anything interesting, so my guess is that it does not exist yet.
However, you can use native libraries with http://nodejs.org/api/addons.html.
You can also use node-ffi, which sometimes makes things even simpler.
I know this answer is coming too in April 2019... But for future use and people interested in this topic:
Option 1: You can use Node.js Cluster API (https://nodejs.org/api/cluster.html) to mimic or implement simple MPI functions e.g. send, receive, rank, etc.. and much more advanced functions depending on your programming prowess in Node.js.
Option 2: You can also use the following Node.js' MPI library, which implements some of MPI functionalities. The library is available in NPM registry:
mpi-node - https://www.npmjs.com/package/mpi-node
I recently created klyng, a message-passing distributed computing framework for Node.js influenced by MPI. You can consider it (for now) a small implementation of the MPI Standards in javascript.
There seems to be one now. It seems to be becoming a popular standard in most languages.
Here's one web site:
https://www.npmjs.com/package/mpi-node

Why isn't Node.js compiled before runtime?

My understanding of the technology is that it is compiled on the fly into assembly. On the speed spectrum it is slower than Java but faster than Ruby and Python. On the client side an interpreter makes sense but on the server side my first thought is that compilation prior to running, or at least having the option to do so, is an optimal architecture. If the JavaScript was pre compiled in this way would it run faster than Java? Or is it something to do with weakly typed languages which means that JavaScript will always be slower than Java?
Some of Node.js is C++ and is pre-compiled. My understanding though is that there was an effort to keep as much of it in Javascript as possible, but where performance was poor then C++ was used.
Node.js would not be possible without the V8 JavaScript Engine, which is what compiles the javascript. This engine is well-known for being extremely fast. It was built for the Chrome browser, but the performance pays off in Node.js too.
Regarding performance of Node.js, as a web server it is at least on a par with the other leading web servers like Apache+PHP. So performance is not an issue in the common use case. That said, there are faster technologies. Erlang based servers are known for being faster under concurrent loads (interestingly, Erlang is also a dynamically typed language).
For pure number crunching cpu/gpu intensive tasks, Node.js is not a good choice, unless you temper it with Fabric Engine, in which case it can be on a par with C++.
There are a couple of projects that are currently exploring speed issues with JavaScript:
Dart - http://www.dartlang.org/support/faq.html. (Its not just about speed but that is part of it).
Node Native - https://github.com/d5/node.native/

Is using Node.js or Ringojs safe for live websites?

As stated in the title, I would like to know if it's safe to develop a website using one of the actuals "omg" platforms that are Node.js and Ringo.js at their actual version.
Also, I would like to know if they support cookies/sessions and how do they deals with multi-fields post (fieldname[] in PHP).
Thank you
--Edit--
Thanks for all the links guys.
What can you tell me about Ringojs ?
Since I haven't figured which platform to start playing with. I must admit that the fact it can use Java seamlessly really impress me. The only available XSLT 2.0 library is in Java. I could use it as a templating system.
Is there anyone who had the chance to play with Ringojs?
From my experience using both, Ringo is more stable and "safer" for production use but you can comfortably deploy both. In addition to the ability to wrap existing Java libraries that you mention, you also get the benefit of being able to run it in an existing webapp container which manages the lifecycle of the application for you and ensures its availability.
That being said, it doesn't have to be an either or decision. By using my common-node package and assuming you don't use any Java libraries, it's perfectly feasible to maintain a project that runs on both without any changes to the code.
I've also included benchmarks that test the performance of Node.js vs. RingoJS the results of which you can find in the common-node/README.md. To summarize: RingoJS has slightly lower throughput than Node.js, but much lower variance in response times while using six times the RAM with default Java settings. The latter can be tweaked and brought down to as little as twice the memory usage of Node with e.g. my ringo-sunserver but at the expense of decreased performance.
Node.js is stable, so yes it's safe to use. Node.js is capable of handling cookies, sessions, and multiple fields but are not as easy to manage. Web frameworks solve this problem.
I recommend Express.js, it's an open-source web framework for Node.js which handles all of this and more.
You can download it here:
https://github.com/visionmedia/express
I hope this helped!
Examples of some of the bigger sites running Node.js
https://www.learnboost.com/
http://ge.tt/
https://gomockingbird.com/
https://secured.milewise.com/
http://voxer.com/
https://www.yammer.com/
http://cloud9ide.com/
http://beta.etherpad.org/
http://loggly.com/
http://wordsquared.com/
Yes. It is. https://github.com/joyent/node/wiki/Projects,-Applications,-and-Companies-Using-Node and https://github.com/joyent/node/wiki/modules
cookies/sessions/forms etc http://expressjs.com/ makes it easier
Ringojs is a framework developed by Hannes Wallnöver and uses rhino as it's scripting framework. There are webframeworks, templating-engines, orm-packages and many many more things already available. Have a look at the tutorial featuring a good subset of packages you may use for a simple web-application. It's not too long and straightforward.
Even thought some of those packages used within the tutorial (e.g. ringo-sqlstore]) are marked as 0.8 and come with the hint "consider this being beta" they are already very stable and bugs - if you find one - get fixed or commented on very fast.
And the power of uncountable java-libraries out there is at your fingertips - so if you already have java-knowledge this knowledge isn't wasted. Rhino - the scripting-engine - even enables you to implement interfaces and extend classes. It is possible a little more advanced but i've done it and i know of packages taking advantage of such features (like ringo-ftpserver which is a wrapper around Apache FtpServer written in java)
Another pro for me is - because ringojs is based on java - it works fairly well with multithreading with ringo/worker for example.

Resources