问题

一篇#2011-003 multiple implementations denial-of-service via hash algorithm collision 文章,引起了 Web 应用安全领域的骚动。

这种hash算法冲突的原理到底是什么?可以看看一下两篇以PHP为例子的说明文章:

解决办法

既然是语言层面的hash算法冲突导致的,那么这种冲突就无法避免了。
但是我们可以限制Hash key的数量来避免。

所以可以进行一下设置解决此问题:

  • 限制请求大小 (只能指标不治本,因为PHP版本的话,700KB的数据就足以发起攻击)
  • 限制请求key的数量 (这可以基本解决问题,除非应用无法预知最大的key数量)
  • 只接受允许的key (这是终极方法,但需要保证开发记得配置新增的key)

在Nodejs防御此问题

虽然在目前为止还没看到对Nodejs造成攻击的具体方法,但是还是以防范于未然为原则,需要对此问题做好充分的防御措施。

Nodejs 的攻击方法已经出现,具体测试结果可以查看 Hash algorithm collision in Nodejs
hac-results

由于我个人一直使用的是 connect ,所以我以 connect 为示例说明吧 ^_^

使用 connect.limit 限制 request-body-size

Issue #446 已有同学提出此问题了,@TJ回复如下:

we have limit() for this, which works for any request body. Even without this specific issue you could exhaust resources reasonably easily without some form of limiting

好吧,直接上 connect.limit 模块解决

connect()
  .use(connect.limit('1mb'))
  .use(handleRequest)

修改 qs 模块,让其支持 keys-limit 和 allow-keys

querystring.js

PS: 提了pull request,但是估计在没有真实攻击示例放出来之前,是不会被接受的。

/**
 * Parse the given str.
 */

function parseString(str, options) {
  var limit = options && options.limit;
  var keys = options && options.keys;
  if (keys && Array.isArray(keys)) {
    keys = {};
    for (var i = 0, l = options.keys.length; i < l; i++) {
      keys[options.keys[i]] = 1;
    }
  }
  return String(str)
    .split('&', limit)
    .reduce(function(ret, pair){
      try{
        pair = decodeURIComponent(pair.replace(/\+/g, ' '));
      } catch(e) {
        // ignore
      }

      var eql = pair.indexOf('=')
        , brace = lastBraceInKey(pair)
        , key = pair.substr(0, brace || eql);
      if (keys && !keys[key]) {
        return ret;
      }
      var val = pair.substr(brace || eql, pair.length)
      val = val.substr(val.indexOf('=') + 1, val.length);

      // ?foo
      if ('' == key) key = pair, val = '';

      return merge(ret, key, val);
    }, { base: {} }).base;
}


/**
 * Parse the given query `str` or `obj`, returning an object.
 *
 * Options: (only effect on parse string)
 *
 *  - `limit` parse string split limit.
 *  - `keys`  which keys need to be parse.
 *
 * @param {String} str | {Object} obj
 * @param {Object} options
 * @return {Object}
 * @api public
 */

exports.parse = function(str, options) {
  if (null == str || '' == str) return {};
  return 'object' == typeof str
    ? parseObject(str)
    : parseString(str, options);
};

还需要让 connect.query 模块 传递options参数给 qs.parse()

module.exports = function query(options){
  return function query(req, res, next){
    req.query = ~req.url.indexOf('?')
      ? qs.parse(parse(req.url).query, options)
      : {};
    next();
  };
};

同样 connect.urlencoded 模块也需要将options参数传递给 qs.parse()

    req.on('end', function(){
      try {
        req.body = buf.length
          ? qs.parse(buf, options)
          : {};
        next();
      } catch (err){
        next(err);
      }
    });

全部组合起来

var qsOptions = { limit: 100 };
connect()
  .use(connect.limit('1mb'))
  .use(connect.query(qsOptions))
  .use(connect.bodyParser(qsOptions))
  .use(handleRequest)

防范 http header 攻击

请求的 http header 也会导致hash冲突,在V8层面未修复hash算法之前,可以通过简单的 http_patch.js 修复此问题:

var http = require('http');

var IncomingMessage = http.IncomingMessage;
var _addHeaderLine = IncomingMessage.prototype._addHeaderLine;

// limit http header number
IncomingMessage.prototype._addHeaderLine = function(field, val) {
  if (!this.__headerCount__) {
    this.__headerCount__ = 0;
  } else if (this.__headerCount__ >= 100) {
    return;
  }
  _addHeaderLine.apply(this, arguments);
  this.__headerCount__++;
};

最后

2011年末,苦逼的程序员还在为这个安全漏洞写补丁,打补丁,想各种解决方法。
2012年或许还会有各种各样的问题,我们一起勇敢面对吧。
Happy New Year!

posted @ 2012-01-01 00:49 MK2 阅读(315) 评论(4) 编辑

Node.js is Cancer show a wrong way to use nodejs.
But the test code Fibonacci is so funny.
I implement the fibonacci function in other Dynamic Languages for comparison testing.

Languages

Dynamic

Static

If you want to help add more dynamic languagues, please leave the implement code in comments.

Results

(^_^) c > go > luajit > nodejs > pypy > lua > python > php > perl > ruby1.9.3 > ruby1.8.5 (T_T)

LanguageTimesPosition
c0m1.606s#0
go0m1.769s#1
node + cpp module0m2.216s#2
luajit0m2.583s#3
nodejs0m5.124s#4
pypy0m7.562s#5
lua0m34.492s#6
python1m11.647s#7
php1m28.198s#8
perl2m34.658s#9
ruby 1.9.34m40.790s#10
ruby 1.8.54m41.942s#11

lua use local function will get better performance.

Test Codes

nodejs

function fibonacci(n) {
  if (n < 2) {
    return 1;
  }
  return fibonacci(n - 2) + fibonacci(n - 1);
}

console.log(fibonacci(40));

run

$ time node fibonacci.js
165580141

real  0m5.153s
user  0m5.124s
sys 0m0.012s

nodejs + cpp module

cppfibonacci.cpp

#include 
#include 

using namespace v8;

int fibonacci(int n) {
  if (n < 2) {
    return 1;
  }
  return fibonacci(n - 1) + fibonacci(n - 2);
}

Handle Fibonacci(const Arguments& args) {
    HandleScope scope;

    if (args.Length() < 1) {
        return ThrowException(Exception::TypeError(
            String::New("First argument must be a number")));
    }
    Local integer = args[0]->ToInteger();
    int r = fibonacci(integer->Value());

    return scope.Close(Integer::New(r));
}

void RegisterModule(v8::Handle target) {
    // Add properties to target
    NODE_SET_METHOD(target, "fibonacci", Fibonacci);
}

// Register the module with node.
NODE_MODULE(cppfibonacci, RegisterModule);

wscript

#!/usr/bin/env python

def set_options(ctx):
  ctx.tool_options('compiler_cxx')

def configure(ctx):
  ctx.check_tool('compiler_cxx')
  ctx.check_tool('node_addon')

def build(ctx):
  t = ctx.new_task_gen('cxx', 'shlib', 'node_addon')

  t.source = ['cppfibonacci.cpp']

  # Must be same as first parameter in NODE_MODULE.
  t.target = 'cppfibonacci'

cppfibonacci.js

var fibonacci = require('./build/default/cppfibonacci').fibonacci;
console.log(fibonacci(40));

run

$ node-waf configure
$ node-waf build
$ time node cppfibonacci.js
165580141

real  0m2.224s
user  0m2.216s
sys 0m0.008s

python2.4.3 && python2.6.7 && pypy1.7

def fibonacci(n):
    if n < 2:
        return 1
    return fibonacci(n - 2) + fibonacci(n - 1)

print fibonacci(40)

run

$ time python2.4.3 fibonacci.py
165580141

real  1m11.667s
user  1m11.647s
sys 0m0.002s

$ time python2.6.7 fibonacci.py
165580141

real  1m9.837s
user  1m9.792s
sys 0m0.006s

$ time ./pypy-1.7/bin/pypy fibonacci.py
165580141

real  0m7.608s
user  0m7.562s
sys 0m0.031s

perl

sub fibonacci {
    my $n = shift;
    if ($n < 2) {
      return 1;
    }
    return fibonacci($n - 2) + fibonacci($n - 1);
}

print fibonacci(40), "\n";

run

$ time perl fibonacci.pl
165580141

real  2m34.777s
user  2m34.658s
sys 0m0.004s

php


run

$ time php fibonacci.php

165580141
real  1m28.364s
user  1m28.198s
sys 0m0.039s

ruby1.8.5 && ruby1.9.3

def fibonacci(n)
  if n < 2
    return 1
  end
  return fibonacci(n - 2) + fibonacci(n - 1)
end

puts fibonacci(40)

run

$ time ruby1.8.5 fibonacci.rb
165580141

real  5m43.132s
user  4m41.942s
sys 1m0.653s

$ time ruby1.9.3 fibonacci.rb
165580141

real  5m41.714s
user  4m40.790s
sys 1m0.661s

lua && luajit

function fibonacci(n)
  if n < 2 then
    return 1
  end
  return fibonacci(n - 2) + fibonacci(n - 1)
end

io.write(fibonacci(40), "\n")

run

$ time ./lua-5.1.4/src/lua fibonacci.lua 
165580141

real  0m34.514s
user  0m34.492s
sys 0m0.004s

$ time ./LuaJIT-2.0.0-beta9/src/luajit fibonacci.lua 
165580141

real  0m2.598s
user  0m2.583s
sys 0m0.001s

local function should be faster:

local function fibonacci(n)
  if n < 2 then
    return 1
  end
  return fibonacci(n - 2) + fibonacci(n - 1)
end

io.write(fibonacci(40), "\n")

$ time ./lua-5.1.4/src/lua fibonacci.lua.local
165580141

real  0m31.737s
user  0m31.549s
sys 0m0.001s

$ time ./LuaJIT-2.0.0-beta9/src/luajit fibonacci.lua.local
165580141

real  0m2.227s
user  0m2.225s
sys 0m0.001s

c

#include 

int fibonacci(n) {
  if (n < 2) {
    return 1;
  }
  return fibonacci(n - 2) + fibonacci(n - 1);
}

int main() {
  printf("%d\n", fibonacci(40));
  return 0;
}

run

$ gcc fibonacci.c
$ time ./a.out 
165580141

real  0m3.434s
user  0m3.427s
sys 0m0.000s

Compilation with optimization:

$ gcc -O2 fibonacci.c
$ time ./a.out 
165580141

real  0m1.607s
user  0m1.606s
sys 0m0.001s

@fool: How about C++ meta programming, it’s a bit of cheating

#include 

template
struct fibonacci {
    enum { Result = fibonacci::Result + fibonacci::Result };
};

template<>
struct fibonacci<1> {
    enum { Result = 1 };
};

template<>
struct fibonacci<0> {
    enum { Result = 1 };
};

int main(int argc, char *argv[])
{
    printf("%d\n", fibonacci<40>::Result);
    return 0;
}

run

$ g++ fibonacci.template.cpp 
$ time ./a.out
165580141

real  0m0.002s
user  0m0.001s
sys 0m0.001s

go

package main

import "fmt"

func fibonacci(n int) int{
  if (n < 2) {
    return 1
  }
  return fibonacci(n - 2) + fibonacci(n - 1)
}

func main() {
  fmt.Println(fibonacci(10))
}

run

$ 6g fibonacci.go
$ 6l fibonacci.6
$ time ./6.out
165580141

real  0m1.770s
user  0m1.769s
sys 0m0.001s

Conclusion

nodejs is very FAST.
luajit 2X faster than nodejs, Shocking.

posted @ 2011-12-14 22:21 MK2 阅读(182) 评论(1) 编辑

forever

A simple CLI tool for ensuring that a given script runs continuously (i.e. forever).
一个非常简单的CLI工具,让你的程序持续运行。

安装forever: https://github.com/nodejitsu/forever

$ [sudo] npm install forever -g

Demo: 进程重启超过5次后将不再运行

$ forever examples/error-on-timer.js -m 5

forever-webui

A simple web UI for efficient nodejs administration
既然有了CLI工具帮忙保证程序的持续运行,那么有个简单的web监控就更加好了。
forever-webui 就是这样一个web应用程序。

安装并运行

$ npm install forever-webui && node node_modules/forever-webui/app.js

浏览器访问 http://127.0.0.1:8085

http://ww4.sinaimg.cn/large/61c56ebcjw1dnd6elhv81j.jpg

PS:如果你使用forever来启动forever-webui,还可以自己监控自己喔,不知道会不会死循环?!

有爱

^_^ 希望本文对你有用。

posted @ 2011-11-23 02:33 MK2 阅读(726) 评论(0) 编辑

疑问

按nodejs官方的文档说明,使用Buffer操作字节流通常会比转化成String要高效。
实际情况全都是这样的吗?
本文通过一个简单的解析HTTP Request Header实例来解开此疑问。

HTTP Request Header Demo

POST /foo HTTP/1.1\r\n
Host: foo.example.com\r\n
Content-Length: 5\r\n
Connection:keep-alive\r\n
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n
Cookie:connect.sid=OY2nKGqI3obs5lYee0JKTjhf.FDtbY1Jz5Ngw5So9Jv3MUetI5ITvrIfwgCkRw%2FcXUCk\r\n
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.41 Safari/535.7
\r\n\r\n
q=bar

需求

获取Header中Host的值

Buffer版本

var SPACE = 0x20, // ' '
    COLON = 0x3a, // 58, :
    NEWLINE = 0x0a, // \n
    ENTER = 0x0d; // \r

exports.parse = function parse(data) {
    var line_start = 0, len = data.length;
    for(var i = 0 ; i < len; i++) {
        // Host: xxx.abc.com
        if(data[i] === COLON) {
            var key = data.toString('ascii', line_start, i).toLowerCase();
            i++; // skip ':'
            if(key === 'host') {
                var value_start = i;
                while(i < len) {
                    if(data[i] === ENTER) {
                        return data.toString('ascii', value_start, i).trim().toLowerCase();
                    }
                    i++;
                }
            }
        } else if(data[i] ===  ENTER && data[i+1] === NEWLINE) {
            i += 2;
            line_start = i;
            if(data[i] ===  ENTER && data[i+1] === NEWLINE) {
                // \r\n\r\n
                return 'Host header not found';
            }
        }
    }
    return null;
};

String版本

exports.parse = function parse(data) {
    var lines = data.toString('ascii').split("\n");
    var cut, name, host;
    for (var i = 0, len = lines.length; i < len; i++) {
        cut = lines[i].split(':');
        name = cut[0];
        if (name === 'Host') {
            if (cut[1] === undefined) {
                return 'Host header not found';
            }
            host = cut[1].trim().toLowerCase();
            return host;
        }
    }
    return null;
};

测试脚本

var buffer_parse = require('./string-buffer-benchmark-parse-header-buffer').parse
  , string_parse = require('./string-buffer-benchmark-parse-header-string').parse;

var data = new Buffer('POST /foo HTTP/1.1\r\nHost: foo.example.com\r\nContent-Length: 5\r\nConnection:keep-alive\r\nAccept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nCookie:connect.sid=OY2nKGqI3obs5lYee0JKTjhf.FDtbY1Jz5Ngw5So9Jv3MUetI5ITvrIfwgCkRw%2FcXUCk\r\nUser-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.41 Safari/535.7\r\n\r\nq=bar');

//console.log(buffer_parse(data));
//console.log(string_parse(data), data.length);

var n = 1000000;
var start = new Date();
for(var i = 0; i < n; i++) {
    buffer_parse(data);
}
console.log('buffer_parse take: ' + (new Date() - start) + ' ms');

start = new Date();
for(var i = 0; i < n; i++) {
    string_parse(data);
}
console.log('string_parse take: ' + (new Date() - start) + ' ms');

测试结果

$ node string-buffer-benchmark.js
buffer_parse take: 1888 ms
string_parse take: 4948 ms

结论

Buffer比String快多了。

posted @ 2011-11-19 01:21 MK2 阅读(343) 评论(0) 编辑

新版本 nodejs 性能

node0.6.0 已经发布了,性能提高如何呢?
本文将记录 nodejs 历史更新中所有版本的hello world性能测试。

测试环境

$ uname -a
Linux xxx 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:48 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux

$ cat /proc/cpuinfo
Intel(R) Xeon(R) CPU           E5410  @ 2.33GHz

测试 helloworld.js

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');

http_load 压测命令

$ http_load -p 100 -s 10 http://127.0.0.1:1337/

测试结果: fetches/sec

  • v0.7.x
0.7.0
7676
  • v0.6.x
0.6.70.6.60.6.50.6.40.6.30.6.20.6.10.6.0
77918046806081118070813882408157
  • v0.5.x
0.5.100.5.90.5.80.5.70.5.6 0.5.50.5.40.5.30.5.20.5.10.5.0
82007259707170986996 8073-79318127--
  • v0.4.x
0.4.120.4.110.4.100.4.90.4.8 0.4.70.4.60.4.50.4.4 0.4.30.4.20.4.10.4.0
75107558760076066588 7916793179607981 7930796579757490
  • v0.3.x
0.3.80.3.70.3.60.3.50.3.4 0.3.30.3.20.3.10.3.0
78107871781588809000 899992009347-
  • v0.2.x
0.2.60.2.50.2.40.2.3 0.2.20.2.10.2.0
7525748174897500 741071367130
  • v0.1.x
0.1.1040.1.1030.1.1020.1.1010.1.100 0.1.990.1.980.1.970.1.960.1.95 0.1.940.1.930.1.920.1.910.1.90 0.1.0
76407538753776747040 72807211734072707210 70637931802085618146 -

v0.6.0与v0.4.12的性能对比

v0.6.0更新 说明文章中,列出的对比数据

v0.4.12 (linux) v0.6.0 (linux)

http_simple.js /bytes/1024  5461 r/s    6263 r/s
io.js read                  19.75 mB/s  26.63 mB/s
io.js write                 21.60 mB/s  17.40 mB/s
startup.js                  74.7 ms     49.6 ms

v0.4.12 (windows: Cygwin) v0.6.0 (windows)

http_simple.js /bytes/1024  3858 r/s    5823 r/s
io.js read                  12.41 mB/s  26.51 mB/s
io.js write                 12.61 mB/s  33.58 mB/s
startup.js                  152.81 ms   52.04 ms

v0.4 和 v0.6之间的更新说明请查看: API-changes-between-v0.4-and-v0.6

node0.7.0

7675.8 fetches/sec, 92109.6 bytes/sec
msecs/connect: 0.050985 mean, 1.047 max, 0.02 min
msecs/first-response: 12.9343 mean, 47.329 max, 2.926 min

node0.6.7

7790.79 fetches/sec, 93489.5 bytes/sec
msecs/connect: 0.052154 mean, 0.716 max, 0.023 min
msecs/first-response: 12.7397 mean, 41.609 max, 5.318 min

node0.6.6

8046.29 fetches/sec, 96555.5 bytes/sec
msecs/connect: 0.0517639 mean, 0.396 max, 0.023 min
msecs/first-response: 12.3359 mean, 36.495 max, 4.808 min

node0.6.5

8060.28 fetches/sec, 96723.4 bytes/sec
msecs/connect: 0.0518643 mean, 0.702 max, 0.021 min
msecs/first-response: 12.3109 mean, 35.02 max, 4.762 min

node0.6.4

8111 fetches/sec, 97332 bytes/sec
msecs/connect: 0.051521 mean, 1.847 max, 0.021 min
msecs/first-response: 12.2351 mean, 49.227 max, 1.847 min

node0.6.3

8070 fetches/sec, 96840 bytes/sec
msecs/connect: 0.0517654 mean, 0.502 max, 0.02 min
msecs/first-response: 12.2967 mean, 51.886 max, 5.151 min

node0.6.2

8137.79 fetches/sec, 97653.5 bytes/sec
msecs/connect: 0.0515829 mean, 0.642 max, 0.021 min
msecs/first-response: 12.1961 mean, 42.128 max, 3.111 min

node0.6.1

8239.6 fetches/sec, 98875.2 bytes/sec
msecs/connect: 0.0530447 mean, 0.439 max, 0.022 min
msecs/first-response: 12.0422 mean, 32.93 max, 1.846 min

node0.6.0

8157.38 fetches/sec, 97888.5 bytes/sec
msecs/connect: 0.0512865 mean, 0.741 max, 0.022 min
msecs/first-response: 12.1661 mean, 46.023 max, 4.57 min

node0.5.10

8200 fetches/sec, 98400 bytes/sec
msecs/connect: 0.0517871 mean, 0.508 max, 0.024 min
msecs/first-response: 12.0963 mean, 34.816 max, 4.831 min

node0.5.9

7258.88 fetches/sec, 87106.6 bytes/sec
msecs/connect: 0.0521661 mean, 0.667 max, 0.022 min
msecs/first-response: 13.6817 mean, 49.23 max, 3.31 min

node0.5.8

7070.8 fetches/sec, 84849.6 bytes/sec
msecs/connect: 0.0523142 mean, 0.517 max, 0.022 min
msecs/first-response: 14.0466 mean, 39.545 max, 6.215 min

node0.5.7

7097.59 fetches/sec, 85171.1 bytes/sec
msecs/connect: 0.0526457 mean, 0.586 max, 0.024 min
msecs/first-response: 13.9935 mean, 44.333 max, 5.604 min

node0.5.6

6995.6 fetches/sec, 83947.2 bytes/sec
msecs/connect: 0.0525126 mean, 0.413 max, 0.022 min
msecs/first-response: 14.1971 mean, 37.55 max, 6.123 min

node0.5.5

8073.3 fetches/sec, 96879.6 bytes/sec
msecs/connect: 0.0509257 mean, 0.41 max, 0.02 min
msecs/first-response: 12.2924 mean, 44.222 max, 4.323 min

node0.5.4

出现编译错误:

/usr/bin/ld: skipping incompatible /usr/lib/libc.a when searching for -lc
/home/admin/pkgs/node-v0.5.4/build/default/deps/uv/uv.a(eio.o): In function `eio__sync_file_range':
/home/admin/pkgs/node-v0.5.4/build/default/deps/uv/src/eio/eio.c:1083: undefined reference to `sync_file_range'
collect2: ld returned 1 exit status
Waf: Leaving directory `/home/admin/pkgs/node-v0.5.4/build'
Build failed:  -> task failed (err #1): 
    {task: cxx_link node_main_5.o,node_5.o,node_buffer_5.o,node_javascript_5.o,
    node_extensions_5.o,node_http_parser_5.o,node_constants_5.o,node_file_5.o,
    node_script_5.o,node_os_5.o,node_dtrace_5.o,node_string_5.o,timer_wrap_5.o,
    handle_wrap_5.o,stream_wrap_5.o,tcp_wrap_5.o,pipe_wrap_5.o,cares_wrap_5.o,
    stdio_wrap_5.o,process_wrap_5.o,node_cares_5.o,node_net_5.o,
    node_signal_watcher_5.o,node_stat_watcher_5.o,node_io_watcher_5.o,
    node_stdio_5.o,node_child_process_5.o,node_timer_5.o,platform_linux_5.o,
    node_crypto_5.o,http_parser_3.o -> node}
make: *** [program] Error 1

node0.5.3

7931.39 fetches/sec, 95176.7 bytes/sec
msecs/connect: 0.0520728 mean, 0.701 max, 0.024 min
msecs/first-response: 12.5109 mean, 45.553 max, 5.302 min

node0.5.2

8126.8 fetches/sec, 97521.6 bytes/sec
msecs/connect: 0.0513291 mean, 2.476 max, 0.021 min
msecs/first-response: 12.2076 mean, 38.541 max, 1.328 min

node0.5.1

编译不通过,暂缺

node0.5.0

编译不通过,暂缺

node0.4.12

7510 fetches/sec, 90120 bytes/sec
msecs/connect: 0.0540341 mean, 0.631 max, 0.023 min
msecs/first-response: 13.2113 mean, 47.364 max, 3.807 min

node0.4.11

7557.79 fetches/sec, 90693.5 bytes/sec
msecs/connect: 0.0553164 mean, 0.467 max, 0.025 min
msecs/first-response: 13.13 mean, 44.789 max, 2.899 min

node0.4.10

7600 fetches/sec, 91200 bytes/sec
msecs/connect: 0.0534043 mean, 0.367 max, 0.022 min
msecs/first-response: 13.0584 mean, 53.123 max, 4.559 min

node0.4.9

7605.7 fetches/sec, 91268.4 bytes/sec
msecs/connect: 0.0539834 mean, 0.379 max, 0.02 min
msecs/first-response: 13.0469 mean, 46.833 max, 5.299 min

node0.4.8

6587.9 fetches/sec, 79054.8 bytes/sec
msecs/connect: 0.0512022 mean, 0.499 max, 0.021 min
msecs/first-response: 15.0846 mean, 49.04 max, 4.448 min

node0.4.7

7916.1 fetches/sec, 94993.2 bytes/sec
msecs/connect: 0.0516686 mean, 1.629 max, 0.021 min
msecs/first-response: 12.5375 mean, 43.116 max, 5.695 min

node0.4.6

7930.88 fetches/sec, 95170.6 bytes/sec
msecs/connect: 0.0517224 mean, 0.704 max, 0.022 min
msecs/first-response: 12.5125 mean, 42.465 max, 5.519 min

node0.4.5

7960 fetches/sec, 95520 bytes/sec
msecs/connect: 0.0522368 mean, 0.674 max, 0.021 min
msecs/first-response: 12.4676 mean, 43.185 max, 5.598 min

node0.4.4

7981.4 fetches/sec, 95776.8 bytes/sec
msecs/connect: 0.0511981 mean, 0.729 max, 0.02 min
msecs/first-response: 12.4255 mean, 51.829 max, 5.506 min

node0.4.3

7929.9 fetches/sec, 95158.8 bytes/sec
msecs/connect: 0.0510949 mean, 0.833 max, 0.023 min
msecs/first-response: 12.5189 mean, 51.677 max, 5.02 min

node0.4.2

7965.19 fetches/sec, 95582.3 bytes/sec
msecs/connect: 0.0526699 mean, 0.864 max, 0.023 min
msecs/first-response: 12.4563 mean, 42.695 max, 3.897 min

node0.4.1

7975.19 fetches/sec, 95702.3 bytes/sec
msecs/connect: 0.0527306 mean, 1.418 max, 0.021 min
msecs/first-response: 12.4361 mean, 47.871 max, 0.767 min

node0.4.0

7490 fetches/sec, 89880 bytes/sec
msecs/connect: 0.051049 mean, 0.691 max, 0.021 min
msecs/first-response: 13.255 mean, 51.421 max, 5.735 min

node0.3.8

7810 fetches/sec, 93720 bytes/sec
msecs/connect: 0.0514884 mean, 0.581 max, 0.02 min
msecs/first-response: 12.7136 mean, 43.613 max, 5.42 min

node0.3.7

7870.99 fetches/sec, 94451.9 bytes/sec
msecs/connect: 0.0527374 mean, 0.453 max, 0.022 min
msecs/first-response: 12.6068 mean, 37.022 max, 5.835 min

node0.3.6

7814.89 fetches/sec, 93778.6 bytes/sec
msecs/connect: 0.0522743 mean, 0.719 max, 0.023 min
msecs/first-response: 12.6983 mean, 37.436 max, 5.748 min

node0.3.5

8879.97 fetches/sec, 106560 bytes/sec
msecs/connect: 0.0571404 mean, 0.753 max, 0.022 min
msecs/first-response: 11.1496 mean, 46.028 max, 4.842 min

node0.3.4

9000 fetches/sec, 108000 bytes/sec
msecs/connect: 0.0566353 mean, 0.633 max, 0.023 min
msecs/first-response: 11.0017 mean, 46.633 max, 5.126 min

node0.3.3

8999.29 fetches/sec, 107992 bytes/sec
msecs/connect: 0.0569282 mean, 0.583 max, 0.022 min
msecs/first-response: 11.0035 mean, 43.218 max, 5.112 min

node0.3.2

9200 fetches/sec, 110400 bytes/sec
msecs/connect: 0.0582272 mean, 0.709 max, 0.023 min
msecs/first-response: 10.7557 mean, 32.685 max, 5.059 min

node0.3.1

9347.3 fetches/sec, 112168 bytes/sec
msecs/connect: 0.0564677 mean, 0.974 max, 0.022 min
msecs/first-response: 10.592 mean, 38.921 max, 4.77 min

node0.3.0

编译不通过

node0.2.6

7524.9 fetches/sec, 90298.7 bytes/sec
msecs/connect: 0.0581787 mean, 0.649 max, 0.02 min
msecs/first-response: 13.1609 mean, 105.413 max, 5.191 min

node0.2.5

7480.6 fetches/sec, 89767.1 bytes/sec
msecs/connect: 0.0589546 mean, 0.693 max, 0.023 min
msecs/first-response: 13.2442 mean, 94.122 max, 5.744 min

node0.2.4

7488.59 fetches/sec, 89863.1 bytes/sec
msecs/connect: 0.0595586 mean, 0.428 max, 0.023 min
msecs/first-response: 13.2342 mean, 95.229 max, 5.88 min

node0.2.3

7500 fetches/sec, 89999.9 bytes/sec
msecs/connect: 0.0591254 mean, 0.57 max, 0.024 min
msecs/first-response: 13.1974 mean, 94.721 max, 5.728 min

node0.2.2

7409.99 fetches/sec, 88919.9 bytes/sec
msecs/connect: 0.0597531 mean, 0.558 max, 0.021 min
msecs/first-response: 13.3618 mean, 102.09 max, 5.846 min

node0.2.1

7135.9 fetches/sec, 85630.8 bytes/sec
msecs/connect: 0.0565066 mean, 0.59 max, 0.023 min
msecs/first-response: 13.8999 mean, 100.855 max, 5.703 min

node0.2.0

7129.99 fetches/sec, 85559.9 bytes/sec
msecs/connect: 0.0565618 mean, 0.356 max, 0.02 min
msecs/first-response: 13.915 mean, 100.048 max, 4.344 min

node0.1.104

7640 fetches/sec, 91679.9 bytes/sec
msecs/connect: 0.0577092 mean, 0.564 max, 0.024 min
msecs/first-response: 12.9695 mean, 90.161 max, 3.711 min

node0.1.103

7538.38 fetches/sec, 90460.6 bytes/sec
msecs/connect: 0.0577052 mean, 1.091 max, 0.021 min
msecs/first-response: 13.1506 mean, 92.522 max, 5.378 min

node0.1.102

7537.49 fetches/sec, 90449.9 bytes/sec
msecs/connect: 0.0583015 mean, 0.396 max, 0.024 min
msecs/first-response: 13.1514 mean, 103.188 max, 5.577 min

node0.1.101

7673.9 fetches/sec, 92086.8 bytes/sec
msecs/connect: 0.0588679 mean, 0.767 max, 0.021 min
msecs/first-response: 12.9082 mean, 99.924 max, 4.776 min

node0.1.100

7040 fetches/sec, 84480 bytes/sec
msecs/connect: 0.0557378 mean, 0.592 max, 0.022 min
msecs/first-response: 14.0982 mean, 107.368 max, 6.009 min

node0.1.99

7279.99 fetches/sec, 87359.9 bytes/sec
msecs/connect: 0.0555776 mean, 0.569 max, 0.022 min
msecs/first-response: 13.6292 mean, 93.241 max, 5.983 min

node0.1.98

7210.6 fetches/sec, 86527.2 bytes/sec
msecs/connect: 0.0552844 mean, 0.379 max, 0.02 min
msecs/first-response: 13.7576 mean, 94.502 max, 5.685 min

node0.1.97

7339.55 fetches/sec, 88074.6 bytes/sec
msecs/connect: 0.057371 mean, 0.802 max, 0.022 min
msecs/first-response: 13.5052 mean, 89.268 max, 5.326 min

node0.1.96

7269.6 fetches/sec, 87235.2 bytes/sec
msecs/connect: 0.0566584 mean, 0.573 max, 0.021 min
msecs/first-response: 13.6483 mean, 60.543 max, 4.296 min

node0.1.95

7209.65 fetches/sec, 86515.9 bytes/sec
msecs/connect: 0.0565087 mean, 0.529 max, 0.024 min
msecs/first-response: 13.7617 mean, 60.438 max, 4.418 min

node0.1.94

7063.39 fetches/sec, 84760.6 bytes/sec
msecs/connect: 0.0547156 mean, 0.66 max, 0.022 min
msecs/first-response: 14.0522 mean, 130.751 max, 4.987 min

node0.1.93

7930.6 fetches/sec, 95167.2 bytes/sec
msecs/connect: 0.0587932 mean, 0.61 max, 0.023 min
msecs/first-response: 12.4891 mean, 77.833 max, 3.689 min

node0.1.92

8019.99 fetches/sec, 96239.9 bytes/sec
msecs/connect: 0.058158 mean, 0.718 max, 0.021 min
msecs/first-response: 12.354 mean, 79.033 max, 3.423 min

node0.1.91

8560.98 fetches/sec, 102732 bytes/sec
msecs/connect: 0.0596777 mean, 0.471 max, 0.022 min
msecs/first-response: 11.522 mean, 71.727 max, 3.235 min

node0.1.90

8146.18 fetches/sec, 97754.2 bytes/sec
msecs/connect: 0.0595273 mean, 0.826 max, 0.021 min
msecs/first-response: 12.1531 mean, 223.064 max, 3.189 min

node0.1.0

helloworld.js跑不起来了,出现一下异常:

hello.js:8: TypeError: Object # has no method 'createServer'
http.createServer(function (req, res) {
     ^

有爱

^_^ 希望本文对你有用

posted @ 2011-11-17 00:08 MK2 阅读(313) 评论(0) 编辑
摘要: 使用方法 @mashihua 同学在cnode新闻组发布了他维护的npm镜像源,速度很快! 以下是邮件内容: 很高兴的通知大家。在周末的空闲时间里,我们搭建了一个镜像的npm资源库,服务器在日本的Linode上。大家可用下面的命令来安装npm的模块: $ npm --registry "http://npm.hacknodejs.com/" install express 或下面的命令...阅读全文
posted @ 2011-11-16 16:05 MK2 阅读(345) 评论(0) 编辑
摘要: Change logs 完全基于Connect,提高整体响应性能; 移除对express, libxml2的依赖; Session使用Mongodb存储; NodeBlog 介绍 A blog base on nodejs. Demo: http://nodeblog.org, http://nodeblog.cnodejs.net Features Write, Read, Li...阅读全文
posted @ 2011-11-15 00:54 MK2 阅读(219) 评论(0) 编辑
摘要: 实例化解析: function Foo() {}; var foo = new Foo(); foo.__proto__ === Foo.prototype; foo.__proto__.__proto__ === Object.prototype; foo.__proto__.__proto__.__proto__ === null; foo.prototype === undefined;...阅读全文
posted @ 2011-11-02 15:02 MK2 阅读(202) 评论(0) 编辑
摘要: @Cnodejs社区的NAE 目前正在邀请内测中,目前已经增加自定义域名绑定。 只需在package.json文件中指定customHost属性即可。 例如我需要绑定nae.nodeblog.org => nodeblog.cnodejs.net ,只需在package.json增加一行即可: "customHost": "nae.nodeblog.org"阅读全文
posted @ 2011-10-27 02:29 MK2 阅读(259) 评论(0) 编辑
摘要: 本文收集我个人编译的一些离线文档 nodedoc.0.5.4.zip阅读全文
posted @ 2011-08-17 11:35 MK2 阅读(353) 评论(0) 编辑
摘要: 内存限制 大文件读写操作,由于内存限制问题,不要直接使用fs.readFile 和 fs.writeFile。 必须使用fs.ReadStream 和 fs.WriteStream 来对文件进行读写操作。 fs.ReadStream:上传大文件 var urlparse = require('url').parse , http = require('http') , fs = require('...阅读全文
posted @ 2011-08-16 12:19 MK2 阅读(734) 评论(0) 编辑
摘要: 问题 Nodejs原生的http.request 方法是不支持设置超时参数的,而网络请求经常会遇到超时的情况,特别是对于外部网络,如果不处理超时,发起的请求将会一直卡主,消耗的系统资源也不能及时被释放。 解决方案(旧) 定时器:通过定时器,当timeout事件触发的时候,主动调用req.abort() 终止请求,然后返回超时异常。 Request Timeout & Response Ti...阅读全文
posted @ 2011-08-09 21:30 MK2 阅读(714) 评论(0) 编辑
摘要: XMLHttpRequest.upload 在Firefox, Google Chrome and Safari中,如果通过XMLHttpRequest上传文件,是可以通过监听XMLHttpRequest.upload对象的progress事件来查看进度的。 var xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress"...阅读全文
posted @ 2011-08-05 15:22 MK2 阅读(730) 评论(2) 编辑
摘要: Buffer不会被GC? 为了看看这个问题,我写了一段测试代码 var http = require('http') , os = require('os'); function create(size, res) { var mb = 1024 * 1024; res.write('free ' + os.freemem() / mb + 'MB\r\n'); res.write('------...阅读全文
posted @ 2011-07-20 00:16 MK2 阅读(495) 评论(0) 编辑
摘要: 起因 看到simple todo的各种python版本实现, 我也来凑凑热闹...既然已经有这么多python版本了, 我就对比实现了一个Simple-TODO的nodejs版本: Node TODO, 模版和樣式全部copy自web.py版本. Source Code && Demo 源代码: https://github.com/fengmk2/todo 在线demo: http://api....阅读全文
posted @ 2011-07-07 15:18 MK2 阅读(896) 评论(3) 编辑