Clone and build Node for analysis:
$ git clone https://github.com/joyent/node.git
$ cd node
$ export GYP_DEFINES="v8_enable_disassembler=1"
$ ./configure
$ make -j4
# Hello, and welcome to makefile basics. | |
# | |
# You will learn why `make` is so great, and why, despite its "weird" syntax, | |
# it is actually a highly expressive, efficient, and powerful way to build | |
# programs. | |
# | |
# Once you're done here, go to | |
# http://www.gnu.org/software/make/manual/make.html | |
# to learn SOOOO much more. |
var fs = require('fs'); | |
var infile = process.argv[2]; | |
if (!infile) return console.log("need infile"); | |
var data = fs.readFileSync(infile, 'utf8').split('\n'); | |
var outlines = []; | |
data.forEach(function(item) { |
$ cat test.js | |
function foo () { while (true) { } } | |
function bar () { return foo(); } | |
bar(); | |
$ node test.js & | |
$ gdb attach $(pidof node) | |
0x00000bf778c63d5f in ?? () | |
(gdb) b v8::internal::Runtime_StackGuard | |
Breakpoint 1 at 0x84a1f0 | |
(gdb) print 'v8::V8::TerminateExecution'(0) |
brew install git bash-completion
Configure things:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
// derived from http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Parallel_algorithm | |
function map() { | |
emit(1, // Or put a GROUP BY key here | |
{sum: this.value, // the field you want stats for | |
min: this.value, | |
max: this.value, | |
count:1, | |
diff: 0, // M2,n: sum((val-mean)^2) | |
}); |
# Here a few bash one-liners that helped me analyze / fight a weak DOS attack against debuggable.com. Mostly for future reference. | |
# The attacker was opening lots of tcp connections without sending data, I believe it's called a SYN flood, see: http://tools.ietf.org/html/rfc4987#section-3.2 | |
# Step 0: Check what is going on at port 80 | |
$ netstat -tan | grep ':80 ' | awk '{print $6}' | sort | uniq -c | |
# Step 1: Increase the number of available fds | |
$ ulimit -n 32000 | |
# Step 2: Restart your webserver, for me: |
// fs.copy(src,dst) && fs.copySync(src,dst) | |
var copy = function copy(src, dst, callback) { | |
var self = this; | |
if(!callback) { | |
callback = function(){}; | |
} | |
self.on('error', function(err) { |