node.js
evented I/O for V8 javascript”. It’s a toolkit for writing extremely high performance non-blocking event driven network servers in JavaScript. Think similar to Twisted or EventMachine but for JavaScript instead of Python or Ruby.
http://s3.amazonaws.com/four.livejournal/20091117/jsconf.pdf
node.js in brief:
Server-side Javascript
Built on Google’s V8
Evented, non-blocking I/O. Similar to EventMachine or Twisted.
CommonJS module system.
8000 lines of C/C++, 2000 lines of Javascript, 14 contributors.
Many web applications have code like this:What is the software doing while it queries the database?
var result = db.query("select * from T");
// use result
In many cases, just waiting for the response.
I/O latency
L1: 3 cycles
L2: 14 cycles
RAM: 250 cycles
DISK: 41,000,000 cycles
NETWORK: 240,000,000 cycles
Better software can multitask.
Other threads of execution can run while waiting.
Apache uses one thread per connection.
NGINX doesn't use threads. It uses an event loop.
Context switching is not free
Execution stacks take up memory
For massive concurrency, cannot use an OS thread for each connection.
Green threads or coroutines can improve the situation dramatically
BUT there is still machinery involved to create the illusion of holding execution on I/O.
Node.js is genuinely exciting
other http servers.
nginx
Tornado Web Server
Yaws, Apache vs. Yaws
沒有留言:
張貼留言