瞎扯淡 Is Node.js Better?

hooopo · 2012年04月10日 · 最后由 jefffreylam 回复于 2012年10月11日 · 6481 次阅读

it's never about programming languages, all come down to the man writes it.

ruby 优雅强一点,速度慢一点,看你怎么加权了

#2 楼 @clc3123 node.js 很快么?我不了解它。不过同样是动态语言,我想,即使是快,也快不到哪里去吧

#4 楼 @googya 不是这样喔~ 性能主要是看语言的引擎。Node 的 javascript 引擎是 V8,支持 JIT。而 CRuby 的 VM 是 stack-based 虚拟机。性能是逊于 V8 的。JRuby,MacRuby 则借助其桥接的平台从而也有了 JIT,而 Rubinius 则利用 LLVM 实现了 JIT。这几款 Ruby 的实现性能都不错。

不过又说回来~ 实际上,很多应用的性能瓶颈并不在 VM 的性能上的,需要看应用的场景。脱离了应用场景来直接评判语言的 VM,意义也不大 :)

http://rubylearning.com/blog/2012/04/23/ruby-in-2012/ What is your opinion on Node.js? Is this the future? Do you think Node.js will beat Ruby in web application development?

Matt Aimonetti: This is a question I often get. I personally like node.js, I think it’s fun, easy to get started and with CoffeeScript, writing JavaScript (JS) is almost fun. That said, Node is really young, not very well documented and relies extremely heavily on callbacks which can be quite confusing at times. My experience with Node is limited, but as my personal project started growing, I started struggling to keep my code simple and easy to maintain. Because I already know Ruby quite well and because equivalent tools exist in Ruby land, I don’t see a real need to use Node besides being the new cool framework.

But the project is fast growing, the cross-platform focus is welcomed and I think that for some developers, Node.js can be a great solution, especially when developing simple web APIs.

Will it “beat” Ruby? Well, a framework and a programming language are two different things. Will it beat Rails in popularity, that’s a possibility due to the fact that JavaScript is becoming very popular. However, some of the issues I mentioned earlier might prevent Node.js to become as popular as some people seem to believe. Finally, at the end of the day, if a JS framework becomes a better solution than anything else I use, I will certainly switch. But so far, I don’t see that happening.

语言的性能不决定应用的性能,现在对 scalability 的看重更是高于 performance.

callback 调用太深,无论开发,debug 还是测试,都会欲仙欲死的............以前写 python 就是一边吐一边 twisted...直到 eventlet 的出现........

我要说句公道话: Node.js 性能比 Rails 强。但是,你整个 stack 跑起来以后,view, DB, controller,然后再用什么 expressjs 去搞搞。性能又强不了多少了。

而且大家要注意的是:

Node.js 是强在用来开发实时 web application 的。那个可以说跟 Rails 完全不搭噶的。跟 Ruby 的 EventMachine 搭噶的。EventMachine 性能绝对比 Node.js 快。一倍不敢说,但是快一点。EM 比 Node 最大的差别是 Node 的社区旺啊。所以插件支持多。

其实性能 还是 golang 好,内存消耗真少,全公司项目可以跑在一个服务器上,跑测试的时间不能上厕所了。 @sunfmin 可以作证。 但是 golang 的支持能跟 Rails 的社区比么,也没有最近火爆的 Node 社区比。所以暂时风头盖不上其他两个。有时候,性能不是一切,只是额外的获得而已,因为你什么都没做。

这个比快有什么用?开发学习曲线/开发快速和修改适应性才是关键 不然用汇编写个框架,肯定是飞快,可是写个表单估计得花个 1 个人月吧,谁干啊

@azhao 其实有时候也需要快 :) 这个时候你就得想其他办法了,比如网站计数器脚本。

#13 楼 @hlxwell 计数器这个例子好像不恰当...

@hooopo 51.la 的计数器脚本,每天至少接受上亿的请求。挺恰当的。

#15 楼 @hlxwell 这东西比的是数据库的设计和读写性能,和语言的快慢没多少关系。

#12 楼 @hooopo 好像很不错的样子啊,得空折腾一下 :)

#12 楼 @hooopo 顶一下老赵的 jscex,这个东西非常有价值,我一直很奇怪 node 社区的人为什么不重视这个方面,很难想象大伙会如此没眼光

@hooopo 你做任何事情都不能脱离整个 stack, 短板效应。今天数据库有问题明天网络有问题。 我上次做过一个实验。 前端 Nginx, 可以处理 20000 + r/s, 后端跑了 4 个 EventMachine, 4 核的机器,每个能处理 1w+ r/s,猜猜结果如何。6000r/s, 操作系统在分配资源上很多东西都消耗了性能。所以语言在快,还得考虑整个 stack 能否配合你上去。架构啊架构啊。架构师吃牛排是有理由的啊

#19 楼 @hlxwell 这部分应该可以优化的吧,希望分享经验啊

Node.js is just a server with some server side commonjs support. It itself is not a all included framework as rails is.

个人感觉 node.js 在 web 上的优势还是在于两点:

  1. 处理大量持续的 tcp 连接,也就是实时应用,
  2. 能够让前段和后端用同样的代码实现,提高代码复用,尤其对于一些 js 依赖很高的应用,服务器端可以为不支持 js 的浏览器和搜索引擎渲染出静态内容

目前这个方向的 node 应用框架有不少:比如 http://meteor.com http://derbyjs.com

而作为传统的 web 框架来使用就没有太大优势了,express 本身比 sinatra 就快不了多少,并且底层库 js 还是远不如 ruby 支持的好

服务器端可以为不支持 js 的浏览器和搜索引擎渲染出静态内容 這是甚麼意思?跟據 request header 中的 agent 發頁面嗎。實際意義不大,不如真接作 web 和移動兩個 view。而且 Node.js 是基於 gecko 的並不能自動解決跨流覽器的這兼容問題。

http://stackoverflow.com/questions/3436335/could-node-js-replace-ruby-on-rails-completely-in-the-future 最后一句亮了:

It's like that old joke about learning Chinese: it can't be that hard, even two year old Chinese kids speak it …

#24 楼 @hooopo

最后一句,其实讲的就是术业有专攻吧。那些讲一个可以完全替代另一个的理论,纯粹扯淡。

#26 楼 @poshboytl 这个有点标题党阿,而且老赵以前也解释过两种方案的优劣

#27 楼 @fsword JavaScript 早就已经有 yield 了 ...

#24 楼 @hooopo 用 ajax 的,多数只是用个回调函数,其实不需要理解异步编程模型。像 nodejs 中那种大量回调函数的场景,在客户端 javascript 中很难出现的。

#26 楼 @poshboytl 我是支持用 Fiber 来简化成顺序编程的

#19 楼 @hlxwell 说的很有道理,有很多其他的因素构成,比如系统的 IO,cpu,内存等等。

我一直觉着这俩没啥可比性,都不一样的东西...

把这个老贴翻出来学习

sqsy 整理学习 EventMachine 的一些文章和帖子 提及了此话题。 09月08日 17:05
需要 登录 后方可回复, 如果你还没有账号请 注册新账号