用于 Comet 应用程序的 Node.js 与 Java

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4488614/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 06:35:57  来源:igfitidea点击:

Node.js vs Java for Comet application

javanode.jscometgrizzly

提问by SyBer

We look to build a high-performance, scalable Comet server, and thought first about using Java Grizzly with GlassFish.

我们希望构建一个高性能、可扩展的 Comet 服务器,并首先考虑将 Java Grizzly 与 GlassFish 结合使用。

But after some research, we see that Node.JS is taking rapidly as the preferred choice due to extreme simplicity, and claimed performance:

但经过一些研究,我们发现 Node.JS 由于极其简单而迅速成为首选,并声称其性能:

http://news.ycombinator.com/item?id=1088699

http://news.ycombinator.com/item?id=1088699

http://amix.dk/blog/post/19484

http://amix.dk/blog/post/19484

I will be happy to hear some real-life experience of using both, and what ultimately can be the best choice down the road.

我会很高兴听到一些使用两者的真实体验,以及最终可能是最好的选择。

Thanks!

谢谢!

回答by Sanjay T. Sharma

If you would further read the blog posts by the same author, namely the post, Is node.js best for Comet, he explains why he again went back to the Java based solution (Netty) and is happy with it. I guess that would be an interesting read.

如果您想进一步阅读同一作者的博文,即文章Is node.js best for Comet,他解释了为什么他再次回到基于 Java 的解决方案 (Netty) 并对此感到满意。我想那将是一个有趣的阅读。

回答by brandizzi

I know this is an old and already answered question but I think my experience can be helpful.

我知道这是一个古老且已经回答的问题,但我认为我的经验可能会有所帮助。

I started a little pet project to test Node.js - how it "feels" and how to program on it. I became impressed by the ease of working in such ecosystem: Node.js code is easy to write (although its asynchronous paradigm is not that straightforward for the conventional programmer), libraries are easy to build etc. etc. Even npm is amazingly easy: I just found the most straightforward way to provide code of your own as a library is to make a public package of it!

我开始了一个小项目来测试 Node.js——它“感觉”如何以及如何在它上面编程。在这样的生态系统中工作的便利性给我留下了深刻的印象:Node.js 代码很容易编写(尽管它的异步范式对传统程序员来说并不那么简单),库很容易构建等等。甚至 npm 也非常简单:我刚刚发现将您自己的代码作为库提供的最直接方法是制作它的公共包!

However, there is not much good tools to work with Node.js. Maybe because it is tooeasy to do anything, most libraries are partially-implemented, undocumented solutions (and I am guilty too).

然而,没有太多好的工具可以使用 Node.js。也许是因为做任何事情都容易了,大多数库都是部分实现的、未记录的解决方案(我也很内疚)。

Also, note that the relevant difference of Node.js is not the JavaScript language, but the asynchronous I/O model. It is the most interesting aspect of Node.js, but the asynchronous programming style is not as well tested as the conventional way of web development. Maybe it is really the marvel that is propagandized - or perhaps, it is not as good as promised.

另请注意,Node.js 的相关差异不是 JavaScript 语言,而是异步 I/O 模型。这是 Node.js 最有趣的方面,但异步编程风格没有像传统的 Web 开发方式那样经过充分测试。或许,宣传的真的是奇迹——或许,并没有想象中的那么美好。

Even in the case it pays off, will you have enough developers to maintain such an (at least still) unusual codebase? If you can get a lot of advantages from the asynchronous "way of life" of Node.js, you can use more consolidated languages and frameworks, such as Twistedfor Python (which is my preferred languabe, so take care with my opinion :) ). There may be something like this for Java, too. Anyway, I suspect that you do not have a lot of interest in this model for now, since your question focuses more on languages than in the programming paradigm, so Node.js does not have much to offer to you anyway.

即使它得到了回报,您是否有足够的开发人员来维护这样一个(至少仍然是)不寻常的代码库?如果你能从 Node.js 的异步“生活方式”中获得很多优势,你可以使用更统一的语言和框架,比如Twistedfor Python(这是我的首选语言,所以请注意我的意见:) )。Java 也可能有类似的东西。无论如何,我怀疑你现在对这个模型没有太大兴趣,因为你的问题更多地关注语言而不是编程范式,所以 Node.js 无论如何都没有给你提供太多东西。

So... no, I would not develop something professonaly in Node.js for now, although I think it is both fun and instructive to study.

所以……不,我暂时不会在 Node.js 中开发一些专业的东西,尽管我认为学习它既有趣又有益。

回答by jmarranz

In my opinion the asynchronous approach for Comet glorified in Node.JS and Grizzly is deeply flawed.

在我看来,在 Node.JS 和 Grizzly 中美化的 Comet 异步方法存在严重缺陷

回答by Matt

In a more recent test (August 2012), Node.js was able to handle 1 million single connections from a single 16GB RAM Server.

在最近的一次测试中(2012 年 8 月),Node.js 能够处理来自单个 16GB RAM 服务器的 100 万个单个连接。

http://blog.caustik.com/2012/08/19/node-js-w1m-concurrent-connections/

http://blog.caustik.com/2012/08/19/node-js-w1m-concurrent-connections/