简体   繁体   English

使用OTP / Erlang作为Web应用程序基于组件的体系结构的一部分

[英]Using OTP/Erlang as a part of the component-based architecture of a web application

I have an Erlang/OTP application which does some business logic. 我有一个做一些业务逻辑的Erlang / OTP应用程序。 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). 它是用Erlang编写的,主要是为了容错,因为我可以轻松地重新启动系统崩溃的组件之一(最重要的要求是正常运行时间)。 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". 让我们将此Erlang / OTP应用程序称为“后端”。

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). 此Erlang / OTP应用程序还将使用PostgreSQL服务器将结果存储在持久性存储中,并存储其计算所需的其他元信息(尚未实现)。

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. 接下来,我需要在此Erlang / OTP应用程序中添加一个前端-一个简单的基于Web的解决方案,可以为Web用户服务:接受他/她的计算请求,请后端进行计算,然后向用户提供后端的结果。

There is no scalability requirement, I think that the maximum number of users per day can be no more than 1000. 没有可扩展性要求,我认为每天的最大用户数量不能超过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). 因此,我现在的当前任务是为我的后端Erlang / OTP应用程序实现一个通用前端(这通常意味着我有一个典型的用例:访问该站点,注册,登录,使用该应用程序并获得结果)美观的网页,退出)。

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. 一方面,我知道代码重用可以节省很多时间:例如,使用Ruby on Rails,我可以免费获得用户身份验证,密码存储,ajax接口和许多其他功能。

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. 另一方面,我对设计包含Erlang / OTP + PostgreSQL数据库服务器后端和Web框架(RoR,Django等)作为前端的应用程序一无所知。

I lot of questions spring in my mind: Should Erlang/OTP and the web-framework use the same PostgreSQL database to share the result? 我想到了很多问题:Erlang / OTP和Web框架是否应该使用相同的PostgreSQL数据库共享结果? What is the best way to send a computation request from the web-framework to the Erlang/OTP application and get it back? 将计算请求从网络框架发送到Erlang / OTP应用程序并将其取回的最佳方法是什么? How do I supervise the PostgreSQL server - it is not covered by OTP's fault tolerance? 如何监督PostgreSQL服务器-OTP的容错能力未涵盖该服务器?

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). 一般来说,我有几个异构软件组件,我想从它们中构建一个工作系统(“主要”组件是Erlang / OTP应用程序)。


Where I should start with this task? 我应该从哪里开始这项任务? Can you give me any advice or a hint which resources to read? 您能给我任何建议或提示来阅读哪些资源吗?

PS I have tried to read this and followed the links, but did not understand much. PS我试图阅读和遵循的联系,但并没有多少了解。

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. UPD:我知道Chicago Boss和其他Erlang网络框架确实存在,但是我怀疑它们中的任何一个都具有如此成熟的环境,活跃的社区以及不同插件和库(例如Ruby on Rails,Django或任何PHP)的巨大可变性基于MVC的框架。 Right? 对?

UPD2: Maybe I have to elaborate on this deeper: I also need the front-end to be as maintainable as possible. UPD2:也许我必须更深入地阐述:我还需要前端尽可能地易于维护。 Doing it in Erlang means that I might face problems finding the right developers to maintain it; 在Erlang中进行操作意味着我可能会遇到寻找合适的开发人员进行维护的问题。 doing it in RoR,Django, etc. means I can easily find work force to maintain the front-end and to grow it. 在RoR,Django等中执行此操作意味着我可以轻松地找到工作人员来维护前端并进行扩展。

First of all, there is an Erlang PostGreySQL Client here: https://github.com/wg/epgsql . 首先,这里有一个Erlang PostGreySQL客户端: https : //github.com/wg/epgsql Another thing is that you may want to check out ZOTONIC . 另一件事是,您可能想检查ZOTONIC Its a CMS written in Erlang but it is a Web framework as well. 它是用Erlang编写的CMS,但它也是一个Web框架。 One of its features is that it has integrated PostGreySQL Database very well and so all Erlang applications behind Zotoniuc would benefit from this. 它的功能之一是它很好地集成了PostGreySQL数据库,因此Zotoniuc后面的所有Erlang应用程序都将从中受益。 It is very good when developing MVC or Event driven Web apps. 开发MVC或事件驱动的Web应用程序时,它非常好。

Also, you may want to check out Nitrogen Web Framework and Chicago Boss which are also web frameworks for Erlang Web apps. 另外,您可能想查看Nitrogen Web FrameworkChicago Boss ,它们也是Erlang Web应用程序的Web框架。 I have personally developed Erlang web apps using Nitrogen, Yaws and Mnesia as a complete set. 我个人使用Nitrogen,Yaws和Mnesia作为整套工具开发了Erlang Web应用程序。 One very nice advantage is that you can have several many Erlang Applications behind this technology stack. 一个非常不错的好处是,您可以在此技术堆栈后面拥有许多Erlang应用程序。 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. Yaws Web Server凭借其Appmod动态内容服务能力RESTFUL,我可以向您保证),以如此惊人的简单性和美感为我们的JavaScript驱动的前端Web应用程序提供了强大功能,并提供了多个Erlang应用程序提供的服务。

If you want to have a fast Web Front End , with Ajaxy/HTML5 like features , then hurry, quick! 如果您想拥有Ajaxy / HTML5之类的快速Web Front End,那就快点! and grab your self the Nitrogen Web Framework . 并掌握Nitrogen Web框架 Since you are an Erlang Programmer already, this will be so fast for you. 由于您已经是Erlang程序员,因此对您来说是如此之快。 With Templating, you can write HTML4.X / HTML5 Templates, or use a Web page Maker/Studio Software to create template(s) for you. 使用模板,您可以编写HTML4.X / HTML5模板,或使用网页Maker / Studio软件为您创建模板。 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. 然后,稍后,您将显示Nitrogen的输入位置,并使用由您的Erlang代码产生的动态生成的JQuery代码将您的Erlang后端绑定到这些漂亮的页面。

You will find the documentation very simple. 您会发现文档非常简单。 Nitrogen is just a collection of Erlang Records, with each record standing for an HTML Tag. 氮气只是Erlang记录的集合,每个记录代表一个HTML标签。 Other records are used for defining effects and events that will be POST back into your Erlang Application. 其他记录用于定义效果和事件,这些效果和事件将回发到您的Erlang应用程序中。 Developing Web beautiful interfaces in Nitrogen is so fast. 在氮气中开发漂亮的Web界面是如此之快。 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 . 实际上,通过动态生成的JQuery代码,您可以使用EXT JSMooToolsprototype js之类的其他JavaScript库将自己的JavaScript编写到Template中,以配合整个功能。 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. 在模板中,您将指出Nitrogen应该在哪里呈现动态生成的HTML元素以及将“ AJaxically”作用于这些元素的JQuery。 A template in this case simply means an HTML Page. 在这种情况下,模板仅表示HTML页面。


Remember to become a member of its mailing list to find more assistance as well as keep asking any more questions here on StackOverflow. 记住要成为其邮件列表的成员,以寻求更多帮助,并继续在StackOverflow上提问。 Welcome to the world of Erlang Web Development. 欢迎来到Erlang Web开发的世界。 Some several links you may be interested in ( 您可能对一些链接感兴趣(
IEEE Paper on Web Development in Erlang , IEEE关于Erlang网站开发的论文
Erlang Web Framework , Erlang Web框架
erlydtl - Erlang Django like Templating Implementation , erlydtl-Erlang Django之类的模板实现
ErlyWeb Framework ErlyWeb框架
) 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 etc With it you, yourself can actually manage/maintain the site/application. 但是,正如我前面提到的, Zotonic是成熟的(Web) CMS ,就像Joomla或Word Press等一样。有了它,您实际上可以管理/维护站点/应用程序。

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. 但是,您也可以使用Django或Ruby on Rails开发Web前端,但可以使用JSON格式的数据从Web前端将安全服务创建到Mochiweb 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. 然后,使用mochiweb随附的Mochijson2.erl ,解析JSON并将其转换为Erlang后端中的请求或方法和参数。 This would be done in both directions ie you make requests to your Erlang applications, get the returned results and render them as JSON data. 这将在两个方向上完成,即您向Erlang应用程序发出请求,获取返回的结果并将其呈现为JSON数据。

Mochiweb is the powerful tool that can interface any Erlang Back End with any Web technology at the front using Service/ RESTFul Model. Mochiweb是功能强大的工具,可以使用Service / RESTFul模型将任何Erlang后端与前端的任何Web技术连接起来。 Its simple and light weight. 它简单轻巧。 Its fast and all it needs is you to point it to which methods to handle POST, GET, PUT etc HTTP requests and it would wait for the results for sending back. 它的快速及其所需要的就是您将其指向处理POST,GET,PUT等HTTP请求的方法,并且它将等待结果发送回去。 Mochiweb has been used in very many Erlang systems eg 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 , etc You could see someone putting mochiweb in action here , then here and lastly here . Mochiweb已用于很多Erlang系统中,例如Couch DB (最先进的NoSQL DBMS之一,改变了我们对Web和SOA系统的理解方式)以及所有其他系统,例如Membase Single ServerBig Couch / Cloudant等。看到有人在这里然后在这里最后在这里使mochiweb发挥作用。

Django, Twisted, PHP, or Ruby on Rails frameworks make JSON requests and expect JSON responses from Erlang Back ends powered by Mochiweb. Django,Twisted,PHP或Ruby on Rails框架发出JSON请求,并期望来自Mochiweb支持的Erlang后端的JSON响应。 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 :) Misultin是Erlang Web后端的另一个很棒的RESTful接口,它甚至支持Web套接字,有时被认为是最快/响应最快的Erlang HTTP库:)

In my experience, i have worked with PHP gurus, JavaScript gurus etc 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. 根据我的经验,我曾经使用过PHP大师,JavaScript大师等,但是每当将Web服务器作为带有JSON以及来自两个方向的响应的面向服务模型的 Yaws时 ,我们发现开发成本都会降低。 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. 在这种情况下,我们不会失去Erlang的可用性和容错能力,而且,即使使用了所有JavaScript和/都支持的JSONP ,即使它们隐藏在域的不同子网中,您也可以向尽可能多的分布式Erlang服务器发出许多请求。或Front-web框架。 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 ). 我强烈建议您将Mochiweb或Misultin放在erlang后端的前面,并选择使用JSON格式(甚至XML,您可以使用erlsom进行解析,请在此处下载)进行请求的Web框架。 I hope you do get what am suggesting. 希望您能得到建议。 Success!!! 成功!!!

You could implement your frontend in erlang as well using any available web framework . 您也可以使用任何可用的Web框架在erlang中实现您的前端。 Run front-end and back-end in separate erlang nodes using erlang RPC for communication between them. 使用erlang RPC在单独的erlang节点中运行前端和后端,以在它们之间进行通信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM