简体   繁体   中英

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. 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?

PS 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: . : Another thing is that you may want to check out . 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 and which are also web frameworks for Erlang Web apps. ,它们也是Erlang Web应用程序的Web框架。 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 and (so 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. 我可以向您保证),以如此惊人的简单性和美感为我们的JavaScript驱动的前端Web应用程序提供了强大功能,并提供了多个Erlang应用程序提供的服务。

If you want to have a fast Web Front End , with Ajaxy/HTML5 like features , then hurry, quick! and grab your self the . 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 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 Code arising from your Erlang Code. 代码将您的Erlang后端绑定到这些漂亮的页面。

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 code, you can write your own JavaScript into the Template to accompany the entire functionality say, making use of another JavaScript library like , or or . 代码,您可以使用类的其他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. 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 (
,
,
,

) Success !




Now, what you say is actually true. Finding Developers to Maintain it would be a task. However, as i mentioned earlier is a full fledged (Web) just as Joomla or Word Press etc With it you, yourself can actually manage/maintain the site/application. 是成熟的(Web) ,就像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 from your Web front. Then, using which comes with mochiweb, you parse the JSON and translate it into requests or methods and arguments in your Erlang Back-end. ,解析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.

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 etc HTTP requests and it would wait for the results for sending back. Mochiweb has been used in very many Erlang systems eg (one of the most advanced NoSQL DBMS changing the way we understand the Web and SOA Systems) and all those other systems such as , , etc You could see someone putting mochiweb in action , and . (最先进的NoSQL DBMS之一,改变了我们对Web和SOA系统的理解方式)以及所有其他系统,例如等。看到有人在使mochiweb发挥作用。

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 , which even supports Web Sockets and is sometimes feared to be the fastest/ or most responsive Erlang HTTP library :) 是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 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 which is supported by all JavaScript and/or Front-web frameworks. ,即使它们隐藏在域的不同子网中,您也可以向尽可能多的分布式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 , download it ). 解析,请下载)进行请求的Web框架。 I hope you do get what am suggesting. Success!!!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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