Skip to content
Performance impact of async_hooks
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Add a simple hapi benchmark. Jan 17, 2018
.npmrc Disable package-lock.json. Jan 17, 2018
README.md
async-hook-full.js Also measure the impact of all hooks. Jan 17, 2018
async-hook-init.js Also measure the impact of all hooks. Jan 17, 2018
bluebird-doxbee.js
bluebird-parallel.js
hapiserver.js Add a simple koa benchmark. Jan 17, 2018
koaserver.js
package.json
results-hapi-koa-node-9.4.0.png Fix the results graph. Jan 17, 2018
results-node-9.3.0.png
results-promise-node-9.4.0.png Also measure the impact of all hooks. Jan 17, 2018
run.js
wikipedia.js remove duplication; add run.js Jan 16, 2018

README.md

Performance impact of async_hooks

This is a simple demo of the potential performance impact of async_hooks on Promise heavy workloads. This repository contains the popular Bluebird benchmarks and the so-called Wikipedia Promise benchmark with and without async_hooks (running with native promises).

To measure the actual impact there's a version of each benchmark with an empty init hook, i.e. we prepend the following code to the actual code under test:

const async_hooks = require('async_hooks');
const hook = async_hooks.createHook({
    init(asyncId, type, triggerAsyncId) { }
});
hook.enable();

We also test with all hooks (i.e. init, before, after, destroy and promiseResolve) using the following snippet:

const async_hooks = require('async_hooks');
const hook = async_hooks.createHook({
    init(asyncId, type, triggerAsyncId, resource) { },
    before(asyncId) { },
    after(asyncId) { },
    destroy(asyncId) { },
    promiseResolve(asyncId) { },
});
hook.enable();

Results

Here the results of running the Promise micro benchmarks with and without async_hooks enabled:

Benchmark Node 8.9.4 Node 9.4.0
Bluebird-doxbee (regular) 226 ms 189 ms
Bluebird-doxbee (init hook) 383 ms 341 ms
Bluebird-doxbee (all hooks) 440 ms 411 ms
Bluebird-parallel (regular) 924 ms 696 ms
Bluebird-parallel (init hook) 1380 ms 1050 ms
Bluebird-parallel (all hooks) 1488 ms 1220 ms
Wikipedia (regular) 993 ms 804 ms
Wikipedia (init hook) 2025 ms 1893 ms
Wikipedia (all hooks) 2109 ms 2124 ms

Results for Node 9.4.0

And we also ran some more realistic benchmarks, based on hapi and koa, with and without async_hooks enabled:

Benchmark Node 9.4.0
hapi (asynchooks) 6026.9 reqs
hapi (regular) 9024.19 reqs
koa (asynchooks) 11508.6 reqs
koa (regular) 12592.55 reqs

The koa benchmark is pretty flaky, so the performance difference could be within noise and thus not relevant.

Results for Node 9.4.0

Bluebird benchmarks

The files here are modified from: https://github.com/petkaantonov/bluebird/tree/master/benchmark

The current version is based on bluebird@c0d4472cecd523c2f9d4805a23d87be3cfe03b41

Wikipedia Benchmark

The files here are modified from: https://github.com/wikimedia/web-stream-util

The current version is based on web-stream-util@fc76740cd6a73dcb044251a233bc3c868d3c9a77

You can’t perform that action at this time.