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

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

问题描述

我想为一家披萨外卖店构建一个容错的软实时 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.

这些目标并不罕见,但我想让该服务 24/7 可用,即使其具有容错性.此外,我想让它工作得非常快并且反应灵敏.

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. 我是否应该尝试将所有服务的所有数据(客户、车辆状态等)存储在 RAM 中,以使应用程序具有高响应性?
  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 ServerMiddle ware applicationData Storage.在大多数高可用应用程序中,数据存储层必须通过replication 实现冗余,并通过Distribution 进行负载管理.在大多数实际应用程序中,您不需要在 RAM 中存储任何内容,除非应用程序本质上是实时的,例如 多人游戏服务器电信交换机.因此,在这种情况下,您的应用程序类型实际上不需要 RAM 存储(可能在各处进行某种缓存,正如我们将要看到的.)

现在,这种应用程序,涉及不同类型的数据,信息在任何时候都不能具有相同的形式,因此,使用 RDMS 将迫使您以相同的方式安排一切.我的建议是,您可以学习使用任何面向文档的数据库NoSQL DB键值系统,因为它们已针对实际情况进行了很好的建模.世界的复杂性.在此 pdf 中可以找到有关任何类型存储的更多信息.我建议您使用 Couch 基础服务器,这样您的数据将只是 JSON 文档schemaless 并且可以随着您的应用程序的增长而发展.它带有分发和复制功能,就像任何应用程序都需要它一样.您可以在运行时添加服务器或删除服务器,整个系统只会保持重新平衡.它还带有内置用于缓存的 memcached,因此对于您正在谈论的 IN-Memory 部分,缓存将为您完成一切.

说完Storage,再来说说中间件.我想将 Web 服务器作为中间件的一部分来讨论.您将需要一个非常稳定的 Web 服务器,具体取决于负载,并且如果您想使用 Erlang,我建议使用 yaws Web 服务器 并学习如何使用 appmodsRESTFUL 服务/代码>.在 Web 服务器集群前使用作为 Nginx 的代理可能有助于负载管理.至少有几种方法可以在 Web 服务器前面进行负载平衡.在此之后,您将需要一个 OTP 应用程序.OTP 应用程序不必具有 gen_servers.但是随着您将学习,您将真正发现哪里需要并行化或哪里需要顺序代码.然而,它担心你想使用你还没有掌握的东西.请关注本网络书和本Oriely book 帮助你掌握关于 Erlang 的一切.您会发现尝试 Chicago BossMochiwebMisultin Http 服务器库很有用.

我应该做的另一件事提到在 Erlang 中执行此操作是,您需要掌握数据结构以及使用它们的有效方法.数据结构选择不当可能会导致问题.在每一步测试和测试一切.尽可能在任何地方使用 records 并检查每个阶段的内存消耗.关于这个问题有很多话要说,但希望其他人也能发表他们的想法.

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