EventMachine 与 Node.js
我将开发一个协作网站,其中一项功能是具有实时更改的协作编辑。即,当两个或多个用户编辑同一个文档时,他们可以立即看到彼此的更改。 我有一些使用 Ruby on Rails 的经验,所以我正在考虑使用 EventMachine,但由于围绕 Node.js 的所有这些炒作,我知道我正在考虑使用它。那么,使用 Node.js 代替 EventMachine 的主要好处是什么?
太长了;博士 EventMachine 和 Node.js 之间的主要区别是什么(除了语言之外)?
I'm going to develop a collaborative site, and one of the features will be collaborative editing with realtime changes. i.e. when two or more users are editing the same doc, they can see each other changes as soon as they happen.
I have some experience with Ruby on Rails, so I was thinking about using EventMachine, but with all this hype around Node.js, I am know considering using it instead. So, what would be the main benefits of using Node.js instead of EventMachine?
tl;dr
What are the main differences between EventMachine and Node.js (besides the language)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
EventMachine 与 Rails 没有任何关系,除了它们都是用相同的语言编写的。您可以像 Node.js 一样获得 EventMachine;您所要做的就是不要将库添加到您的项目中。根据我的经验,EventMachine 库(如 em-http)比 Node.js 的任何库都要好得多。您可以使用纤程代替回调来避免回调地狱。由于所有回调,在 Node 中完全处理异常几乎是不可能的。另外,Ruby 是一种比 Javascript 更好、更完整的语言。
EventMachine has nothing to do with Rails apart from them both being written in the same language. You can get EventMachine as bare as Node.js; all you have to do is not add libraries to your project. In my experience the EventMachine libraries (like em-http) are much nicer than anything for Node. And you can use fibers instead of callbacks to avoid callback hell. Complete exception handling is pretty much impossible in Node because of all the callbacks. Plus Ruby is a nicer, more complete language than Javascript.
我倾向于“使用你所知道的”(即使它是一个更重的架构)。正因为如此,我认为它不像“EventMachine vs NodeJS”那么简单。主要的区别可以概括为:
也就是说,技术问题是可以克服的。 (在我看来)应该指导您做出决定的更重要的问题是:
两者之间存在相当多的技术差异。一个是语言,一个是框架。真的,您想要运行多大的堆栈?您的开发人员需要学习多少知识?您是否想要一个完整的堆栈,它可以为您提供许多您可能不会使用的细节,或者您是否想要一个运行速度极快且并发的简单框架,即使您可能需要编写额外的样板代码并学习新语言?
虽然 Rails 不像某些 Web 应用程序架构那么重,但与 NodeJS 中处理类似的吞吐量相比,您仍然需要更多的处理器能力。假设两个系统都有质量代码。在任一堆栈上编写的错误代码都会阻止堆栈发光。这实际上归结为 - 您是否真的想学习一种全新的做事方式,或者利用您目前对 Ruby 的理解来快速开展工作?
我知道这并不是一个明确的答案,但我希望这有助于指导您做出决定!
I tend towards the "use what you know" (even if it's a heavier architecture). Because of that, I don't see it being quite as simple as "EventMachine vs NodeJS." Mainly, the difference can be summarized as this:
That said, technical problems can be overcome. The more important questions (from my view) that should guide your decision are these:
There are quite a few technical differences between the two. One is a language, one is a framework. Really, how heavy of a stack you want to run? How much learning will your developers have to do? Do you want a full stack the gives you a lot of niceties, that you may not use, or do you want a bare bones set up that runs extremely fast and concurrent, even though you may have to write extra boiler plate code and learn a new lanugage?
While Rails is not as heavy as some web application architectures, you're still going to need more processor power than you would to handle a similar amount of throughput in NodeJS. Assuming quality code for both systems. Bad code written on either stack is going to prevent the stack from shining. It really comes down to- Do you really want to learn a whole new way of doing things, or utilize your current understanding of Ruby to get things off the ground fast?
I know it's not really a definitive answer, but I hope this helps guide you to a decision!
值得一提的是制作故事。与大多数 Rack 一样,EM 拥有大量经过充分测试的可用测试和监控工具,而 Node.js 在这方面还远远不够。
在撰写本文时,似乎几乎不可能从 Node 获得明确的指标来回答“我是否需要扩展”之类的问题。 Joyent 之类的工具已经开始出现,并且总是有自己的主张,但没有像 NewRelic 这样的工具。
从性能/可配置性的角度来看,Node.js 非常好,但就我个人而言,我暂时还不会在生产环境中托管它。
One thing worth mentioning is the production story. EM, like most Rack stuff, has plenty of testing and monitoring tools available that are well tested, whereas Node.js falls well short in this respect.
At the time of writing, it seems almost impossible to get clear metrics from Node to answer questions like 'Do I need to scale'. There are options starting to form out there from the likes of Joyent, and always the roll-your-own argument, but nothing anywhere near tools such as NewRelic.
Node.js is very good from a performance / configurability point of view, but personally I wouldn't host it in production just yet.
Node.js
您可以更好地对正在发生的事情进行低级别控制。您可以包含在 Node.js 之上构建的通用库,以根据自己的喜好调整抽象级别。例如,您可以使用 connect 或express,具体取决于您是否想要为您编写的视图引擎。
您可以使用 socket.io 或现在,具体取决于您希望客户端-服务器连接抽象程度。您可以选择包含众多 MVC 库中的任何一个,也可以编写自己的库。
Event-Machine
一个异步 IO 库,就像 Node.js 一样,
这取决于 Ruby 与 JavaScript 的偏好、您想要抽象或缺乏抽象的灵活性以及是否要使用 Node 作为实际的网络服务器。
Node.js
You get far better control low level control over what's going in. You can include general libraries to build on top of node.js to tweak your level of abstraction to your own liking. For example you can use connect or express depending on whether you want a view engine written for you.
You can use socket.io or now depending on how much you want your client-server connection abstracted. You can opt to include any of numerous MVC libraries or write your own.
Event-Machine
An asynchronous IO library just like node.js
It comes down to a Ruby vs JavaScript preference, how much flexibility you want with abstractions or lack of abstractions and whether you want to use node as your actual web server.
已经提出了关于混乱的详细视图...
如果您准备好学习和实验比您想象的更多,那么只是个人视图 [] node.js 会更好,因为:
它的线程机制很棒(灵感来自'erlang' 的线程机制)
你可以(轻松地)构建一个特定用途的服务器,这将是真正高效的
a detailed view at confusion has already been proposed... just a personal view
[] node.js will be better, if you are ready to learn and experiment more than you think because:
it's thread mechanism is awesome (inspired from that of 'erlang')
you can build a purpose specific server (easily) which will be real productive