[英]Building a fault-tolerant soft real-time web application with Erlang/OTP
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.
它应该有助于披萨店接受来自客户的电话,将它们作为订单放入系统(通过CRM网络客户端),并帮助调度员将订单分配给送货司机。
These goals are nothing unusual, but I would like to make the service available 24/7, ie to make it fault-tolerant. 这些目标并不罕见,但我希望每周7天每天24小时提供服务,即使其具有容错能力。 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. 问题是我不知道如何使用所有Erlang / OTP优点来使应用程序具有响应性和容错性。
Here are my questions: 这是我的问题:
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.
它是一个Web服务。 Which means we have these layers:
Web Server
, Middle ware application
and then Data Storage
. 这意味着我们拥有这些层:
Web Server
, Middle ware application
,然后是Data Storage
。 In most highly available applications, the Data Storage layer must have redundancy through replication
and load managed through Distribution
. 在大多数高可用性应用程序中,数据存储层必须通过
replication
实现冗余,并通过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
. 在大多数实际应用程序中,除非应用程序实际上是实时的,否则您不需要在RAM中存储任何内容,例如
Multi-player Game Server
或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.) 所以,你的应用程序,在这种情况下真的,不需要RAM存储(也许在这里和那里进行某种
caching
,正如我们将要看到的那样。)
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. 现在,这种应用程序涉及不同类型的数据,任何时候都不能具有相同形式的信息,因此,使用RDMS将迫使您以相同的方式安排所有内容。 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. 我的建议是你学会使用任何
document oriented database
, NoSQL DB
或key-value system
因为它们很好地模拟了现实世界的复杂性。 More information about any kind of storage is found in this pdf . 有关任何类型存储的更多信息,请参阅此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. 我建议您使用Couch基本服务器 ,您的数据将只是
JSON documents
, schemaless
并且可以随着应用程序的增长而发展。 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. 它还内置了用于缓存的
memcached
,因此对于你所讨论的IN-Memory部分,缓存将为你做所有事情。
After the Storage, lets talk about the middle ware. 在存储之后,让我们谈谈中间件。 i want to talk about the web server as being part of the middle ware.
我想谈谈Web服务器作为中间件的一部分。 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
. 您将需要一个非常稳定的Web服务器,具体取决于负载,并且您想要使用Erlang,我建议使用
appmods
yaws web server并学习使用它来做RESTFUL服务 。 Using Proxies sunch as Nginx
infront of a cluster of web servers may help in load management. 使用Proxies sunch作为Web服务器集群前面的
Nginx
可能有助于负载管理。 Atleast there are several ways of load-balancing infront of web servers. 至少有几种方法可以对Web服务器进行负载均衡。 After this, you will need an OTP application.
在此之后,您将需要一个OTP应用程序。 An OTP application doesnot necessary have to have
gen_servers
. OTP应用程序不一定必须有
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.
请按照这本网页和这本Orielly书来帮助您掌握Erlang的所有内容。 You could find it useful to try out
Chicago Boss
and Mochiweb
or Misultin
Http server libraries. 你会发现尝试
Chicago Boss
和Mochiweb
或Misultin
Http服务器库很有用。
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. 关于在Erlang中执行此操作,我应该提到的另一件事是,您需要掌握数据结构以及使用它们的有效方法。 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. 尽可能在任何地方使用
records
并检查每个阶段的内存消耗。 There is just lots to say about this question , but hopefully, others are also going to post their thinking. 关于这个问题还有很多话要说,但希望其他人也会发表他们的想法。
hack this game: https://github.com/synrc/games all real-time, low latency, pub/sub, database, architecture questions are there, written as a state-of-the-art software. 破解这个游戏: https : //github.com/synrc/games所有实时,低延迟,发布/订阅,数据库,架构问题都在那里,作为最先进的软件编写。 I suggest to use gen_fsm to control states in your app as done in 'okay' supervisors.
我建议使用gen_fsm控制你的应用程序中的状态,就像'好'的主管一样。 riak is integrated with kvs lib, that has a good support for social updates also.
riak与kvs lib集成,对社交更新也有很好的支持。 n2o choosed cowboy server, in my view, the best server around.
n2o选择了牛仔服务器,在我看来,是最好的服务器。 http://www.ostinelli.net/a-comparison-between-misultin-mochiweb-cowboy-nodejs-and-tornadoweb/
http://www.ostinelli.net/a-comparison-between-misultin-mochiweb-cowboy-nodejs-and-tornadoweb/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.