简体   繁体   English

实时Web应用程序的体系结构

[英]Architecture of real-time web applications

This is going to be a rather theoretical question. 这将是一个相当理论上的问题。 I'm currently working on my bachelor thesis, which includes the creation of a web-based real-time object synchronization framework much like Firebase , but local (ie not cloud based). 我目前正在研究我的学士论文,其中包括创建一个基于Web的实时对象同步框架,就像Firebase一样,但是本地(即不是基于云的)。
I need to distinguish "regular" web applications (is there a better term?) from real-time, especially in terms of architecture. 我需要从实时中区分“常规”Web应用程序(有更好的术语吗?),尤其是在体系结构方面。 My thoughts so far: 到目前为止我的想法:

  • a regular web application is based on the Client-Server model, ie "Clients and servers exchange messages in a request-response messaging pattern: The client sends a request, and the server returns a response." 常规Web应用程序基于客户端 - 服务器模型,即“客户端和服务器以请求 - 响应消息传递模式交换消息:客户端发送请求,服务器返回响应”。
  • a real-time web application maintains a persistent connection between the client and the server. 实时Web应用程序维护客户端和服务器之间的持久连接。 Both can send and receive messages simultaneously and independently from each other over that connection (full-duplex). 两者都可以通过该连接同时并且彼此独立地发送和接收消息(全双工)。
  • my advisor (from the chair of applied software engineering) states the above point already qualifies the application for a Peer-to-Peer architecture, though he's not quite sure. 我的顾问(来自应用软件工程主席)表示,上述观点已经证明了对等体系结构的申请资格,尽管他不太确定。 I'm not yet convinced since a) the peers are not homogeneous, b) the server is still a centralized system, c) we still use the terms "server" and "client". 我还不确信,因为a)同行不是同质的,b)服务器仍然是一个集中系统,c)我们仍然使用术语“服务器”和“客户端”。
  • the server doesn't send messages directly to specific clients, but uses the publish-subscribe messaging pattern, ie a client connects to a message channel and receives a message when the server publishes it in the respective channel. 服务器不直接向特定客户端发送消息,而是使用发布 - 订阅消息传递模式,即客户端连接到消息通道,并在服务器在相应通道中发布消息时接收消息。 Hence the server doesn't actually know about its clients, though he could know. 因此服务器实际上并不知道它的客户端,尽管他可以知道。
  • the main use case is as follows: a client sends a message to the server (eg when a new todo item was created), the server processes it (eg writes the new todo item to the database) and finally dispatches the message to all other subscribed clients. 主要用例如下:客户端向服务器发送消息(例如,当创建新的待办事项项时),服务器处理它(例如将新的待办事项项目写入数据库)并最终将消息发送给所有其他用户订阅的客户。 The mediator pattern came to my mind, though it's a behavioral pattern, not an architectural one. 我想到了中介模式 ,虽然它是一种行为模式,而不是一种建筑模式。
  • but there's another use case: the server sends a message of its own accord (eg it recognizes the expiry date of a todo item exceeded and deletes it) to subscribed clients. 但还有另一个用例:服务器向订阅的客户端发送自己的消息(例如,它识别超出todo项目的到期日期并删除它)。 So the communication doesn't always have to start at the client. 因此,沟通并不总是必须从客户端开始。

Sorry, it got longer than intended. 对不起,它比预期的要长。 To put it in a nutshell, I see three possibilities for the architecture of a web-based real-time application: 简而言之,我看到了基于Web的实时应用程序架构的三种可能性:

  1. Peer-to-Peer (with heterogeneous peers) 点对点(具有异构对等体)
  2. Client-Server with pub-sub messaging pattern and mediator (if the latter matters for architecture) 具有pub-sub消息传递模式和中介的客户端服务器(如果后者对于体系结构很重要)
  3. you surprise me with something totally different ;-) 你用一些完全不同的东西让我感到惊讶;-)

Not sure if it's of importance at all, but I use Rails (with a JMS -based messaging service that provides WebSocket -support) on the backend and AngularJS on the frontend. 不确定它是否具有重要性,但我在后端使用Rails (带有基于JMS的消息传递服务,提供WebSocket -support),在前端使用AngularJS

"Real-time" actions or applications or systems have timeliness and predictability constraints. “实时”操作或应用程序或系统具有及时性和可预测性限制。

In principle, that is independent of the system architecture--in practice, the architecture must be suitable for the real-time properties you need. 原则上,这与系统架构无关 - 实际上,架构必须适合您需要的实时属性。

A publish/subscribe mechanism has a real-time metric based on the latency from when a publishable event occurs until the event is manifest at all operational subscribers--simplified, real-time = real fast (think automated financial trading). 发布/订阅机制具有基于从可发布事件发生到事件在所有运营订户中显现的延迟的实时度量 - 简化,实时=真实快速(想想自动化金融交易)。 But real-time is as much about timeliness predictability. 但实时性与时效性可预测性同样重要。 In the P/S case, the predictability of interest is the latency--both in magnitude and in variability ("jitter" is a special case). 在P / S案例中,感兴趣的可预测性是延迟 - 在幅度和可变性方面(“抖动”是一种特殊情况)。 There is a lot of literature in both the research and practitioner communities--in your case I suggest reading some of the excellent documents on RTI's web site (although IMHO RTI doesn't deal with predictability as thoroughly as they could, but they make good products). 在研究和从业者社区中有很多文献 - 在你的情况下,我建议阅读RTI网站上的一些优秀文件(尽管IMHO RTI并没有尽可能彻底地处理可预测性,但它们做得很好产品)。

Non-P/S systems, including but not limited to client/server ones, have a different style of real-time. 非P / S系统(包括但不限于客户端/服务器系统)具有不同的实时风格。 There are multiple time-constrained (say) tasks contending for shared resources (such as a processor, synchronizers, networks, etc.). 有许多争用共享资源的时间约束(比方说)任务(例如处理器,同步器,网络等)。 The contending access requests must be resolved by being either dispatched or scheduled in an order that satisfies both a timeliness and a predictability optimality criterion. 必须通过以满足及时性和可预测性最优性标准的顺序调度或调度来解决竞争访问请求。 Everyone is familiar with the very simple special case that the requests have deadlines and the optimality criterion is to meet all the deadlines. 每个人都熟悉一个非常简单的特殊情况,即请求有截止日期,最优标准是满足所有截止日期。 Note that the "meet deadlines" timeliness criterion has been expressed together with the predictability criterion "always meet all." 请注意,“符合期限”及时性标准已与可预测性标准“始终满足所有”一起表达。

In the vast majority of real world real-time cases (not limited to computers), the criteria are much more complex--for example, it is common for a real-time system to require that the mean (or, alternatively, maximum) tardiness either be minimized or not exceed some value. 在绝大多数现实世界的实时案例(不仅限于计算机)中,标准要复杂得多 - 例如,实时系统通常要求均值(或者,最大值)延迟要么最小化要么不超过某个值。 Additional complexity is added by dependencies, such as precedence constraints. 依赖性添加了额外的复杂性,例如优先约束。 This style of real-time has major implications on certain properties of the architecture and its system software. 这种实时方式对架构及其系统软件的某些属性有重大影响。 All of the above has been greatly simplified for brevity. 为简洁起见,上述所有内容都已大大简化。

I can read your question in one of the following ways: 我可以通过以下方式之一阅读您的问题:

a) Which of Peer-to-Peer, Client-Server, or some other term describes the application best? a)哪个Peer-to-Peer,Client-Server或其他术语最好地描述了该应用程序?

b) Which architecture should the application use as the basis of its design? b)应用程序应使用哪种架构作为其设计的基础?

In my opinion your question describes the application's architecture quite well, and it's quite irrelevant whether you want to call it Peer-to-Peer or Client-Server or something else. 在我看来,你的问题很好地描述了应用程序的体系结构,无论你是想将它称为Peer-to-Peer还是Client-Server或其他东西,这都是无关紧要的。

That said, the real-time aspects of the design don't make it Peer-to-Peer for the very reasons you mention. 也就是说,设计的实时方面并没有因为你提到的原因而成为Peer-to-Peer。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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