Erlang 的容错能力对 Web 项目的真正好处是什么?

发布于 2024-12-09 18:36:52 字数 262 浏览 2 评论 0 原文

假设我们有一个 Web 项目,希望有大约 10000 个 Web 客户端同时连接到服务器。我们还假设一个客户端会话持续大约 25 分钟。

如果我们将 LAMP 堆栈或任何其他流行的 Web 堆栈/框架(Linux 上的 Ruby on Rails 和 Apache 等)与用 Erlang/OTP 构建的 Web 项目进行比较 - Erlang/OTP 在容错方面有何特点?其他框架不会?

客户端发生什么事件会导致整个 LAMP 堆栈崩溃,而 Erlang/OTP 会坚守阵地?

Let's assume we have a web project in which we want to have ~10000 web clients connected to the server simultaneously. Let's also assume that one client session lasts about 25 minutes.

If we compare LAMP stack or any other popular web stack/framework (Ruby on Rails with Apache on Linux, etc.) to a web project built in Erlang/OTP - what does Erlang/OTP have in terms of fault tolerance that other frameworks don't?

What event can happen to a client that will cause the whole LAMP stack crash, while Erlang/OTP will stand its ground?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

北方的韩爷 2024-12-16 18:36:53

请注意,典型的 LAMP 堆栈确实采用了一定的容错能力。特别是,如果 LAMP 堆栈中的请求失败,则只有该请求失败,而其余代码将继续运行。这种保护允许您在单个请求中出现错误,而不会影响其他请求。

Erlang 提供了这种“能够以更细粒度的方式应对较小的不可预见的错误”的想法。您的应用程序中可能有其他子系统,并且可以将相同类型的错误容忍度扩展到这些子系统。您不会“免费”获得它,但工具可以构建一个强大的系统。想象一下 LAMP 堆栈中的客户端错误。这通常会导致该客户端断开连接。在 Erlang 中可能不是这样,客户端可以继续运行。

对于拥有 10000 个客户端的系统,Erlang 提供的优势是每个客户端可以有一个进程。或者每个客户端可能有 10 个进程。这在许多语言中都很难实现,因为进程/线程相当繁重且昂贵。请注意,客户端之间的进程间通信很容易,即使某些客户端位于另一台计算机上(想象一下有一天扩展到分布式集群)。

如果您以某种方式编写代码,则可以确保如果客户端由于某种原因崩溃,则其他进程可以正确清理其状态。这也可以避免状态中大量令人讨厌的小泄漏。

Note that a typical LAMP-stack does employ some fault tolerance. In particular, if a request in the LAMP stack fail, only that request will, while the rest of the code will run on. This kind of protection allows you to have faults in a single request without that hurting other requests.

Erlang provides this idea of "able to cope with smaller unforseen errors" at a much finer grained scale. You may have other subsystems in an application, and the same kind of tolerance to errors can be extended to those. You won't get it "for free", but the tooling is there to build a system which is robust. Imagine a client error in the LAMP stack. This will often lead to a disconnect of that client. It may not be so in Erlang and the client can keep on running.

For a system of 10000 clients, Erlang provides the advantage that you can have a process per client. Or perhaps 10 processes per client. That is much harder to pull of in many languages since a process/thread is rather heavy and expensive. Note that interprocess communication between the clients are easy, also if some clients are on another machine (imagine extending to a distributed cluster some day).

If you write your code in a certain way, you can make sure that if a client crashes, for one reason or the other, then its state is properly cleaned up by other processes. That can avoid lots and lots of small nasty leaks in state as well.

幸福%小乖 2024-12-16 18:36:53

Erlang/OTP 在容错方面有什么其他框架没有的?

现在,Erlang/OTP 的副作用非常小(如果没有的话),零副作用。由于其并发性,像 yaws 这样的 Web 服务器实际上是这样的为每个连接生成一个小型 Web 服务器。如果一名用户受到应用程序中给定 Web 服务故障的影响,所有其他用户将永远不会注意到,并且唯一的用户进程可能会退出。

借助 OTP,您可以构建具有多个supervisor,这样,如果服务器出现故障,它会重新启动以及您可能需要的许多其他功能和选项。

Erlang的发行版允许我们编写分布式应用程序。我个人在构建 Web 应用程序时使用过 yaws Web 服务器。

我的经验是,无论您选择哪个网络服务器,例如 Mochiweb,此处找到的教程:http://alexmarandon.com/articles/mochiweb_tutorial/,性能相当令人印象深刻。事实上,几年前,最旧版本的 yaws Web Server 已使用(当时)最新版本的 Apache基准测试的结果非常令人振奋。当我经历了百万使用 Mochiweb 的用户 comet 应用程序,其中具有 第 2 部分第 3 部分,给我留下了深刻的印象。这些是为 Web 构建的强大 Web 框架的一些示例。

顺便说一句,您是否听说过这些新的 NO SQL 数据库,其使用 Erlang/OTP 开发的 REST (HTTP) 接口,例如 Membase 服务器 [主页在这里: http://www.couchbase.com/products-and-services/ membase-server]、Couch DBRiak,他们的性能非常令人印象深刻,这意味着他们的 Web/REST 界面非常稳定,并且由于他们令人印象深刻,通过记录 write through put,他们证明了他们的底层技术 (Erlang/OTP) 不仅是为高可用性和容错系统构建的,而且也是为 Web 构建的!只需阅读此文档:http://blog.couchbase.com/why- membase-uses-erlang

更多用 erlang 构建且令人印象深刻的 Web 框架可以在此处的 wiki 页面上找到:http://en.wikipedia.org/wiki/Erlang_(programming_language) 。可以在这里找到使其在网络上强大的功能的更好总结:http://cs.nyu.edu/~lerner/spring10/projects/Erlang.pdf

what does Erlang/OTP have in terms of fault tolerance that other frameworks don't?

Now, Erlang/OTP has very minimal if not, Zero side effects. Because of its concurrency, a web server like yaws literally spawns a small web server for every connection. If one user is affected by a given web service fault in your application, all other users will never notice and the only that users process may exit.

With OTP, you can build applications with a number of supervisors, such that if a server goes down, its restarted and many other functions and options you may need.

Erlang's distribution allows us to write distributed applications. I have personally used yaws web server in building a web application.

My experience is that which ever web server you may pick, say Mochiweb, a tutorial found here: http://alexmarandon.com/articles/mochiweb_tutorial/, is quite impressive in performance. Infact, a few years back, the oldest version of yaws web Server was bench marked with the (then) newest version of Apache, and the results of the bench mark are very awakening. When i went through a million user comet application with Mochiweb, which has Part 2 and Part 3, i was impressed. These are some of the few examples of powerful web frameworks built for the web.

And by the way, have you heard of these new NO SQL Databases with REST (HTTP) interface developed in Erlang/OTP e.g. Membase Server [home page here: http://www.couchbase.com/products-and-services/membase-server], Couch DB, and Riak, their performance is very impressive, meaning that their web/REST interface is very stable and due to their impressive , documented write through put, they have proved that their underlying Technology (Erlang/OTP), was built not only for high availability and fault-tolerant systems only, but for the web too! Just read through this document: http://blog.couchbase.com/why-membase-uses-erlang

Many more web frameworks built in erlang and are very impressive can be found listed on the wiki page here: http://en.wikipedia.org/wiki/Erlang_(programming_language). A probably better summary of its features that make it powerful on the web can be found in here: http://cs.nyu.edu/~lerner/spring10/projects/Erlang.pdf

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