Node.js v0.12.0 (Stable) 发布

oschina
 oschina
发布于 2015年02月07日
收藏 8

Node.js v0.12.0 (Stable) 发布,此版本相比 0.10 版本有较大的改进,详细改进请看 wiki。请注意,此版本包括 API 更新,需要更新大量依赖。

此版本值得关注的特性如下:

  • Streams 3

    • The Streams implementation now works the way you thought it already should, without introducing any changes to the API. Basically this means no more getting stuck in "old mode", there are only streams that are flowing or not.

    • Streams now support the use of cork and uncork mechanisms to prevent flushing writes out to the system if an application is going to be performing many writes in a row. There is an implicit uncork performed when you end a writable stream.

  • HTTP

    • maxSockets are no longer limited to 5. The default is now set toInfinity with the developer and the operating system given control over how many simultaneous connections an application can keep open to a given host.

    • Proper KeepAlive support means that sockets will stay open until they timeout at the configured time, are closed by the remote side, or the process exits. Developer's no longer have to make sure requests have been pipelined to keep the socket open, or use an alternative module to get that support.

    • Developers can also now explicitly flushHeaders to ensure time to first byte is low and proxied connections are held open.

  • Cluster

    • Now has two modes of operation, the new default is a round robin distribution mechanism where the master accepts new connections and distributes them to your workers. If you want you can still opt back into the old method where your workers are responsible for acception connections.

  • TLS

    • We have the new TLSWrap mechanism under the hood, this eliminates quite a few of the hops back and forth between JavaScript and our C++ implementations.

    • Added APIs for asynchronous SNI callbacks, OCSP stapling, and storage events.

  • Buffer

    • We use a more accurate mechanism for allocating memory for buffers now, which means you'll see less overhead and impact from holding onto to small slices of Buffers. This reduces the amount of memory pressure on the system, which means GC runs are quicker, which means Node.js is on CPU less, and thus lower latency for your applications.

  • child_process

    • spawnSync/execSync have been added to facilitate synchronous child processes, warning your node process won't make forward progress while waiting for the child to exit, caveat emptor!

  • Crypto

    • Added APIs for loading custom engines for use with compiled in OpenSSL.

    • More APIs support supplying the pass phrases.

    • Added APIs for RSA public/private key encryption/decryption.

  • VM

    • The module is now based on the Contextify module, which shares values from the sandbox to avoid missing changes inside the execution from appearing in the parent context.

  • 初步支持 ECMAScript Internationalization API 1.0 (ECMA-402)

    • By default, Node.js v0.12.0 binaries are shipped with ECMA-402 support, but only for the English language. In other words, the ECMA-402 API is working as you would expect, but only data for the English language is included. You can find more info on how to include more languages in the Wiki.

相关资源:

源代码:http://nodejs.org/dist/v0.12.0/node-v0.12.0.tar.gz

Macintosh Installer (Universal): http://nodejs.org/dist/v0.12.0/node-v0.12.0.pkg

Windows Installer: http://nodejs.org/dist/v0.12.0/node-v0.12.0-x86.msi

Windows x64 Installer: http://nodejs.org/dist/v0.12.0/x64/node-v0.12.0-x64.msi

Windows x64 Files: http://nodejs.org/dist/v0.12.0/x64/

Linux 32-bit Binary: http://nodejs.org/dist/v0.12.0/node-v0.12.0-linux-x86.tar.gz

Linux 64-bit Binary: http://nodejs.org/dist/v0.12.0/node-v0.12.0-linux-x64.tar.gz

Solaris 32-bit Binary: http://nodejs.org/dist/v0.12.0/node-v0.12.0-sunos-x86.tar.gz

Solaris 64-bit Binary: http://nodejs.org/dist/v0.12.0/node-v0.12.0-sunos-x64.tar.gz

Other release files: http://nodejs.org/dist/v0.12.0/

网站:http://nodejs.org/docs/v0.12.0/

文档:http://nodejs.org/docs/v0.12.0/api/

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处,尊重他人劳动共创开源社区。
转载请注明:文章转载自 OSCHINA 社区 [http://www.oschina.net]
本文标题:Node.js v0.12.0 (Stable) 发布
加载中

最新评论(19

eechen
eechen
@matyhtf 使用PECL扩展Redis,在开启多个Swoole工作进程压测时会出现以下错误:
Fatal error: Uncaught exception 'RedisException' with message 'read error on connection'
in /png/node/0.12.0/bin/benchmark/redis_swoole.php:9
Stack trace:
#0 /png/node/0.12.0/bin/benchmark/redis_swoole.php(9): Redis->set('time_php', 1423374378)
#1 [internal function]: {closure}(Object(swoole_http_request), Object(swoole_http_response))
#2 /png/node/0.12.0/bin/benchmark/redis_swoole.php(13): swoole_http_server->start()
#3 {main}
thrown in /png/node/0.12.0/bin/benchmark/redis_swoole.php on line 9

是不是Swoole里要访问Redis最好使用Swoole官方的异步Redis客户端?
matyhtf
matyhtf

引用来自“eechen”的评论

@matyhtf 请教个问题,$http->on()里使用外部的声明的$redis,会报:
Notice: Undefined variable: redis in /home/eechen/swoole.php on line 10
Fatal error: Call to a member function set() on a non-object in /home/eechen/swoole.php on line 10
<?php
$http = new swoole_http_server("0.0.0.0", 9501);
$http->set([
'worker_num' => 1 //开启1个工作进程
]);
$redis = new Redis();
$redis->pconnect('127.0.0.1', 6379);
$http->on('request', function (swoole_http_request $request, swoole_http_response $response) {
  $redis->set('time_php', time());
  $response->header('Content-Type', 'text/html;charset=UTF-8');
  $response->end('<!DOCTYPE html><html><head><meta charset="UTF-8" /><title>PHP测试</title></head><body>'.$redis->get('time_php').'</body></html>');
});
$http->start();

引用来自“eechen”的评论

恩,解决了,PHP提供了关键词use来连接闭包和外界变量.
$http->on()里的匿名函数后加 use ($redis) 就可以了:
$http->on('request', function (swoole_http_request $request, swoole_http_response $response) use ($redis) {...}
你的测试可能有问题。详细的基准测试对比,可以看这里 http://my.oschina.net/matyhtf/blog/338800
大漠真人
大漠真人

引用来自“大漠真人”的评论

@红薯 能不能把node的logo换一下,好难看的说。。

引用来自“红薯”的评论

已换
一如既往的高效率,给你1024个赞
eechen
eechen

引用来自“eechen”的评论

@matyhtf 请教个问题,$http->on()里使用外部的声明的$redis,会报:
Notice: Undefined variable: redis in /home/eechen/swoole.php on line 10
Fatal error: Call to a member function set() on a non-object in /home/eechen/swoole.php on line 10
<?php
$http = new swoole_http_server("0.0.0.0", 9501);
$http->set([
'worker_num' => 1 //开启1个工作进程
]);
$redis = new Redis();
$redis->pconnect('127.0.0.1', 6379);
$http->on('request', function (swoole_http_request $request, swoole_http_response $response) {
  $redis->set('time_php', time());
  $response->header('Content-Type', 'text/html;charset=UTF-8');
  $response->end('<!DOCTYPE html><html><head><meta charset="UTF-8" /><title>PHP测试</title></head><body>'.$redis->get('time_php').'</body></html>');
});
$http->start();
恩,解决了,PHP提供了关键词use来连接闭包和外界变量.
$http->on()里的匿名函数后加 use ($redis) 就可以了:
$http->on('request', function (swoole_http_request $request, swoole_http_response $response) use ($redis) {...}
eechen
eechen
@matyhtf 请教个问题,$http->on()里使用外部的声明的$redis,会报:
Notice: Undefined variable: redis in /home/eechen/swoole.php on line 10
Fatal error: Call to a member function set() on a non-object in /home/eechen/swoole.php on line 10
<?php
$http = new swoole_http_server("0.0.0.0", 9501);
$http->set([
'worker_num' => 1 //开启1个工作进程
]);
$redis = new Redis();
$redis->pconnect('127.0.0.1', 6379);
$http->on('request', function (swoole_http_request $request, swoole_http_response $response) {
  $redis->set('time_php', time());
  $response->header('Content-Type', 'text/html;charset=UTF-8');
  $response->end('<!DOCTYPE html><html><head><meta charset="UTF-8" /><title>PHP测试</title></head><body>'.$redis->get('time_php').'</body></html>');
});
$http->start();
eechen
eechen

引用来自“eechen”的评论

<?php
$http = new swoole_http_server("0.0.0.0", 9501);
$http->set([
'worker_num' => 1 //开启1个工作进程
]);
$redis = new Redis();
$redis->pconnect('127.0.0.1', 6379);
$redis->set('time_php', time());
$redis->get('time_php');
$http->on('request', function (swoole_http_request $request, swoole_http_response $response) {
  $response->header('Content-Type', 'text/html;charset=UTF-8');
  $response->end('<!DOCTYPE html><html><head><meta charset="UTF-8" /><title>PHP测试</title></head><body>'.time().'</body></html>');
});
$http->start();

测试: 并发1000,RPS为17614.
ab -r -c1000 -n50000 http://127.0.0.1:9501/

PHP Swoole开启1个工作进程,在1000并发的情况下仍然秒杀100并发的Node.JS,每秒处理的请求书RPS还是Node.JS的三倍还多,这是什么情况?
上述脚本只在启动时连接Redis进行set/get操作,$http->on响应请求时没有和Redis交互,所以RPS出奇的高.修改后重新测试:
<?php
$http = new swoole_http_server("0.0.0.0", 9501);
$http->set([
'worker_num' => 1 //开启1个工作进程
]);
$http->on('request', function (swoole_http_request $request, swoole_http_response $response) {
  $redis = new Redis();
  $redis->pconnect('127.0.0.1', 6379);
  $redis->set('time_php', time());
  $response->header('Content-Type', 'text/html;charset=UTF-8');
  $response->end('<!DOCTYPE html><html><head><meta charset="UTF-8" /><title>PHP测试</title></head><body>'.$redis->get('time_php').'</body></html>');
});
$http->start();

ab -r -c1000 -n50000 http://127.0.0.1:9501/
RPS为9742.17,仍然远远高于Node.JS.
红薯
红薯

引用来自“大漠真人”的评论

@红薯 能不能把node的logo换一下,好难看的说。。
已换
大漠真人
大漠真人
@红薯 能不能把node的logo换一下,好难看的说。。
新鲜的蟑螂
新鲜的蟑螂
这货受刺激了吧
返回顶部
顶部