FAQ
Currently, my C++ program communicates with my node.js app via stdin/stdout.
So, my node.js app instantiate my C++ program using child_process and
use its stdin/stdout.

Recently, I played with node.js addons:

http://nodejs.org/api/addons.html

and discovered that a simple "a + b" program can be up to 50x faster
implemented as addons
compared to C++ program that uses scanf / printf and communicate via
stdin/stdout.

So, I am really motivated to use addons for the communications!
However, my C++ program has interaction with disk (has to perform I/O).

The current node.js documentation above doesn't have an example
on how to use addons + libuv to do a non-blocking addons.

Can anyone give a simple example of non-blocking addons?

Thanks,

Felix Halim

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Search Discussions

  • Tim Caswell at Mar 29, 2012 at 1:43 pm
    Native addons are in the same process as node which means all
    the benefits and drawbacks that brings.

    As you noted, using a child process is good if the child is going to block
    since it won't block node. Also the child process can use a different CPU
    core than node for true parallel work. However there is significant
    overhead to having a new process and serializing all data back and forth.
      In process addons are much more efficient but share the same process. The
    C++/JS boundary is somewhat expensive (though nothing like serializing data
    across processes). Once in the main node process it's very bad to block
    the process because it defeats the purpose of the event loop if any one
    call blocks for a long time.

    There is one solution using threads in the addon. Libuv has APIs to help
    with this. Look at uv_work_t and friends. The node zlib module uses uv
    threads to perform compression in a background thread. <
    https://github.com/joyent/node/blob/master/src/node_zlib.cc>

    Too much use of the thread pool can be bad for a program, so take all
    considerations in moderation.

    -Tim Caswell
    On Thu, Mar 29, 2012 at 3:49 AM, Felix Halim wrote:

    Currently, my C++ program communicates with my node.js app via
    stdin/stdout.
    So, my node.js app instantiate my C++ program using child_process and
    use its stdin/stdout.

    Recently, I played with node.js addons:

    http://nodejs.org/api/addons.html

    and discovered that a simple "a + b" program can be up to 50x faster
    implemented as addons
    compared to C++ program that uses scanf / printf and communicate via
    stdin/stdout.

    So, I am really motivated to use addons for the communications!
    However, my C++ program has interaction with disk (has to perform I/O).

    The current node.js documentation above doesn't have an example
    on how to use addons + libuv to do a non-blocking addons.

    Can anyone give a simple example of non-blocking addons?

    Thanks,

    Felix Halim

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Paul Hauner at Apr 12, 2016 at 4:37 pm
    Hi Felix,
      I have made an example which demonstrates a non-blocking async C++ node
    addon.
    This example implements the callback pattern.

    https://github.com/paulhauner/example-async-node-addon

    I hope it helps :)
    Paul
    On Thursday, 29 March 2012 19:49:15 UTC+11, Felix Halim wrote:

    Currently, my C++ program communicates with my node.js app via
    stdin/stdout.
    So, my node.js app instantiate my C++ program using child_process and
    use its stdin/stdout.

    Recently, I played with node.js addons:

    http://nodejs.org/api/addons.html

    and discovered that a simple "a + b" program can be up to 50x faster
    implemented as addons
    compared to C++ program that uses scanf / printf and communicate via
    stdin/stdout.

    So, I am really motivated to use addons for the communications!
    However, my C++ program has interaction with disk (has to perform I/O).

    The current node.js documentation above doesn't have an example
    on how to use addons + libuv to do a non-blocking addons.

    Can anyone give a simple example of non-blocking addons?

    Thanks,

    Felix Halim
    --
    Job board: http://jobs.nodejs.org/
    New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    ---
    You received this message because you are subscribed to the Google Groups "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
    To post to this group, send email to nodejs@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/fb605601-a446-482a-afd6-6dd3d2ee7251%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Felix Halim at Apr 17, 2016 at 10:21 pm
    Hi Paul,

    Thanks for the examples, but this thread is like 4 years old :)

    I've decided to use libuv directly for my C++11 needs and expose them via
    HTTP as web API.
    Then the nodejs app (or any other app) can use the web API to communicate.
    This design actually far better than using addons since I get to define the
    API for the communications.

    Here is my generic http-server in C++11 that wraps libuv (it supports async
    requests see the test_server.cc
    <https://github.com/felix-halim/http-server/blob/master/test_server.cc>):

    https://github.com/felix-halim/http-server

    It has been running for ~2 years now and is pretty stable in production:

    https://uhunt.onlinejudge.org/api

    Felix Halim
    On Tue, Apr 12, 2016 at 4:00 AM, Paul Hauner wrote:

    Hi Felix,
    I have made an example which demonstrates a non-blocking async C++ node
    addon.
    This example implements the callback pattern.

    https://github.com/paulhauner/example-async-node-addon

    I hope it helps :)
    Paul

    On Thursday, 29 March 2012 19:49:15 UTC+11, Felix Halim wrote:

    Currently, my C++ program communicates with my node.js app via
    stdin/stdout.
    So, my node.js app instantiate my C++ program using child_process and
    use its stdin/stdout.

    Recently, I played with node.js addons:

    http://nodejs.org/api/addons.html

    and discovered that a simple "a + b" program can be up to 50x faster
    implemented as addons
    compared to C++ program that uses scanf / printf and communicate via
    stdin/stdout.

    So, I am really motivated to use addons for the communications!
    However, my C++ program has interaction with disk (has to perform I/O).

    The current node.js documentation above doesn't have an example
    on how to use addons + libuv to do a non-blocking addons.

    Can anyone give a simple example of non-blocking addons?

    Thanks,

    Felix Halim

    --
    Job board: http://jobs.nodejs.org/
    New group rules:
    https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    ---
    You received this message because you are subscribed to the Google Groups
    "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to nodejs+unsubscribe@googlegroups.com.
    To post to this group, send email to nodejs@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/nodejs/fb605601-a446-482a-afd6-6dd3d2ee7251%40googlegroups.com
    <https://groups.google.com/d/msgid/nodejs/fb605601-a446-482a-afd6-6dd3d2ee7251%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    Job board: http://jobs.nodejs.org/
    New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    ---
    You received this message because you are subscribed to the Google Groups "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
    To post to this group, send email to nodejs@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAAbwPorkFr1Mdafg1PhJH5qBVzE0P-SBvt5iujbKhrPO4k%3D-Uw%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupnodejs @
categoriesnodejs
postedMar 29, '12 at 8:49a
activeApr 17, '16 at 10:21p
posts4
users3
websitenodejs.org
irc#node.js

People

Translate

site design / logo © 2017 Grokbase