建筑使用Erlang / OTP容错软实时Web应用程序 [英] Building a fault-tolerant soft real-time web application with Erlang/OTP

查看:242
本文介绍了建筑使用Erlang / OTP容错软实时Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个比萨饼递铺容错软实时web应用程序。它应该帮助披萨店,接受客户的电话,把他们当成订单进入系统(通过CRM Web客户端),帮助调度员分配送货司机的订单。

这些目标是没有什么不寻常,但我想,以使服务提供全天候服务,即让它容错。此外,我想使它非常快的工作,是非常敏感。

下面是这样一个应用程序一个非常简单的结构图。

问题是,我不知道如何使用所有的二郎山/ OTP善良,使应用程序非常敏感和容错。

下面是我的问题:


  1. 哪个系统要素应以提供容错性,我应该怎么办被复制?我知道我可以每辆车的状态(坐标,分配订单等)存储在复制的Mnesia数据库。那是一个正确的方式去?

  2. 哪些数据存储服务应该是传统的基于SQL的(例如,基于 boss_db ),并应在Mnesia的做才能提供非常快的​​响应?它是确定使用传统的SQL数据库存储在这样一个容错和高敏感的应用的客户记录和历史记录?

  3. 我应该尝试在RAM中的所有服务(客户,车辆状态等)的所有数据存储,以使应用程序高度敏感?

  4. 我应该存储持久车辆数据以常规SQL数据库(ID,容量等)并存储(在后备箱等坐标,分配订单,订单)的实时数据中的Mnesia数据库,以使应用更多的实时响应?


解决方案

首先,这是一个大问题,但我会尝试打破它。在让事实先看看。它是一种Web服务。这意味着我们必须在这些层: Web服务器中间件应用程序然后数据存储。在大多数高度可用的应用程序,数据存储层必须通过复制有冗余,并通过分配负载管理。在大多数现实世界的应用,你会不会需要存储在RAM中任何东西,除非应用程序是真正的实时性的,如多玩家游戏服务器 A电信交换机。所以,你的一种应用,在这种情况下真的,无需RAM存储(也许某种缓存在这里和那里的,因为我们将要看到的。)
结果现在,这种应用,涉及到不同种类的数据,信息不能有相同的形式在任何时间,因此,使用关系数据库管理系统将迫使你安排好一切以同样的方式。我的建议是,你要学会使用任何面向文档的数据库,一个的NoSQL数据库键-value系统,因为它们是很好的模拟真实世界的复杂性。任何类型的存储的更多信息在这个 PDF 被找到。我建议你​​使用沙发基本服务器因此您的数据将仅仅是 JSON文件无模式和您的应用程序的增长可演变。它配备了分发和复制,只要任何应用程序曾经需要它的方式。您可以添加服务器或删除服务器,在运行时,整个系统只是不断再平衡本身。它还配备了 memcached的内置缓存,所以你在谈论,缓存会为你做的一切在内存中的一部分。搜索结果蓄水后,让我们来谈谈的中间件。我想谈论的Web服务器作为中间件的一部分。您将需要一个非常稳定的Web服务器,根据负载,并且是要使用二郎山,我建议雅司病web服务器,学会做 RESTful服务与它使用 appmods 。使用代理sunch为 Nginx的盈Web服务器的集群可能有助于负载管理。 ATLEAST有Web服务器的负载平衡盈的几种方法。在此之后,您将需要一个OTP应用。一个OTP应用亘古不变的必要要有 gen_servers 。但正如你将学习,你会发现,真的,你需要并行化或者需要连续code。然而它,担心你想用的东西,你还没有掌握。请按照<​​a href=\"http://learnyousomeerlang.com/content\" rel=\"nofollow\">本网站本书这的 Orielly书来帮助您掌握有关Erlang的一切。你会发现它很有用尝试芝加哥老大受Mochiweb Misultin HTTP服务器库。搜索结果的另一件事我应该提到关于二郎山这样做的是,你需要掌握你的数据结构,并与他们一起工作的方式effcient。数据结构的选择不当可能引起问题。试验的每一步测试一切。使用记录无处不如果可能的话,并在每个阶段检查内存消耗。只是有很多要说这个问题,但我希望,其他人也将会发表他们的想法。

I would like to build a fault-tolerant soft real-time web application for a pizza delivery shop. It should help the pizza shop to accept phone calls from customers, put them as orders into the system (via a CRM web client) and help the dispatchers to assign delivery drivers to the orders.

These goals are nothing unusual, but I would like to make the service available 24/7, i.e. to make it fault-tolerant. Moreover, I would like to make it work very fast and to be very responsive.

Below is a very simple architecture view for such an application.

The problem is that I do not know how to use all of the Erlang/OTP goodness to make the application very responsive and fault tolerant.

Here are my questions:

  1. Which system elements should be replicated in order to provide fault-tolerance and how should I do that? I know that I can store the status of each vehicle (coordinates, assigned orders, etc.) in a replicated Mnesia database. Is that a right way to go?
  2. Which data-storage services should be conventional SQL-based (e.g. based on boss_db) and which should be done on Mnesia to provide for very fast response? Is it ok to use a conventional SQL database to store customer records and history in a such fault-tolerant and highly-responsive application?
  3. Should I try to store all the data for all the services (customers, vehicles status, etc.) in RAM in order to make the application highly-responsive?
  4. Should I store the persistent vehicle data (id, capacity, etc.) in a conventional SQL database and store the real-time data (coordinates, assigned orders, orders in the trunk, etc.) in a Mnesia database to make the application more real-time responsive?

解决方案

First of all, this is a big question, but i will try to break it down. Lets first look at the facts. Its a web service. Which means we have these layers: Web Server , Middle ware application and then Data Storage. In most highly available applications, the Data Storage layer must have redundancy through replication and load managed through Distribution. In most real-world applications, you will not need to store anything in RAM, unless the application is really real-time in nature, such as a Multi-player Game Server or A telecom Switch. So, your kind of application, in this case really, no need for RAM storage (maybe some kind of caching here and there, as we are going to see.)

Now, this kind of application, involves different kind of data,information that cannot have the same form at any one time, hence, using an RDMS will force you to arrange everything the same way. My suggestion is that you learn to use any document oriented database, a NoSQL DB or key-value system because they are well modelled for real-world complexities. More information about any kind of storage is found in this pdf. I suggest that you use Couch base server whereby your data will simply be JSON documents, schemaless and can be evolved as your application grows. It comes with distribution and replication, just the way any application ever needed it. You can add servers or remove servers,at run-time and the entire system just keeps re-balancing itself. It also comes with memcached built in for caching, so for the IN-Memory part you were talking about, caching will do everything for you.

After the Storage, lets talk about the middle ware. i want to talk about the web server as being part of the middle ware. You will need a very stable Web server, depending on the load, and being that you want to use Erlang, i suggest yaws web server and learn to do RESTFUL services with it using appmods. Using Proxies sunch as Nginx infront of a cluster of web servers may help in load management. Atleast there are several ways of load-balancing infront of web servers. After this, you will need an OTP application. An OTP application doesnot necessary have to have gen_servers. But as you will learn, you will discover, really, where you need parallelisation or where you need sequential code. Its however, worrying that you want to use something which you have not yet mastered. please follow this web book and this Orielly book to help you master everything about Erlang. You could find it useful to try out Chicago Boss and Mochiweb or Misultin Http server libraries.

The other thing i should mention about doing this in Erlang is that, you need to master your Data Structures and an effcient way to work with them. Poor choice of data structures may cause problems. Test and Test everything at each step. Use records everywhere if possible and check memory consumption at each stage. There is just lots to say about this question , but hopefully, others are also going to post their thinking.

这篇关于建筑使用Erlang / OTP容错软实时Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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