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

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

问题描述

我想为比萨饼店提供容错的软实时网络应用程序。它应该帮助比萨店接受来自客户的电话,将其作为订单(通过CRM网络客户端)进行订购,并帮助调度员为订单分配交付驱动程序。

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.

问题是我不知道如何使用全部的Erlang / OTP善良使应用程序非常响应和容错。

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.

这是我的问题:


  1. 应该复制哪些系统元素以提供容错,我该怎么做?我知道我可以将每个车辆的状态(坐标,分配的订单等)存储在复制的Mnesia数据库中。这是正确的方式吗?

  2. 哪些数据存储服务应该是常规的基于SQL的(例如,基于 boss_db ),应该在Mnesia上做出非常快的反应?使用常规SQL数据库可以将客户记录和历史记录存储在这样的容错和高响应性应用程序中吗?

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

  4. 我应该将持续车辆数据(id,容量等)存储在常规SQL数据库,并在Mnesia数据库中存储实时数据(坐标,分配的订单,中继线中的订单等),使应用程序更实时响应?

  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?


推荐答案

首先,这是一个很大的问题,但我会尝试将其打破。让我们先看事实。它是一个Web服务。这意味着我们有这些层: Web服务器中间件应用程序然后数据存储。在大多数高可用性应用程序中,数据存储层必须通过复制进行冗余,并通过分发进行加载。在大多数现实世界的应用中,您不需要在RAM中存储任何东西,除非应用程序实际上是实时的,例如多玩家游戏服务器电信交换机。所以,在这种情况下,您的应用程序真的不需要RAM存储(也许某种缓存这里和那里,正如我们将要看到的)。 >
现在,这种应用程序涉及到不同类型的数据,在任何时候都不能拥有相同形式的信息,因此使用RDMS将强制您以相同的方式排列所有内容。我的建议是学习使用任何面向文档的数据库,一个 NoSQL DB 键-value system ,因为它们被真正体现了真实世界的复杂性。有关任何类型的存储的更多信息,请参见此 pdf 。我建议您使用沙发基础服务器,您的数据将只是 JSON文档 schemaless ,可以随着应用程序的发展而发展。它具有分发和复制功能,只需要任何应用程序所需的方式。您可以在运行时添加服务器或删除服务器,而整个系统只会自动重新平衡。它还附带了用于缓存的 memcached ,所以对于您正在谈论的IN-Memory部分,缓存将为您做所有的事情。存储后,让我们来谈谈中间件。我想谈论网络服务器作为中间件的一部分。您将需要一个非常稳定的Web服务器,具体取决于负载,并且您希望使用Erlang,我建议 yaws web server ,并学习使用 RESTFUL服务 > appmods 。使用Proxies sunch as Nginx 一个Web服务器集群的前端可能有助于进行负载管理。至少有几种Web服务器负载平衡的方法。之后,您将需要一个OTP应用程序。一个OTP应用程序不必要有 gen_servers 。但是,正如您将学习的那样,您将发现真正需要并行化的位置或需要顺序代码的位置。然而,它担心你想要使用你还没有掌握的东西。请遵循此网页书,而此 Orielly书,以帮助您掌握关于Erlang的一切。您可以发现尝试 Chicago Boss Mochiweb Misultin Http服务器库。

在Erlang中我应该提到的另一件事是,您需要掌握数据结构和高效的方式来处理它们。数据结构选择不良可能会导致问题。测试和测试每一步的一切。尽可能使用记录,并检查每个阶段的内存消耗。只有很多话要说这个问题,但希望其他人也会发表他们的想法。

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天全站免登陆