您在 Erlang 上使用 Nitrogen 的体验如何?
我一直在查看 Nitrogen Project,它应该是 Erlang 最成熟的 Web 开发框架。
Erlang 作为一种语言,是非常令人印象深刻的。然而,对于 Nitrogen,我不太热衷于使用 Erlang 相当不常见的语法(除非您是 PROLOG 本地语言)来构建 UI。
与 Django 或 Rails 等其他主流 Web 框架相比,您对它的体验如何?
I've been checking out the Nitrogen Project which is supposed to be the most mature web development framework for Erlang.
Erlang, as a language, is extremely impressive. However, with regards to Nitrogen, what I am not too keen about is using Erlang's rather uncommon syntax (unless you're native in PROLOG) to build UIs.
What is your experience with it as opposed to other mainstream web frameworks such as Django or Rails?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
到目前为止,我对 Nitrogen 的了解还很少,但我已经监控邮件列表几个月了,所以我想我有一些有用的内容要说。
对于您对 Erlang 和 Nitrogen 框架语法的担忧,我的回答是,这听起来纯粹是不熟悉,而不是不适合。客观地说,HTML 并不是一种美丽的语言,而且它有很多怪癖。你现在已经习惯了,所以看起来并没有那么糟糕。给 Nitrogen/Erlang 一个机会,您可能会发现您也很快就习惯了它。
对于您关于与其他语言和框架进行比较的问题,我想说最大的区别是,使用 Nitrogen,整个网站都直接由 Erlang 运行时提供服务。 Ruby on Rails 有这样的模式,但它仅用于测试。许多其他框架甚至不提供在单个长时间运行的进程中运行所有内容的选项。
在单个长时间运行的进程中运行整个 Web 应用程序及其底层基础设施对站点的运行方式具有重大影响:
使用 Apache,每个子进程会在每 N 个连接中被终止,其中 N=500 左右,您可以不能说某个给定的子进程是否总是会处理给定客户的所有请求。由于 HTTP 是无状态的,但 Web 应用程序几乎总是需要一些客户端状态,因此 Apache 子级必须重建其客户端状态视图,作为处理新连接的一部分。默认情况下,这意味着返回磁盘以获取存储的有关该客户端的持久数据。还有诸如 memcached 之类的替代方案,但这些方案并未内置到 LAMP 类型堆栈的核心中。使用 Erlang,不会定期删除任何内容,并且 Erlang 提供标准设施,例如 Mnesia,它提供磁盘支持的内存数据库。
顺便说一句,如果您熟悉 nginx,它的构建原理与 Erlang 相同,而且速度很快同样的原因。 nginx 和运行 Web 服务器的 Erlang 实例之间的主要区别在于 nginx 不是编程环境,因此它仍然需要将大量处理委托给外部代码。这意味着它与 Apache 具有相同的 IPC 和持久状态问题。
由于运行时持续运行并且是一个功能齐全的编程环境,因此您可以在 Erlang 中构建比使用捆绑在一起的 LAMP 类型堆栈更多的系统部分。这放大了上述好处。系统的各个部分可以通过消息传递和 Mnesia 进行协调,而不是重量级的 IPC 和 MySQL,并且所有部分都保持正常运行并持续运行,从而减少耗时的状态重建。
十几个左右的 Apache 子进程都访问持久客户端状态数据存储,这是一个基于锁的毛团。这些框架都透明地为您处理锁定等问题,但它们无法隐藏的是正确完成所有这些操作所需的时间。
Erlang 是一种不纯粹的函数式语言,这意味着但不要求数据纯粹性;它还在构建时考虑了多处理,明确了运行时设计的核心。这两个事实意味着,与在其他框架之一上构建的服务器相比,您不太可能花时间在基于 Erlang 的服务器中等待锁。当然可以优化其他系统中的锁定延迟,但这真的是您想要做的吗?您是否想成为在服务流行后必须学习如何优化其 Web 堆栈的第一千个团队中的一员,或者您宁愿将其全部交给工具,以便您可以花时间做其他人尚未做过的事情?
I've done very little with Nitrogen so far, but I've been monitoring the mailing list for months, so I think I have something useful to say about it.
To your concern about the syntax of Erlang and the Nitrogen framework, I'd respond that that sounds like a pure case of unfamiliarity, rather than unsuitability. Objectively, HTML is not a beautiful language, and it has plenty of quirks. You're used to this now, so it doesn't seem so bad. Give Nitrogen/Erlang a chance and you may find that you get used to it soon enough, too.
To your question about comparison to other languages and frameworks, I'd say the biggest difference is that with Nitrogen, the entire web site is being served directly by the Erlang runtime. Ruby on Rails has such a mode, but it's intended only for testing. Many other frameworks don't even offer the option of running everything within a single long-running process.
Running the entire web application and its underlying infrastructure within a single long-running process has significant implications on how the site runs:
With Apache, each child gets killed off every N connections, where N=500 or so, and you can't say whether a given child will always handle all of a given client's requests. Because HTTP is stateless but web apps almost always require some client state, an Apache child must rebuild its view of client state as part of handling a new connection. By default, this means going back to disk for persistent data stored about that client. There are alternatives like memcached, but these aren't built into the core of a LAMP type stack. With Erlang, nothing is killed off periodically, and Erlang offers standard facilities like Mnesia which provide disk-backed in-memory DBs.
Incidentally, if you're familiar with nginx, it's built on the same principles as Erlang, and it's fast for the same reason. The main difference between nginx and an Erlang instance running a web server is that nginx isn't a programming environment, so it still has to delegate a lot of processing to outside code. That means it shares the same IPC and persistent state problems as Apache.
Because the runtime stays up continuously and is a fully-functional programming environment, you can probably build more parts of your system in Erlang than with a lashed-together LAMP type stack. This magnifies the above benefits. The various parts of your system can coordinate via message passing and Mnesia instead of heavyweight IPC and MySQL, and all the pieces stay up and running continually, leading to less time-consuming state reconstruction.
A dozen or so Apache children all accessing the persistent client state data store is a lock-based hairball. The frameworks all handle locking and such for you transparently, but what they can't hide is the time it takes to do all this correctly.
Erlang is an impure functional language, which implies but does not require data purity; it is also built with multiprocessing in mind, going clear down to the core of the runtime design. These two facts mean you're less likely to spend time waiting on locks in an Erlang based server than one naively built on one of the other frameworks. It is certainly possible to optimize away lock delays in the other systems, but is that really what you want to be doing? Do you want to be on the thousandth team that has to learn how to optimize its web stack after the service becomes popular, or would you rather leave it all up to the tooling so you can spend your time doing something no one else has done yet?
我也曾经担心过笨重的 Erlang 语法。我构建了一些工具来减轻日常网络编程的烦恼,也许您会发现其中一个或两个都有帮助:
ErlyDTL 是 Django 模板语言的 Erlang 实现;它在 Nitrogen 中不可用,但在其他框架中可用,例如 Zotonic、Erlang Web、BeepBeep 和 Chicago Boss
Chicago Boss 是一个全栈 Erlang 框架,它生成大量代码,以便您可以通过函数调用访问数据字段,而不是 Erlang 相当冗长的记录语法(例如
Person:name()< /code> 而不是
Person#person.name
)请注意,Nitrogen 不包含数据库层,因此它无法与 Rails 或 Django 真正相媲美。要对数据库驱动框架进行全面比较,请查看我对此 StackOverflow 问题的回答:
https://stackoverflow.com/questions/1822518/current-state-of-erlang-web-development-frameworks-template-languages/2898271#2898271
I, too, was once concerned about clunky Erlang syntax. I've built a couple of tools to alleviate its annoyances for everyday web programming, and perhaps you will find one or both of them helpful:
ErlyDTL is an Erlang implementation of the Django Template Language; it's not available in Nitrogen, but it is available in other frameworks, such as Zotonic, Erlang Web, BeepBeep, and Chicago Boss
Chicago Boss is a full-stack Erlang framework that does a lot of code generation so that you can access data fields with function calls instead of Erlang's rather verbose record syntax (e.g.
Person:name()
instead ofPerson#person.name
)Note that Nitrogen does not include a database layer, so it's not really comparable to Rails or Django. For a comprehensive comparison of the database-driven frameworks, check out my answer to this StackOverflow question:
https://stackoverflow.com/questions/1822518/current-state-of-erlang-web-development-frameworks-template-languages/2898271#2898271
如果我是你,我会查看Webmachine。它非常简单、快速,并且界面由您决定。
I would check out Webmachine if I were you. It is quite simple, fast, and leaves the interface up to you.
Erlang Web 也应该被认为是成熟的。它是一个 MVC 框架,而 Nitrogen 则更多地基于事件。这是一个偏好问题。
除了 Webmachine 之外,我没有使用过这里提到的其他工具,我认为它是一个很棒的工具,但它不像其他工具那样是一个 Web 框架。它作为 HTTP 处理器,非常适合构建宁静的接口。
我还建议你给 Erlang 语法一个机会。 Erlang 是我最喜欢使用的语言之一。
Erlang Web should also be considered mature. It is an MVC framework, whereas Nitrogen is more event based. It's a matter of preference.
I haven't used the other tools mentioned here except Webmachine, which I think it's a wonderful tool, but it is not a web framework like the others. It is as HTTP processor, and is ideal for building a restful interfaces.
I would also suggest you give the Erlang syntax a chance. Erlang is one of my favourite languages to use.