| great stories |
[Jan. 3rd, 2011|08:53 pm] |
|
ftp://download.intel.com/technology/itj/q12001/pdf/art_1.pdf |
|
|
| (no subject) |
[Nov. 17th, 2010|10:00 pm] |
Probably you guys don't read my twitter, so I have to post these here. (I cry inside thinking about how livejournal is dieing.)
In version v0.3 of node there is a function stream.pipe which pipes one stream into another. So for example you can pipe a TCP socket to process.stdout.
Here are two examples: - A telnet program
#!/usr/bin/env node
// telnet.js 80 google.com
net = require('net');
a = process.argv.slice(2);
if (!a.length) {
console.error("telnet.js port [ host=localhost ]");
process.exit(1);
}
s = require('net').Stream();
s.connect.apply(s, a);
s.pipe(process.stdout);
stdin = process.openStdin()
stdin.pipe(s);
s.on('end', function () {
stdin.destroy();
});
- An echo server (compacted for tweet-ability)
require('net').Server(function (s) { s.pipe(s); }).listen(8000);
|
|
|
| When to GC |
[Oct. 9th, 2010|07:33 pm] |
GC is a huge concern for Node. V8 "halts the world" while it walks the object graph and then compacts its heap; for a busy server this is bad - a full heap compaction can run for 30ms or more. V8's GC can run at anytime, but the API also allows you to notify it when you're idle -- suggesting better times to GC. Currently Node employs some contrived heuristics to decide when it's idle -- every five seconds a timeout fires which checks how often Node had gone around the event loop in the past second. If it's not so much, then it notifies V8 that it idle. This generally keeps the GC out of the way for 'hello world' web server benchmarks. However, for active long running programs this is potentially too coarse.
As with most servers, Node is greedily reading data and accepting connections from sockets. It tries to drain the kernel buffers every time it comes out of kqueue (or epoll, or poll, or select, ...). Likely, assuming we've drained buffers and no timeouts are immediately pending, the next time we hit kqueue we will be blocked for a while. It might be a win to block on kqueue and, in parallel, notify V8 that we're idle (in a different thread).
Also of note is a possible new V8 feature which uses multiple threads to mark the objects during GC. It might be helpful on large multicore servers. |
|
|