使用OTP / Erlang作为Web应用程序基于组件的架构的一部分 [英] Using OTP/Erlang as a part of the component-based architecture of a web application

查看:266
本文介绍了使用OTP / Erlang作为Web应用程序基于组件的架构的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Erlang / OTP应用程序,它有一些业务逻辑。它主要用于容错的Erlang,因为我可以轻松地重新启动系统崩溃的一个组件(高正常运行时间是最重要的要求)。
每个组件都进行某种特定的并行计算。



由于一个工作周期,应用程序会生成一个值列表。我们将这个Erlang / OTP应用程序称为后端。



此Erlang / OTP应用程序还将使用PostgreSQL服务器将结果存储在持久存储中,存储其计算所需的其他元信息(尚未实现)。



接下来,我需要向这个Erlang / OTP应用程序添加一个前端 - 一个简单的基于Web的解决方案,可以用于Web用户:接受计算请求从他/她,请求后端进行计算,给用户从后端返回结果。



没有可扩展性要求,我认为每天的最大用户数可以不超过1000个。



所以我目前的任务是为我的后端Erlang / OTP应用程序(通常意味着我有一个典型的用例:访问网站,注册,登录,使用应用程序,获得一个漂亮的ajax'y看网页,退出)的结果。



一方面,我知道代码重用可以节省很多时间:例如Ruby on Rails我可以获得用户身份验证,密码存储,ajax接口和很多其他东西免费。另一方面,我不知道如何设计包含Erlang / OTP + PostgreSQL数据库服务器后端和Web框架(RoR,Django)的应用程序等等)作为前端。



我的想法很多问题:Erlang / OTP和Web框架应该使用相同的PostgreSQL数据库来共享结果?将计算请求从Web框架发送到Erlang / OTP应用程序的最佳方式是什么?如何监督PostgreSQL服务器 - 它不受OTP的容错影响?一般来说,我有一些异构软件组件,我想从它们构建一个工作系统(主要组件是Erlang / OTP应用程序)。



/ p>




我应该从哪里开始这个任务?你能给我任何建议或提示哪些资源要阅读?



我试图阅读这个,并遵循链接,但不明白很多。



UPD:我知道芝加哥老板和其他Erlang网络框架确实存在,但我怀疑他们中有一个成熟的环境,充满活力的社区和不同插件和库的巨大变化,例如Ruby on Rails,Django或任何基于PHP的MVC框架。对?



UPD2:也许我必须深入阐述:我还需要前端尽可能的维护。在Erlang进行这种做法意味着我可能会遇到找到正确的开发人员维护它的问题;在RoR,Django等中进行操作,意味着我可以很容易地找到工作队伍来维护前端,并使其成长。

解决方案

p>首先,这里有一个Erlang PostGreySQL客户端: https://github.com/wg/ epgsql 的。另一件事是您可能想查看 ZOTONIC 。它是一个用Erlang编写的CMS,但它也是一个Web框架。其功能之一就是PostGreySQL数据库非常完善,所以Zotoniuc所有的Erlang应用程序都将受益匪浅。开发MVC或事件驱动的Web应用程序非常好。

此外,您可能需要查看 氮网络框架 和< b> 芝加哥老板 ,这也是Erlang Web应用程序的网络框架。我亲自开发了Erlang网络应用程序,使用Nitrogen,Yaws和Mnesia作为一套。一个非常好的优点是您可以在这个技术堆栈后面安装多个Erlang应用程序。 Yaws Web Server及其 Appmods 动态内容服务能力 (所以



如果你想拥有一个快速的Web前端,使用Ajaxy / HTML5类似功能,那么快点,快!并抓住自己的 氮网络框架 。既然你是一个Erlang程序员,这对你来说会很快。使用Templating,您可以编写HTML4.X / HTML5模板,或使用 网页制作工具/ Studio软件 为您创建模板。然后,您将显示氮气进入,将您的Erlang后端绑定到使用动态生成的好页面 JQuery 您的Erlang代码产生的代码。

您将发现文档非常简单。氮只是Erlang Records的一个集合,每个记录代表HTML Tag。其他记录用于定义将重新进入您的Erlang应用程序的效果和事件。在氮气中开发Web美观的界面非常快。实际上,通过动态生成 JQuery 代码,您可以将自己的JavaScript写入模板伴随整个功能说,利用另一个JavaScript库,如 EXT JS MooTools prototype js 。在模板中,您将在哪里指出氮应该呈现动态生成的HTML元素以及将AJAX作用于这些元素的JQuery。在这种情况下,一个模板只是一个HTML页面。




请记住,成为其邮件列表的成员,以寻求更多的帮助,并不断提出更多问题这里是StackOverflow。欢迎来到Erlang Web Development的世界。您可能感兴趣的几个链接(
IEEE Erlang Web开发论文
Erlang Web Framework
erlydtl - Erlang Django like模板化实施
ErlyWeb Framework
)成功!





编辑

现在,你说的是真的。寻找开发者来维护它将是一项任务。但是,如前所述, Zotonic 是一个完整的(Web)像Joomla或Word Press等一样 CMS 有了你,你自己可以管理/维护网站/应用程序。


但是,您还可以使用Django或Ruby on Rails开发Web前端,但使用JSON格式化数据创建安全服务 Mochiweb 。然后,使用 Mochijson2.erl 它与mochiweb一起,您解析JSON并将其转换为Erlang后端的请求或方法和参数。这将在两个方向完成,即您向Erlang应用程序发出请求,获取返回的结果并将其呈现为JSON数据。

Mochiweb是强大的工具,可以将任何Erlang后端与任何Web技术接口前端使用服务/ RESTFul模型。其简单轻便。它的快速和全部需要你指出哪些方法来处理POST,GET,PUT e.t.c HTTP请求,它会等待结果发回。 Mochiweb已被用于非常多的Erlang系统,例如 Couch DB (最先进的NoSQL DBMS之一改变了我们了解Web的方式和SOA系统)以及所有其他系统,例如 Membase Single Server Big Couch / Cloudant 等你可以看到有人把mochiweb付诸实施 here 然后在这里 最后在这里


Django,Twisted,PHP或Ruby on Rails框架使JSON请求并期待JSON响应来自Erlang后端由Mochiweb提供。 Erlang Web后端的另一个很棒的RESTful界面是 Misultin ,这甚至支持Web Sockets,有时可能是成为最快或最响应的Erlang HTTP库:)


根据我的经验,我曾经与PHP大师,JavaScript大师等一起工作但是当我们将Web服务器作为 yaws 使用面向服务的模型,使用来自两个方向的JSON请求和响应。在这种情况下,我们不会对Erlang的可用性和容错造成损失,通过使用 JSONP 。我强烈建议您将Mochiweb或Misultin放在您的erlang后端,并选择使用JSON格式(甚至XML,您将使用 erlsom ,下载 此处 )。我希望你能得到什么建议。成功!!!


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.

解决方案

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!!!

这篇关于使用OTP / Erlang作为Web应用程序基于组件的架构的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆