Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport async hooks to v8.x #18179

Closed
wants to merge 22 commits into from
Closed

Backport async hooks to v8.x #18179

wants to merge 22 commits into from

Commits on Jan 16, 2018

  1. src: explicitly register built-in modules

    Previously, built-in modules are registered before main() via
    __attribute__((constructor)) mechanism in GCC and similiar
    mechanism in MSVC. This causes some issues when node is built as
    static library. Calling module registration function for built-in
    modules in node::Init() helps to avoid the issues.
    
    Signed-off-by: Yihong Wang <yh.wang@ibm.com>
    PR-URL: #16565
    Refs: #14986 (comment)
    Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
    yhwang authored and AndreasMadsen committed Jan 16, 2018
    Configuration menu
    Copy the full SHA
    7a5e327 View commit details
    Browse the repository at this point in the history
  2. src: use unique pointer for tracing_agent

    Use std::unique_ptr instead of raw pointers for the
    tracing_agent_ in node.cc. This makes ownership clearer and we
    don't risk a memory leak.
    
    PR-URL: #17012
    Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
    Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Timothy Gu <timothygu99@gmail.com>
    fhinkel authored and AndreasMadsen committed Jan 16, 2018
    Configuration menu
    Copy the full SHA
    6e98aa9 View commit details
    Browse the repository at this point in the history
  3. async_hooks: add trace events to async_hooks

    This will allow trace event to record timing information for all
    asynchronous operations that are observed by async_hooks.
    
    PR-URL: #15538
    Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    AndreasMadsen committed Jan 16, 2018
    Configuration menu
    Copy the full SHA
    2bffd70 View commit details
    Browse the repository at this point in the history
  4. async_hooks: add destroy event for gced AsyncResources

    In cases where libraries create AsyncResources which may be emitting
    more events depending on usage, the only way to ensure that destroy is
    called properly is by calling it when the resource gets garbage
    collected.
    
    Fixes: #16153
    PR-URL: #16998
    Fixes: #16153
    Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Sebmaster authored and AndreasMadsen committed Jan 16, 2018
    Configuration menu
    Copy the full SHA
    07e7f2e View commit details
    Browse the repository at this point in the history
  5. src: use NODE_BUILTIN_MODULE_CONTEXT_AWARE() macro

    Commit d217b28 ("async_hooks: add trace events to async_hooks")
    used `NODE_MODULE_CONTEXT_AWARE_BUILTIN()` instead.
    
    After commit 8680bb9 ("src: explicitly register built-in modules")
    it no longer works for static library builds so remove it.
    
    PR-URL: #17071
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Timothy Gu <timothygu99@gmail.com>
    bnoordhuis authored and AndreasMadsen committed Jan 16, 2018
    Configuration menu
    Copy the full SHA
    1a66f91 View commit details
    Browse the repository at this point in the history
  6. src: rename async-wrap -> async_wrap

    This commit renames async-wrap to async_wrap for consitency with other
    c++ source files.
    
    PR-URL: #17022
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Refael Ackermann <refack@gmail.com>
    Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
    danbev authored and AndreasMadsen committed Jan 16, 2018
    Configuration menu
    Copy the full SHA
    b7e3109 View commit details
    Browse the repository at this point in the history
  7. timers: cross JS/C++ border less frequently

    This removes the `process._needImmediateCallback` property
    and its semantics of having a 1/0 switch that tells C++ whether
    immediates are currently scheduled.
    
    Instead, a counter keeping track of all immediates is created,
    that can be increased on `setImmediate()` or decreased when an
    immediate is run or cleared.
    
    This is faster, because rather than reading/writing a C++ getter,
    this operation can be performed as a direct memory read/write via
    a typed array. The only C++ call that is left to make is
    activating the native handles upon creation of the first
    `Immediate` after the queue is empty.
    
    One other (good!) side-effect is that `immediate._destroyed` now
    reliably tells whether an `immediate` is still scheduled to run or not.
    
    Also, as a nice extra, this should make it easier to implement
    an internal variant of `setImmediate` for C++ that piggybacks
    off the same mechanism, which should be useful at least for
    async hooks and HTTP/2.
    
    Benchmark results:
    
        $ ./node benchmark/compare.js --new ./node --old ./node-master-1b093cb93df0 --runs 10 --filter immediate timers | Rscript benchmark/compare.R
        [00:08:53|% 100| 4/4 files | 20/20 runs | 1/1 configs]: Done
                                                             improvement confidence      p.value
         timers/immediate.js type="breadth" thousands=2000      25.61 %         ** 1.432301e-03
         timers/immediate.js type="breadth1" thousands=2000      7.66 %            1.320233e-01
         timers/immediate.js type="breadth4" thousands=2000      4.61 %            5.669053e-01
         timers/immediate.js type="clear" thousands=2000       311.40 %        *** 3.896291e-07
         timers/immediate.js type="depth" thousands=2000        17.54 %         ** 9.755389e-03
         timers/immediate.js type="depth1" thousands=2000       17.09 %        *** 7.176229e-04
         timers/set-immediate-breadth-args.js millions=5        10.63 %          * 4.250034e-02
         timers/set-immediate-breadth.js millions=10            20.62 %        *** 9.150439e-07
         timers/set-immediate-depth-args.js millions=10         17.97 %        *** 6.819135e-10
    
    PR-URL: #17064
    Reviewed-By: Refael Ackermann <refack@gmail.com>
    Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
    addaleax authored and AndreasMadsen committed Jan 16, 2018
    Configuration menu
    Copy the full SHA
    8c83406 View commit details
    Browse the repository at this point in the history
  8. async_hooks: deprecate undocumented API

    PR-URL: #16972
    Refs: #14328
    Refs: #15572
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    AndreasMadsen committed Jan 16, 2018
    Configuration menu
    Copy the full SHA
    d66d481 View commit details
    Browse the repository at this point in the history
  9. src: introduce internal C++ SetImmediate() mechanism

    PR-URL: #17117
    Reviewed-By: James M Snell <jasnell@gmail.com>
    addaleax authored and AndreasMadsen committed Jan 16, 2018
    Configuration menu
    Copy the full SHA
    c904ce1 View commit details
    Browse the repository at this point in the history
  10. src: remove async_hooks destroy timer handle

    PR-URL: #17117
    Reviewed-By: James M Snell <jasnell@gmail.com>
    addaleax authored and AndreasMadsen committed Jan 16, 2018
    Configuration menu
    Copy the full SHA
    590cf4a View commit details
    Browse the repository at this point in the history
  11. trace_events: add executionAsyncId to init events

    async_hooks emits trace_events. This adds the executionAsyncId to the
    init events. In theory this could be inferred from the before and after
    events but this is much simpler and doesn't require knowledge of all
    events.
    
    PR-URL: #17196
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
    Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
    AndreasMadsen committed Jan 16, 2018
    Configuration menu
    Copy the full SHA
    d32d180 View commit details
    Browse the repository at this point in the history
  12. async_wrap: add provider types for net server

    Adds `TCPSERVERWRAP` and `PIPESERVERWRAP` as provider types. This
    makes it possible to distinguish servers from connections.
    
    PR-URL: #17157
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    AndreasMadsen committed Jan 16, 2018
    Configuration menu
    Copy the full SHA
    44cbf56 View commit details
    Browse the repository at this point in the history
  13. async_hooks: rename initTriggerId

    rename initTriggerId to defaultTriggerAsyncId such it matches the rest
    of our naming.
    
    PR-URL: #17273
    Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    AndreasMadsen committed Jan 16, 2018
    Configuration menu
    Copy the full SHA
    1044e76 View commit details
    Browse the repository at this point in the history
  14. async_hooks: separate missing from default context

    When context is missing the executionAsyncId will be zero. For the
    default triggerAsyncId the zero value was used to default to the
    executionAsyncId. While this was not technically wrong because the
    functions are different themself, it poorly separated the two concepts.
    
    PR-URL: #17273
    Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    AndreasMadsen committed Jan 16, 2018
    Configuration menu
    Copy the full SHA
    a04d5ee View commit details
    Browse the repository at this point in the history
  15. async_hooks: use scope for defaultTriggerAsyncId

    Previously the getter would mutate the kDefaultTriggerAsncId value. This
    refactor changes the setter to bind the current kDefaultTriggerAsncId to
    a scope, such that the getter doesn't have to mutate its own value.
    
    PR-URL: #17273
    Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    AndreasMadsen committed Jan 16, 2018
    Configuration menu
    Copy the full SHA
    44f4c73 View commit details
    Browse the repository at this point in the history
  16. src: remove unused async hooks methods

    PR-URL: #17757
    Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
    Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
    Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
    Reviewed-By: Jon Moss <me@jonathanmoss.me>
    Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
    Reviewed-By: Timothy Gu <timothygu99@gmail.com>
    Reviewed-By: vdeturckheim <vlad2t@hotmail.com>
    addaleax authored and AndreasMadsen committed Jan 16, 2018
    Configuration menu
    Copy the full SHA
    7310f66 View commit details
    Browse the repository at this point in the history
  17. async_hooks: use CHECK instead of throwing error

    SetupHooks is only available via `process.binding('async_wrap')`, so
    there's no reason it shouldn't be called with the appropriate arguments,
    since it is an internal-only function. The only place this function is
    used is `lib/internal/async_hooks.js`.
    
    PR-URL: #17832
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
    Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
    Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
    Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
    maclover7 authored and AndreasMadsen committed Jan 16, 2018
    Configuration menu
    Copy the full SHA
    4e656fd View commit details
    Browse the repository at this point in the history
  18. async_hooks: use typed array stack as fast path

    - Communicate the current async stack length through a
      typed array field rather than a native binding method
    - Add a new fixed-size `async_ids_fast_stack` typed array
      that contains the async ID stack up to a fixed limit.
      This increases performance noticeably, since most of the time
      the async ID stack will not be more than a handful of
      levels deep.
    - Make the JS `pushAsyncIds()` and `popAsyncIds()` functions
      do the same thing as the native ones if the fast path
      is applicable.
    
    Benchmarks:
    
        $ ./node benchmark/compare.js --new ./node --old ./node-master --runs 10 --filter next-tick process | Rscript benchmark/compare.R
        [00:03:25|% 100| 6/6 files | 20/20 runs | 1/1 configs]: Done
                                                       improvement confidence      p.value
         process/next-tick-breadth-args.js millions=4     19.72 %        *** 3.013913e-06
         process/next-tick-breadth.js millions=4          27.33 %        *** 5.847983e-11
         process/next-tick-depth-args.js millions=12      40.08 %        *** 1.237127e-13
         process/next-tick-depth.js millions=12           77.27 %        *** 1.413290e-11
         process/next-tick-exec-args.js millions=5        13.58 %        *** 1.245180e-07
         process/next-tick-exec.js millions=5             16.80 %        *** 2.961386e-07
    
    PR-URL: #17780
    Reviewed-By: James M Snell <jasnell@gmail.com>
    addaleax authored and AndreasMadsen committed Jan 16, 2018
    Configuration menu
    Copy the full SHA
    067bd2a View commit details
    Browse the repository at this point in the history
  19. trace_events: stop tracing agent in process.exit()

    PR-URL: #18005
    Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
    AndreasMadsen committed Jan 16, 2018
    Configuration menu
    Copy the full SHA
    af928ef View commit details
    Browse the repository at this point in the history
  20. async_hooks: update defaultTriggerAsyncIdScope for perf

    The existing version of defaultTriggerAsyncIdScope creates an Array
    for the callback's arguments which is highly inefficient. Instead,
    use rest syntax and allow V8 to do that work for us. This yields
    roughly 2x performance for this particular function.
    
    PR-URL: #18004
    Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
    Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
    apapirovski authored and AndreasMadsen committed Jan 16, 2018
    Configuration menu
    Copy the full SHA
    1efac0e View commit details
    Browse the repository at this point in the history
  21. async_hooks,http: set HTTPParser trigger to socket

    This allows more easy tracking of where HTTP requests come from. Before
    this change the HTTPParser would have the HTTPServer as the
    triggerAsyncId.
    
    The HTTPParser will still have the executionAsyncId set to the HTTP
    Server so that information is still directly available. Indirectly, the
    TCP socket itself also has its triggerAsyncId set to the TCP Server.
    
    PR-URL: #18003
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
    Reviewed-By: Jon Moss <me@jonathanmoss.me>
    Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
    AndreasMadsen committed Jan 16, 2018
    Configuration menu
    Copy the full SHA
    3ba594f View commit details
    Browse the repository at this point in the history
  22. async_hooks,test: only use IPv6 in http test

    If IPv6 is not supported on a machine, the IPv6 handle will first be
    created, this will then fail and default to an IPv4 handle. This causes
    the graph to change, as there now is an extra handle.
    
    PR-URL: #18143
    Fixes: #18003
    Reviewed-By: Anna Henningsen <anna@addaleax.net>
    Reviewed-By: Rich Trott <rtrott@gmail.com>
    Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    AndreasMadsen committed Jan 16, 2018
    Configuration menu
    Copy the full SHA
    8937440 View commit details
    Browse the repository at this point in the history