Skip to content

Instantly share code, notes, and snippets.

@dbushong
Created December 3, 2019 01:02
Show Gist options
  • Save dbushong/330210786fab2f453ce840569f45fd43 to your computer and use it in GitHub Desktop.
Save dbushong/330210786fab2f453ce840569f45fd43 to your computer and use it in GitHub Desktop.
'use strict';
const fs = require('fs');
const AH = require('async_hooks');
const net = require('net');
const { inspect } = require('util');
function log(...args) {
fs.writeSync(process.stdout.fd, `${args.map(x => inspect(x, { depth: null, colors: true })).join(' ')}\n`);
}
const hook = AH.createHook({
init(id, type, pid) {
if (type.startsWith('TCP')) log(type, { id, pid });
}
});
hook.enable();
for (let i = 0; i < 5; i++) {
(j => {
// pool.pull((err, conn) => {
const conn = net.connect(11211);
conn.on('connect', () => {
log('connect', { j, id: AH.executionAsyncId() });
conn.setEncoding('utf8');
conn.on('data', chunk => {
if (!chunk.includes('END')) return;
conn.end();
log('data', { j, id: AH.executionAsyncId() });
});
conn.write('stats\n');
});
})(i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment