Created
December 3, 2019 01:02
-
-
Save dbushong/330210786fab2f453ce840569f45fd43 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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