使用 OTP/Erlang 作为 Web 应用程序基于组件的架构的一部分
我有一个 Erlang/OTP 应用程序,它执行一些业务逻辑。它是用 Erlang 编写的,主要是为了容错,因为我可以轻松地重新启动系统崩溃的组件之一(高正常运行时间是最重要的要求)。 它的每个组件都执行某种特定的“并行”计算。
作为一个工作周期的结果,应用程序会生成一个值列表。我们将此 Erlang/OTP 应用程序称为“后端”。
此 Erlang/OTP 应用程序还将使用 PostgreSQL 服务器将结果存储在持久存储中,并存储其计算所需的附加元信息(尚未实现)。
接下来,我需要向此 Erlang/OTP 应用程序添加一个前端 - 一个简单的基于 Web 的解决方案,可以为 Web 用户提供服务:接受他/她的计算请求,要求后端进行计算并将后端的结果返回给用户。
没有可扩展性要求,我认为每天的最大用户数不能超过 1000。
所以我现在的任务是为我的后端 Erlang/OTP 应用程序实现一个通用前端(通用意味着我有典型的用例:访问网站、注册、登录、使用应用程序、在漂亮的 ajax 网页上获取结果、注销)。
一方面,我知道代码重用可以节省我很多时间:例如,使用 Ruby on Rails,我可以免费获得用户身份验证、密码存储、ajax 接口和许多其他东西。
另一方面,我对设计一个包含 Erlang/OTP + PostgreSQL 数据库服务器后端和作为前端的 Web 框架(RoR、Django 等)的应用程序一无所知。
我的脑海中浮现出很多问题:Erlang/OTP 和 Web 框架是否应该使用相同的 PostgreSQL 数据库来共享结果?将计算请求从 Web 框架发送到 Erlang/OTP 应用程序并取回的最佳方法是什么?我如何监督 PostgreSQL 服务器 - 它不受 OTP 容错能力的覆盖?
一般来说,我有一些异构软件组件,我想用它们构建一个工作系统(“主要”组件是 Erlang/OTP 应用程序)。
我应该从哪里开始执行这项任务?您能给我任何建议或提示我要阅读哪些资源吗?
PS我尝试阅读此并按照链接进行操作,但没有了解很多。
UPD:我知道 Chicago Boss 和其他 Erlang Web 框架确实存在,但我怀疑它们中是否有任何一个拥有如此成熟的环境、充满活力的社区以及不同插件和库(例如 Ruby)的巨大变化在 Rails、Django 或任何基于 PHP 的 MVC 框架上。正确的?
UPD2:也许我必须更深入地阐述这一点:我还需要前端尽可能可维护。在 Erlang 中进行这意味着我可能会面临寻找合适的开发人员来维护它的问题;在 RoR、Django 等中这样做意味着我可以轻松找到劳动力来维护前端并发展它。
I have an Erlang/OTP application which does some business logic. It is written in Erlang mostly for fault-tolerance, because I can easily restart one of the crashed components of the system (high uptime is the most important requirement).
Each of its components does some sort of specific "parallel" computations.
As a result of one working cycle the application produces a list of values. Let's call this Erlang/OTP application a "back-end".
This Erlang/OTP application would also use a PostgreSQL server to store the results in the persistent storage and to store additional meta-information needed for its computations (not implemented yet).
Next I need to add a front-end to this Erlang/OTP application - a simple web-based solution which can serve to a web user: accept a request for computations from him/her, ask the back-end to do the computations and give the user back the result from the back-end.
There is no scalability requirement, I think that the maximum number of users per day can be no more than 1000.
So my current task now is to implement a common front-end for my back-end Erlang/OTP application (common means I have a typical use case: visit the site, register, log-in, use the app, get the result on a nice ajax'y looking web-page, log-out).
On one side, I know that code reuse can save me a lot of time: for example with Ruby on Rails I can get user authentication, password storage, ajax interfaces and a lot of other stuff for free.
On the other side I do not know anything about designing an application which comprises an Erlang/OTP + PostgreSQL db server back-end and a web-framework (RoR, Django, etc) as a front-end.
I lot of questions spring in my mind: Should Erlang/OTP and the web-framework use the same PostgreSQL database to share the result? What is the best way to send a computation request from the web-framework to the Erlang/OTP application and get it back? How do I supervise the PostgreSQL server - it is not covered by OTP's fault tolerance?
Generally speaking, I have a few heterogeneous software components and I want to build a working system from them (the 'chief' component is the Erlang/OTP application).
Where I should start with this task? Can you give me any advice or a hint which resources to read?
P.S. I have tried to read this and followed the links, but did not understand much.
UPD: I know that Chicago Boss and other Erlang web-frameworks do exist, but I doubt that any of them have such a mature environment, vibrant community and huge variability of different plugins and libraries like for example Ruby on Rails, Django or any PHP-based MVC framework. Right?
UPD2: Maybe I have to elaborate on this deeper: I also need the front-end to be as maintainable as possible. Doing it in Erlang means that I might face problems finding the right developers to maintain it; doing it in RoR,Django, etc. means I can easily find work force to maintain the front-end and to grow it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,这里有一个 Erlang PostGreySQL 客户端:https://github.com/wg/epgsql< /a>。另一件事是,您可能想查看 ZOTONIC。它是一个用 Erlang 编写的 CMS,但它也是一个 Web 框架。它的特点之一是它很好地集成了 PostGreySQL 数据库,因此 Zotoniuc 背后的所有 Erlang 应用程序都将从中受益。在开发 MVC 或事件驱动的 Web 应用程序时它非常有用。
此外,您可能还想查看Nitrogen Web Framework 和 < b>Chicago Boss 这也是 Erlang Web 应用程序的 Web 框架。我亲自使用 Nitrogen、Yaws 和 Mnesia 开发了一套完整的 Erlang Web 应用程序。一个非常好的优点是,您可以在该技术堆栈后面拥有多个 Erlang 应用程序。 Yaws Web 服务器及其 Appmods 和 动态内容服务能力(因此RESTFUL 我可以向你保证),它增强了我们的 JavaScript 驱动前端Web 应用程序具有如此惊人的简单性和美观性,提供来自多个 Erlang 应用程序的服务。
如果您想拥有一个快速的 Web 前端,具有类似 Ajaxy/HTML5 的功能,那么快点,快点!并获取 Nitrogen Web 框架。由于您已经是一名 Erlang 程序员,所以这对您来说会很快。通过模板,您可以编写 HTML4.X / HTML5 模板,或使用网页制作/Studio 软件< /a> 为您创建模板。然后,稍后,您将向 Nitrogen 展示进入的位置,使用动态生成的 JQuery 由您的 Erlang 代码生成的代码。
您会发现文档非常简单。 Nitrogen 只是 Erlang 记录的集合,每个记录代表一个 HTML 标签。其他记录用于定义将 POST 回 Erlang 应用程序的效果和事件。在 Nitrogen 中开发漂亮的 Web 界面是如此之快。事实上,通过动态生成的 JQuery 代码,您可以将自己的 JavaScript 写入模板中伴随整个功能,比如使用另一个 JavaScript 库,例如 EXT JS,或MooTools 或 原型js。在模板中,您将指出 Nitrogen 应在何处呈现动态生成的 HTML 元素以及 JQuery,后者将“AJaxically”作用于这些元素。在这种情况下,模板仅意味着 HTML 页面。
请记住成为其邮件列表的成员以寻求更多帮助,并在 StackOverflow 上继续提出任何更多问题。欢迎来到 Erlang Web 开发的世界。您可能感兴趣的一些链接(
关于 Erlang Web 开发的 IEEE 论文,
Erlang Web 框架、
erlydtl - Erlang Django 类似模板实现,
ErlyWeb框架
)成功!
EDIT
Now, what you say is actually true. Finding Developers to Maintain it would be a task. However, Zotonic as i mentioned earlier is a full fledged (Web) CMS just as Joomla or Word Press e.t.c. With it you, yourself can actually manage/maintain the site/application.
However, you could also develope the Web front using Django, or Ruby on Rails but create Secure Services using JSON Formatted Data to Mochiweb from your Web front. Then, using Mochijson2.erl which comes with mochiweb, you parse the JSON and translate it into requests or methods and arguments in your Erlang Back-end. This would be done in both directions i.e. you make requests to your Erlang applications, get the returned results and render them as JSON data.
Mochiweb is the powerful tool that can interface any Erlang Back End with any Web technology at the front using Service/ RESTFul Model. Its simple and light weight. Its fast and all it needs is you to point it to which methods to handle POST, GET, PUT e.t.c HTTP requests and it would wait for the results for sending back. Mochiweb has been used in very many Erlang systems e.g. Couch DB (one of the most advanced NoSQL DBMS changing the way we understand the Web and SOA Systems) and all those other systems such as Membase Single Server, Big Couch / Cloudant, e.t.c. You could see someone putting mochiweb in action here, then here and lastly here.
Django, Twisted, PHP, or Ruby on Rails frameworks make JSON requests and expect JSON responses from Erlang Back ends powered by Mochiweb. Another great RESTful interface for Erlang Web Back-ends is Misultin, which even supports Web Sockets and is sometimes feared to be the fastest/ or most responsive Erlang HTTP library :)
In my experience, i have worked with PHP gurus, JavaScript gurus e.t.c. but we find development cheaper whenever we put our Web server as yaws with a Service Oriented Model using JSON requests and responses from both Directions. In this case we donot lose on Erlang's availability and fault tolerance and by the way, you can make many requests to as many distributed Erlang Servers even if they are hidden in different Sub nets of Domains by using JSONP which is supported by all JavaScript and/or Front-web frameworks. I strongly advise you to put Mochiweb or Misultin in-front of your erlang Backend and have which ever Web framework you choose to make requests using JSON Format (or even XML, which you would parse using erlsom , download it here). I hope you do get what am suggesting. Success!!!
First of all, there is an Erlang PostGreySQL Client here: https://github.com/wg/epgsql. Another thing is that you may want to check out ZOTONIC. Its a CMS written in Erlang but it is a Web framework as well. One of its features is that it has integrated PostGreySQL Database very well and so all Erlang applications behind Zotoniuc would benefit from this. It is very good when developing MVC or Event driven Web apps.
Also, you may want to check out Nitrogen Web Framework and Chicago Boss which are also web frameworks for Erlang Web apps. I have personally developed Erlang web apps using Nitrogen, Yaws and Mnesia as a complete set. One very nice advantage is that you can have several many Erlang Applications behind this technology stack. Yaws web Server with its Appmods and dynamic Content Serving ability (so RESTFUL i can assure you that), it has empowered our JavaScript Driven Frontend Web Apps with such amazing simplicity and beauty, providing Services from a bunch of several Erlang Applications.
If you want to have a fast Web Front End , with Ajaxy/HTML5 like features , then hurry, quick! and grab your self the Nitrogen Web Framework. Since you are an Erlang Programmer already, this will be so fast for you. With Templating, you can write HTML4.X / HTML5 Templates, or use a Web page Maker/Studio Software to create template(s) for you. Then later, you will show Nitrogen where to come in, binding your Erlang Backends to those nice Pages using Dynamically Generated JQuery Code arising from your Erlang Code.
You will find the documentation very simple. Nitrogen is just a collection of Erlang Records, with each record standing for an HTML Tag. Other records are used for defining effects and events that will be POST back into your Erlang Application. Developing Web beautiful interfaces in Nitrogen is so fast. Infact, with the dynamically generated JQuery code, you can write your own JavaScript into the Template to accompany the entire functionality say, making use of another JavaScript library like EXT JS, or MooTools or prototype js. Within the template is where you will point out where Nitrogen should render the dynamically generated HTML Elements as well as JQuery which will "AJaxically" act on these elements. A template in this case simply means an HTML Page.
Remember to become a member of its mailing list to find more assistance as well as keep asking any more questions here on StackOverflow. Welcome to the world of Erlang Web Development. Some several links you may be interested in (
IEEE Paper on Web Development in Erlang,
Erlang Web Framework,
erlydtl - Erlang Django like Templating Implementation,
ErlyWeb Framework
) Success !
EDIT
Now, what you say is actually true. Finding Developers to Maintain it would be a task. However, Zotonic as i mentioned earlier is a full fledged (Web) CMS just as Joomla or Word Press e.t.c. With it you, yourself can actually manage/maintain the site/application.
However, you could also develope the Web front using Django, or Ruby on Rails but create Secure Services using JSON Formatted Data to Mochiweb from your Web front. Then, using Mochijson2.erl which comes with mochiweb, you parse the JSON and translate it into requests or methods and arguments in your Erlang Back-end. This would be done in both directions i.e. you make requests to your Erlang applications, get the returned results and render them as JSON data.
Mochiweb is the powerful tool that can interface any Erlang Back End with any Web technology at the front using Service/ RESTFul Model. Its simple and light weight. Its fast and all it needs is you to point it to which methods to handle POST, GET, PUT e.t.c HTTP requests and it would wait for the results for sending back. Mochiweb has been used in very many Erlang systems e.g. Couch DB (one of the most advanced NoSQL DBMS changing the way we understand the Web and SOA Systems) and all those other systems such as Membase Single Server, Big Couch / Cloudant, e.t.c. You could see someone putting mochiweb in action here, then here and lastly here.
Django, Twisted, PHP, or Ruby on Rails frameworks make JSON requests and expect JSON responses from Erlang Back ends powered by Mochiweb. Another great RESTful interface for Erlang Web Back-ends is Misultin, which even supports Web Sockets and is sometimes feared to be the fastest/ or most responsive Erlang HTTP library :)
In my experience, i have worked with PHP gurus, JavaScript gurus e.t.c. but we find development cheaper whenever we put our Web server as yaws with a Service Oriented Model using JSON requests and responses from both Directions. In this case we donot lose on Erlang's availability and fault tolerance and by the way, you can make many requests to as many distributed Erlang Servers even if they are hidden in different Sub nets of Domains by using JSONP which is supported by all JavaScript and/or Front-web frameworks. I strongly advise you to put Mochiweb or Misultin in-front of your erlang Backend and have which ever Web framework you choose to make requests using JSON Format (or even XML, which you would parse using erlsom , download it here). I hope you do get what am suggesting. Success!!!
您也可以使用任何可用的 Web 框架 在 erlang 中实现前端。在单独的 erlang 节点中运行前端和后端,使用 erlang RPC 在它们之间进行通信。
You could implement your frontend in erlang as well using any available web framework. Run front-end and back-end in separate erlang nodes using erlang RPC for communication between them.