Performance impact of async_hooks

January 17, 2018 ยท View on GitHub

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:

BenchmarkNode 8.9.4Node 9.4.0
Bluebird-doxbee (regular)226 ms189 ms
Bluebird-doxbee (init hook)383 ms341 ms
Bluebird-doxbee (all hooks)440 ms411 ms
Bluebird-parallel (regular)924 ms696 ms
Bluebird-parallel (init hook)1380 ms1050 ms
Bluebird-parallel (all hooks)1488 ms1220 ms
Wikipedia (regular)993 ms804 ms
Wikipedia (init hook)2025 ms1893 ms
Wikipedia (all hooks)2109 ms2124 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:

BenchmarkNode 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