Skip to content

Instantly share code, notes, and snippets.

View shuhei's full-sized avatar
🐶
This is fine

Shuhei Kagawa shuhei

🐶
This is fine
View GitHub Profile
@shuhei
shuhei / headers-timeout-keep-alive.js
Created April 28, 2019 18:08
A test case for server.headersTimeout + keep alive (fails on Node v10.15.2 and newer)
const http = require("http");
const net = require("net");
const server = http.createServer((req, res) => {
req.resume();
res.end("hello");
});
server.keepAliveTimeout = 6 * 1000;
server.headersTimeout = 4 * 1000;
@shuhei
shuhei / index.js
Created March 2, 2019 20:26
Callback of ClientRequest.prototype.end
const http = require('http');
const server = http.createServer((req, res) => {
console.log('[server] request');
setTimeout(() => {
res.end('hello');
console.log('[server] response');
}, 3000);
});
server.listen(3000, () => {
@shuhei
shuhei / README.md
Last active October 30, 2023 09:42
Benchmark of Node.js Histogram Libraries
@shuhei
shuhei / optional.js
Created October 16, 2018 06:32
A test for optimization of optional properties
const a = {
a: 1,
b: null
};
const b = {
a: 2,
b: null
};
const c = {
a: 2,
@shuhei
shuhei / count.js
Created September 17, 2018 16:45
Count children of a DOM element
function countChildren(el) {
const children = el && el.children;
if (!children) {
return 0;
}
let count = 0;
for (let i = 0; i < children.length; i++) {
const child = children[i];
count += 1;
count += countChildren(child);
@shuhei
shuhei / symbol.js
Created September 4, 2018 21:23
symbol.js
const fs = require('fs');
const path = require('path');
class Node {
constructor(start, end, depth) {
this.start = start;
this.end = end;
this.middle = Math.floor((start + end) / 2);
this.items = [];
this.left = null;
@shuhei
shuhei / README.md
Last active April 13, 2022 07:34
Fixing wrong symbols in Node.js CPU Frame Graphs

Fixing wrong symbols in Node.js CPU Frame Graphs

Motivation

I have been generating CPU Flame Graphs of Node.js applications with Linux perf command, and noticed that some of the graphs have suspicious labels. For example, with a sandbox project and Node 10.8.0, I got LazyCompile:*a.renderDOM /opt/app/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:35 where it should have been something related to streams.

For example, the following is a stack trace from perf script that I used to genearte a CPU Flame Graph. 227bbdff955b has a label LazyCompile:*a.renderDOM, but it doesn't make much sense that React.renderDOM was called from _stream_readable.js and parsed JSON in it.

node 22640 56531.256247:   10101010 cpu-clock: 
@shuhei
shuhei / Makefile
Last active June 28, 2018 07:56
Getting queue stats from libuv with N-API (Node.js v10)
.PHONY: build
configure:
@node-gyp configure
build:
@node-gyp build
run:
@node index.js
@shuhei
shuhei / README.md
Last active June 26, 2018 10:44
Show gzipped file size

gzsize

gzsize shows gzipped file sizes of files in your current working directory.

# For terminal
gzsize

# Markdown table
gzsize -m
@shuhei
shuhei / README.md
Created June 25, 2018 22:33
Node.js Thread Pool test
UV_THREADPOOL=100 node index.js
ab -c 100 -n 1000
htop