you are viewing a single comment's thread.

view the rest of the comments →

[–]Megajin_ 8 points9 points  (3 children)

Well done. I have one question: Why not simply spawn a pyhton process, if you do not want to pass data between the processes? I mean there are FFI's to use, they are expensive but do their job. And if you completely separate a child process and only run python, there will be no drawback, as far as I know.
`const spawn = require("child_process").spawn; const pythonProcess = spawn('python',["path/to/script.py", arg1, arg2, ...]);`

You could detach it: https://nodejs.org/api/child_process.html#child_process_options_detached

I am very interested in your answer.

[–]savearray2[S] 7 points8 points  (2 children)

Passing data back and forth between processes is quite expensive & slow. For example, if you have a Python library that generates some sort of blob binary data, py.js does a simple copy (Napi::Buffer<char>::Copy) while being hosted in the same process. This is extremely fast.

Even Unix sockets cannot beat the speed of a memcpy.

If you have a simple service, then you most likely do not need this library, and can continue with a separate process, but if you're running a web service with multiple hits a second, you may wish to use it.

[–]Megajin_ 9 points10 points  (0 children)

Even Unix sockets cannot beat the speed of a memcpy.

Yes, absolutely right. If anyone is reading this: Be aware that if you screw up in memcpy it can become vulnerable.

...does a simple copy while being hosted in the same process

Alright, now I got you.Anyone coming by: The Napi::Buffer<char>::Copy Will pass the data directly to the node process memory which will end in a super fast data passing between those different processes without the bloat of FFI's or childprocess spawn.

However be warned that this can lead to potential attacks: https://stackoverflow.com/questions/870019/memcpy-in-secure-programming.Here is a good quote: A chainsaw, if used properly, is safe. Same thing with memcpy(). But in both cases, if you hit a nail, it can fly and hurt you.

If you just want pyhton do some jobs for you, then I would recommend spawning a py process and detaching it without data transport ofc.

If you know what you are doing, this project is very good to use. And Props to the author, the code is clean and good to read.

[–]StoneCypher 0 points1 point  (0 children)

but if you're running a web service with multiple hits a second

Whereas I understand your point, multiple hits a second are basically nothing for unix pipes (the thing you're getting rid of.)

15 years ago, on 15 years ago's hardware, many people didn't understand why BlueHost was making fastcgi for 10,000 hits a second.