Reputation: 607
I am scripting a NodeJS server which needs to hash user passwords, in addition to other pieces of data, prior to storing them in a database. Due to the mathematically intense process of creating secure hashes, and the large volume of hashing that will need to be done, I have chosen to code the hashing process in C.
My question is this: How much overhead am I adding by executing the hashing process coded in C via child_process.exec as opposed to creating a native addon for NodeJS?
I.E. every time a piece of data needs to be hashed I will need to call child_process.exec with the piece of data as an argument.
Upvotes: 1
Views: 299
Reputation: 4484
There is significant overhead spawning a child process compared to just having code execute on the already existing node process. The two processes need to be connected and communicate through stdio. If you want specifics, you would have to test it out yourself for your use case. One way to test would be to find a native hashing lib, and test it against your C child process.
With that said, unless you are signing up hundreds of users per second the performance overhead of using a child process is completely negligible. You could even just do the hashing in node and most likely not notice the difference.
In fact, you should just use the 'crypto' module included with node, as it is already a native module.
https://stackoverflow.com/a/17201493/3355076 has a simple example.
Upvotes: 1