EventMachine 与 Node.js

发布于 2024-10-30 05:46:07 字数 250 浏览 5 评论 0原文

我将开发一个协作网站,其中一项功能是具有实时更改的协作编辑。即,当两个或多个用户编辑同一个文档时,他们可以立即看到彼此的更改。 我有一些使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

星軌x 2024-11-06 05:46:07

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.

梦里兽 2024-11-06 05:46:07

我倾向于“使用你所知道的”(即使它是一个更重的架构)。正因为如此,我认为它不像“EventMachine vs NodeJS”那么简单。主要的区别可以概括为:

  • NodeJS 是一种框架/语言,是为处理 JavaScript 中基于事件的编程而编写的。这就是它的驱动力。这不是事后的想法,也不是第三方机制。它已经融入到语言中了。您创建回调/事件,因为这就是语言的构建方式。它不是第三方插件,不会改变您的工作流程。
  • EventMachine 是 Ruby 中的瑰宝,它使开发人员能够获得基于事件的编程模型的一些优点。它被大量使用并经过充分测试,但并未直接融入到该语言中。两者都锁定在一个 CPU 上,但通过 Nodes 核心的事件编程,它仍然具有优势。 Ruby 编写时并没有考虑到并发性。

也就是说,技术问题是可以克服的。 (在我看来)应该指导您做出决定的更重要的问题是:

  • 您的生产环境会是什么样子?您对服务器有完全的控制权吗?您可以随心所欲地托管它吗?或者首先是在共享系统上,然后您必须对此进行扩展?
  • 您团队中的所有开发人员都有能力快速学习一门新语言吗?他们能够以多快的速度理解中间层的基于事件的语言(例如 JavaScript)?
  • 您是否需要 Rails 提供的所有架构(完整的测试框架、脚手架、模型、控制器等)?或者说这太过分了?

两者之间存在相当多的技术差异。一个是语言,一个是框架。真的,您想要运行多大的堆栈?您的开发人员需要学习多少知识?您是否想要一个完整的堆栈,它可以为您提供许多您可能不会使用的细节,或者您是否想要一个运行速度极快且并发的简单框架,即使您可能需要编写额外的样板代码并学习新语言?

虽然 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:

  • NodeJS is a framework/language that was written to handle event based programming in JavaScript. That is its driving force. It's not an after thought, or a third party mechanism. It's baked right in to the language. You create callbacks/events because that's how the language is built. It's not a third party plug in, and doesn't alter your workflow.
  • EventMachine is a gem in Ruby that gives developers access to some of the goodness of the event based programming model. It's heavily used and well tested, but not baked directly in to the language. Both are locked to one CPU, but with event programming at Nodes core, it still has a leg up. Ruby wasn't written with concurrency in mind.

That said, technical problems can be overcome. The more important questions (from my view) that should guide your decision are these:

  • What will your production environment look like? Do you have complete control over the server? Can you host it however you want? Or will it be on a shared system to start with, and then you have to expand on that?
  • Do all the developers on your team have the ability to learn a new language very fast? How fast will they be able to understand an event-based language like JavaScript for the middle tier?
  • Do you need all of the architecture that Rails gives you (full Testing framework, scaffolding, models, controllers, etc)? Or is that overkill?

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!

回忆那么伤 2024-11-06 05:46:07

值得一提的是制作故事。与大多数 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.

半步萧音过轻尘 2024-11-06 05:46:07

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.

渡你暖光 2024-11-06 05:46:07

已经提出了关于混乱的详细视图...

如果您准备好学习和实验比您想象的更多,那么只是个人视图 [] 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文