Erlang 的容错能力对 Web 项目的真正好处是什么?
假设我们有一个 Web 项目,希望有大约 10000 个 Web 客户端同时连接到服务器。我们还假设一个客户端会话持续大约 25 分钟。
如果我们将 LAMP 堆栈或任何其他流行的 Web 堆栈/框架(Linux 上的 Ruby on Rails 和 Apache 等)与用 Erlang/OTP 构建的 Web 项目进行比较 - Erlang/OTP 在容错方面有何特点?其他框架不会?
客户端发生什么事件会导致整个 LAMP 堆栈崩溃,而 Erlang/OTP 会坚守阵地?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请注意,典型的 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.
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 DB 和Riak,他们的性能非常令人印象深刻,这意味着他们的 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 ofApache
, 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
withREST (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-erlangMany 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