Service Fabric 应用程序方案Service Fabric application scenarios

Azure Service Fabric 提供了一个可靠而灵活的平台,可用于编写和运行多种类型的商业应用程序和服务。Azure Service Fabric offers a reliable and flexible platform that enables you to write and run many types of business applications and services. 这些应用程序和微服务可以无状态也可以有状态,它们在各虚拟机间资源平衡,可最大限度提高工作效率。These applications and microservices can be stateless or stateful, and they are resource-balanced across virtual machines to maximize efficiency. Service Fabric 的独特体系结构使你可以在应用程序中执行近实时数据分析、内存中计算、并行事务和事件处理。The unique architecture of Service Fabric enables you to perform near real-time data analysis, in-memory computation, parallel transactions, and event processing in your applications. 可根据不断变化的资源要求轻松向上或向下缩放应用程序(其实是扩展或缩减)。You can easily scale your applications up or down (really in or out), depending on your changing resource requirements.

Azure 中的 Service Fabric 平台非常适合以下类别的应用程序:The Service Fabric platform in Azure is ideal for the following categories of applications:

  • 高度可用的服务:Service Fabric 服务通过创建多个辅助服务副本提供快速的故障转移。Highly available services: Service Fabric services provide fast failover by creating multiple secondary service replicas. 节点、进程或单个服务因硬件或其他故障而不可用时,其中一个次要副本会提升为主要副本,将服务的损失降到最低。If a node, process, or individual service goes down due to hardware or other failure, one of the secondary replicas is promoted to a primary replica with minimal loss of service.
  • 可缩放的服务:可对单独的服务进行分区,以允许在群集范围内扩大状态。Scalable services: Individual services can be partitioned, allowing for state to be scaled out across the cluster. 此外,还可动态创建和删除各项服务。In addition, individual services can be created and removed on the fly. 可根据资源需求简便快捷地扩大服务,从几个节点上的几个实例增加到多个节点上的数千个实例,然后再次缩小。Services can be quickly and easily scaled out from a few instances on a few nodes to thousands of instances on many nodes, and then scaled in again, depending on your resource needs. 可以使用 Service Fabric 生成这些服务并管理其整个生命周期。You can use Service Fabric to build these services and manage their complete lifecycles.
  • 非静态数据计算:使用 Service Fabric,可以生成数据、输入/输出,并计算密集型有状态应用程序。Computation on nonstatic data: Service Fabric enables you to build data, input/output, and compute intensive stateful applications. Service Fabric 允许在应用程序中共置处理(计算)和数据。Service Fabric allows the collocation of processing (computation) and data in applications. 当应用程序需要访问数据时,通常会存在与外部数据缓存或存储层关联的网络延迟。Normally, when your application requires access to data, there is network latency associated with an external data cache or storage tier. 使用 Service Fabric 有状态服务可消除这种延迟,从而提高读取和写入性能。With stateful Service Fabric services, that latency is eliminated, enabling more performant reads and writes. 例如,假设有应用程序为客户执行准实时建议选择,且要求往返时间小于 100 毫秒。Say for example that you have an application that performs near real-time recommendation selections for customers, with a round-trip time requirement of less than 100 milliseconds. 与必须从远程存储中提取所需数据的标准实现模型相比,Service Fabric 服务(其中的建议选择计算与数据和规则共置)的延迟和性能特征向用户提供一种响应体验。The latency and performance characteristics of Service Fabric services (where the computation of recommendation selection is collocated with the data and rules) provides a responsive experience to the user compared with the standard implementation model of having to fetch the necessary data from remote storage.
  • 基于会话的交互式应用程序:在应用程序(例如在线游戏或即时消息)需要低延迟读取和写入时,Service Fabric 非常有用。Session-based interactive applications: Service Fabric is useful if your applications, such as online gaming or instant messaging, require low latency reads and writes. 通过 Service Fabric,可生成这些交互式有状态应用程序,而无需创建无状态应用所需的单独存储或缓存。Service Fabric enables you to build these interactive, stateful applications without having to create a separate store or cache, as required for stateless apps. (这会增加延迟时间并可能产生一致性问题)。(This increases latency and potentially introduces consistency issues.).
  • 数据分析和工作流:Service Fabric 的快速读取和写入使必须可靠处理事件或数据流的应用程序成为可能。Data analytics and workflows: The fast reads and writes of Service Fabric enable applications that must reliably process events or streams of data. Service Fabric 还可让应用程序描述处理管道,其中的结果必须能够可靠地传递到下一个处理阶段而不会丢失。Service Fabric also enables applications that describe processing pipelines, where results must be reliable and passed on to the next processing stage without loss. 这包括交易和财务系统,其中的数据一致性和计算保证至关重要。These include transactional and financial systems, where data consistency and computation guarantees are essential.
  • 数据收集、处理和 IoT:由于 Service Fabric 处理大规模数据并通过其有状态服务实现低延迟,因此它非常适合于设备的数据和计算共存的数百万台设备上的数据处理。Data gathering, processing and IoT: Since Service Fabric handles large scale and has low latency through its stateful services, it is ideal for data processing on millions of devices where the data for the device and the computation are co-located. 我们已看到多个客户使用 Service Fabric(包括 BMWSchneider ElectricMesh Systems)构建 IoT 系统。We have seen several customers who have built IoT systems using Service Fabric including BMW, Schneider Electric and Mesh Systems.

应用程序设计案例研究Application design case studies

介绍如何使用 Service Fabric 设计应用程序的大量案例研究已发布在 Service Fabric 团队博客上。A number of case studies showing how Service Fabric is used to design applications are published on the Service Fabric team blog.

设计由无状态和有状态微服务组成的应用程序Design applications composed of stateless and stateful microservices

构建使用 Azure 云服务辅助角色的应用程序是无状态服务的一个示例。Building applications with Azure Cloud Service worker roles is an example of a stateless service. 相之之下,除请求及其响应以外,有状态微服务还维护其权威状态。In contrast, stateful microservices maintain their authoritative state beyond the request and its response. 在副本支持下提供交易保证的简单 API,从而提供状态的高可用性和一致性。This provides high availability and consistency of the state through simple APIs that provide transactional guarantees backed by replication. Service Fabric 的有状态服务使高可用性变得大众化,将其引入所有类型的应用程序,而不仅仅是数据库和其他数据存储。Service Fabric's stateful services democratize high availability, bringing it to all types of applications, not just databases and other data stores. 这是一种自然的进步。This is a natural progression. 为实现高可用性,应用程序已从使用单纯的关系数据库发展到 NoSQL 数据库。Applications have already moved from using purely relational databases for high availability to NoSQL databases. 现在,应用程序可在自身内部管理其“热”状态和数据,以便进一步提高性能,而无需损失可靠性、一致性或可用性。Now the applications themselves can have their "hot" state and data managed within them for additional performance gains without sacrificing reliability, consistency, or availability.

生成包含微服务的应用程序时,通常有一个无状态 Web 应用(ASP.NET 和 Node.js 等)组合调用应用于无状态和有状态业务中间层服务,这些服务使用 Service Fabric 部署命令全部部署到了同一 Service Fabric 群集中。When building applications consisting of microservices, you typically have a combination of stateless web apps (ASP.NET, Node.js, etc.) calling onto stateless and stateful business middle-tier services, all deployed into the same Service Fabric cluster using the Service Fabric deployment commands. 在规模、可靠性和资源使用情况方面,每种这些服务都是独立的,从而大大提高了开发和生命周期管理的灵活性。Each of these services is independent with regard to scale, reliability, and resource usage, greatly improving agility in development and lifecycle management.

有状态微服务可简化应用程序设计,因为它们不再需要传统上需要用来处理纯无状态应用程序的可用性和延迟需求的附加队列和缓存。Stateful microservices simplify application designs because they remove the need for the additional queues and caches that have traditionally been required to address the availability and latency requirements of purely stateless applications. 由于有状态服务原本就具有高可用性和低延迟,这意味着在应用程序中要作为一个整体进行管理的移动部件更少。Since stateful services are naturally highly available and low latency, this means that there are fewer moving parts to manage in your application as a whole. 下图说明了设计有状态应用程序与无状态应用程序之间的差异。The diagrams below illustrate the differences between designing an application that is stateless and one that is stateful. 通过利用 Reliable ServicesReliable Actors 编程模型,有状态服务降低了应用程序的复杂性,同时实现了高吞吐量和低延迟。By taking advantage of the Reliable Services and Reliable Actors programming models, stateful services reduce application complexity while achieving high throughput and low latency.

使用无状态服务生成的应用程序An application built using stateless services

使用无状态服务的应用程序

使用有状态服务生成的应用程序An application built using stateful services

使用无状态服务的应用程序

后续步骤Next steps