简体   繁体   English

保持服务结构主体的状态

[英]Keeping State in Service Fabric Actors

I'm looking at starting to use Actors within Service Fabric but I wanted to just clarify a few things before getting started. 我正在考虑开始在Service Fabric中使用Actor,但是我想在开始之前先澄清一些事情。

I have a API that accepts a request from the user to process some data and returns an ID. 我有一个API,可以接受用户的请求以处理一些数据并返回ID。 Multiple requests from the users don't overlap in processing and are completely isolated so I feel that actors works well for this. 来自用户的多个请求在处理中不会重叠,并且完全隔离,因此我觉得参与者可以很好地做到这一点。

However what I want to understand is that would it be good practice to store the state locally within each actor that I create from each request and then when the api queries that data? 但是我想了解的是,将状态本地存储在我根据每个请求创建的每个参与者中,然后在api查询该数据时是一种好习惯吗?

I understand that the actors get deactivated when not "being used" ( https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-actors-lifecycle ) but still keep their state and are reactivated when a new call is made to the actor. 我了解,当不“使用”时,参与者会被停用( https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-actors-lifecycle ),但仍保持其状态和状态对演员的新呼叫时,将重新激活。 So in theory there wouldn't be any problem if each actor gets assigned the same ID that gets sent back to the user, then the user can come back and query the data even if the actor has been deactivated. 因此,从理论上讲,如果为每个参与者分配了与发送回用户相同的ID,那么即使参与者被停用,用户也可以返回并查询数据不会有任何问题。

Is this a good approach or should I just get the actors to do the work and offload the storage to another stateful service? 这是一个好方法吗?还是我应该让参与者来做工作并将存储分担给另一个有状态服务? Be good to get a list of pros/cons to this problem. 很好地获得此问题的利弊清单。

Mapping Actors to users could be a good approach, as long as your state is marked Persistent for the Actor the state is stored reliably (ie replicated to other nodes) even across Actor activations/deactivations. 将Actor映射到用户可能是一个很好的方法,只要您的状态被标记为对Actor Persistent ,状态就可以可靠地存储(即复制到其他节点),即使在Actor激活/停用之间也是如此。 An active Actor simply means that it is loaded into working memory of the ActorService . 活动的Actor只是意味着将其加载到ActorService工作内存中。 If an Actor is deactivated and is subsequently called it simply gets reactivated. 如果一个Actor被停用并随后被调用,则只需将其重新激活即可。 If you map ActorId to user id then the same identity could be stored within the Actor itself without a need for a secondary data storage (eg database). 如果将ActorId映射到用户ID,则可以在Actor自身中存储相同的身份,而无需辅助数据存储(例如数据库)。

What is characteristic for Actors is that they are single-threaded. Actor的特征是它们是单线程的。 This means that access to the Actor and the Actor's state is done in a sequential manner. 这意味着以顺序的方式访问Actor和Actor的状态。 If access to the Actor is primarily driven by the user's interactions with your API then that shouldn't be a problem. 如果对Actor的访问主要是由用户与您的API的交互驱动的,那么这应该不是问题。 If you on the other hand have multiple service that are accessing your Actor concurrently then this might become a bottleneck for you, in which case you may want to consider using a Reliable Stateful Service instead for the data/state. 另一方面,如果您有多个服务正在同时访问Actor,则这可能成为您的瓶颈,在这种情况下,您可能要考虑使用可靠的有状态服务代替数据/状态。

Persistent Actors 持久演员

  • Single-threaded access 单线程访问
  • Contained state 包含状态
  • Partitioned by ActorId 由ActorId划分

Actors without state and separate persistance 没有国家和单独坚持的行为者

  • Single-threaded access 单线程访问
  • Partitioned by ActorId 由ActorId划分
  • State/data access limited by persistance solution (SQL connection pool etc.) 状态/数据访问受持久性解决方案限制(SQL连接池等)

Stateful service 有状态的服务

  • Multi-threaded access 多线程访问
  • Partitioned by 'manually' assigned partition key 由“手动”分配的分区键进行分区
  • State reliably contained within partition 状态可靠地包含在分区中

Stateless service 无状态服务

  • Multi-threaded access 多线程访问
  • No partitioning, multiple instances 无分区,多个实例
  • State/data access limited by persistence solution (SQL connection pool etc.) 状态/数据访问受持久性解决方案限制(SQL连接池等)

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

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