配置 Reliable Actors - ReliableDictionaryActorStateProviderConfiguring Reliable Actors--ReliableDictionaryActorStateProvider

通过更改 Visual Studio 包根目录下的指定执行组件的 Config 文件夹中生成的 settings.xml 文件,可以修改 ReliableDictionaryActorStateProvider 的默认配置。You can modify the default configuration of ReliableDictionaryActorStateProvider by changing the settings.xml file generated in the Visual Studio package root under the Config folder for the specified actor.

Azure Service Fabric 运行时在 settings.xml 文件中查找预定义的节名称,并在创建基础运行时组件时使用这些配置值。The Azure Service Fabric runtime looks for predefined section names in the settings.xml file and consumes the configuration values while creating the underlying runtime components.

备注

删除或修改 Visual Studio 解决方案中生成的 settings.xml 文件中的以下配置的节名称。Do not delete or modify the section names of the following configurations in the settings.xml file that is generated in the Visual Studio solution.

也有一些全局设置会影响 ReliableDictionaryActorStateProvider 的配置。There are also global settings that affect the configuration of ReliableDictionaryActorStateProvider.

全局配置Global Configuration

全局配置在群集的群集清单中的 KtlLogger 节下面指定。The global configuration is specified in the cluster manifest for the cluster under the KtlLogger section. 它可配置共享日志位置和大小,以及记录器所使用的全局内存限制。It allows configuration of the shared log location and size plus the global memory limits used by the logger. 请注意,群集清单中的更改会影响使用 ReliableDictionaryActorStateProvider 的所有服务以及可靠有状态服务。Note that changes in the cluster manifest affect all services that use ReliableDictionaryActorStateProvider and reliable stateful services.

群集清单是单个 XML 文件,可保留适用于群集中所有节点和服务的设置与配置。The cluster manifest is a single XML file that holds settings and configurations that apply to all nodes and services in the cluster. 此文件通常称为 ClusterManifest.xml。The file is typically called ClusterManifest.xml. 可以使用 Get-ServiceFabricClusterManifest powershell 命令查看群集的群集清单。You can see the cluster manifest for your cluster using the Get-ServiceFabricClusterManifest powershell command.

配置名称Configuration names

名称Name 计价单位Unit 默认值Default value 备注Remarks
WriteBufferMemoryPoolMinimumInKBWriteBufferMemoryPoolMinimumInKB 千字节Kilobytes 83886088388608 以内核模式分配给记录器写入缓冲区内存池的最小 KB 数。Minimum number of KB to allocate in kernel mode for the logger write buffer memory pool. 此内存池用于在将状态信息写入磁盘之前缓存这些信息。This memory pool is used for caching state information before writing to disk.
WriteBufferMemoryPoolMaximumInKBWriteBufferMemoryPoolMaximumInKB 千字节Kilobytes 无限制No Limit 记录器写入缓冲区内存池可以增长到的大小上限。Maximum size to which the logger write buffer memory pool can grow.
SharedLogIdSharedLogId GUIDGUID """" 指定用来标识默认共享日志文件的唯一 GUID,该文件用于群集中所有节点上的所有 Reliable Services(不会在其服务特定配置中指定 SharedLogId)。Specifies a unique GUID to use for identifying the default shared log file used by all reliable services on all nodes in the cluster that do not specify the SharedLogId in their service specific configuration. 如果指定了 SharedLogId,还必须指定 SharedLogPath。If SharedLogId is specified, then SharedLogPath must also be specified.
SharedLogPathSharedLogPath 完全限定的路径名Fully qualified path name """" 指定完全限定的路径,该路径中的共享日志文件用于群集中所有节点上的所有 Reliable Services(不会在其服务特定配置中指定 SharedLogPath)。Specifies the fully qualified path where the shared log file used by all reliable services on all nodes in the cluster that do not specify the SharedLogPath in their service specific configuration. 但是如果指定了 SharedLogPath,还必须指定 SharedLogId。However, if SharedLogPath is specified, then SharedLogId must also be specified.
SharedLogSizeInMBSharedLogSizeInMB 兆字节Megabytes 81928192 指定以静态方式分配给共享日志的磁盘空间 MB 数。Specifies the number of MB of disk space to statically allocate for the shared log. 此值必须为 2048 或更大。The value must be 2048 or larger.

群集清单节示例Sample cluster manifest section

   <Section Name="KtlLogger">
     <Parameter Name="WriteBufferMemoryPoolMinimumInKB" Value="8192" />
     <Parameter Name="WriteBufferMemoryPoolMaximumInKB" Value="8192" />
     <Parameter Name="SharedLogId" Value="{7668BB54-FE9C-48ed-81AC-FF89E60ED2EF}"/>
     <Parameter Name="SharedLogPath" Value="f:\SharedLog.Log"/>
     <Parameter Name="SharedLogSizeInMB" Value="16383"/>
   </Section>

备注Remarks

记录器具有一个从未分页的内核内存分配的内存全局池,节点上的所有 Reliable Services 都可以使用该池在将状态数据写入与 Reliable Service 副本关联的专用日志之前缓存这些数据。The logger has a global pool of memory allocated from non paged kernel memory that is available to all reliable services on a node for caching state data before being written to the dedicated log associated with the reliable service replica. 池大小由 WriteBufferMemoryPoolMinimumInKB 和 WriteBufferMemoryPoolMaximumInKB 设置控制。The pool size is controlled by the WriteBufferMemoryPoolMinimumInKB and WriteBufferMemoryPoolMaximumInKB settings. WriteBufferMemoryPoolMinimumInKB 指定此内存池的初始大小,以及内存池可以缩小到的大小下限。WriteBufferMemoryPoolMinimumInKB specifies both the initial size of this memory pool and the lowest size to which the memory pool may shrink. WriteBufferMemoryPoolMaximumInKB 是内存池可以增长到的大小上限。WriteBufferMemoryPoolMaximumInKB is the highest size to which the memory pool may grow. 每个打开的 Reliable Service 副本都可能会增加内存池的大小,增加幅度从系统决定的数量到 WriteBufferMemoryPoolMaximumInKB。Each reliable service replica that is opened may increase the size of the memory pool by a system determined amount up to WriteBufferMemoryPoolMaximumInKB. 如果内存池的内存需求大于可用的内存,则会延迟内存请求,直到有可用的内存。If there is more demand for memory from the memory pool than is available, requests for memory will be delayed until memory is available. 因此,如果写入缓冲区内存池对特定配置而言太小,则性能可能会受到影响。Therefore if the write buffer memory pool is too small for a particular configuration then performance may suffer.

SharedLogId 和 SharedLogPath 设置始终一起使用,用于定义群集中所有节点的默认共享日志的 GUID 和位置。The SharedLogId and SharedLogPath settings are always used together to define the GUID and location for the default shared log for all nodes in the cluster. 默认共享日志可用于不在特定服务的 settings.xml 中指定设置的所有 Reliable Services。The default shared log is used for all reliable services that do not specify the settings in the settings.xml for the specific service. 为了获得最佳性能,共享日志文件应置于仅用于共享日志文件的磁盘上,以便减少争用。For best performance, shared log files should be placed on disks that are used solely for the shared log file to reduce contention.

SharedLogSizeInMB 指定要预先分配给所有节点上的默认共享日志的磁盘空间数量。SharedLogSizeInMB specifies the amount of disk space to preallocate for the default shared log on all nodes. 若要指定 SharedLogSizeInMB,不需要指定 SharedLogId 和 SharedLogPath。SharedLogId and SharedLogPath do not need to be specified in order for SharedLogSizeInMB to be specified.

复制器安全配置Replicator security configuration

复制器安全配置用于保护复制过程中使用的通信通道的安全。Replicator security configurations are used to secure the communication channel that is used during replication. 这意味着服务无法看到对方的复制流量,从而确保高度可用的数据也处于安全状态。This means that services cannot see each other's replication traffic, ensuring the data that is made highly available is also secure. 默认情况下,空的安全配置节会影响复制安全。By default, an empty security configuration section prevents replication security.

重要

在 Linux 节点上,证书必须是 PEM 格式。On Linux nodes, certificates must be PEM-formatted. 若要详细了解如何查找和配置适用于 Linux 的证书,请参阅在 Linux 上配置证书To learn more about locating and configuring certificates for Linux, see Configure certificates on Linux.

节名称Section name

<ActorName>ServiceReplicatorSecurityConfig<ActorName>ServiceReplicatorSecurityConfig

复制器配置Replicator configuration

复制器配置用于配置通过在本地复制和保持状态,负责使执行组件状态提供程序的状态高度可靠的复制器。Replicator configurations are used to configure the replicator that is responsible for making the Actor State Provider state highly reliable by replicating and persisting the state locally. 默认配置由 Visual Studio 模板生成,应可满足要求。The default configuration is generated by the Visual Studio template and should suffice. 本部分介绍了可用于调整复制器的其他配置。This section talks about additional configurations that are available to tune the replicator.

节名称Section name

<ActorName>ServiceReplicatorConfig<ActorName>ServiceReplicatorConfig

配置名称Configuration names

名称Name 计价单位Unit 默认值Default value 备注Remarks
BatchAcknowledgementIntervalBatchAcknowledgementInterval Seconds 0.0150.015 收到操作后,向主要复制器发回确认之前,辅助复制器等待的时间段。Time period for which the replicator at the secondary waits after receiving an operation before sending back an acknowledgement to the primary. 为在此间隔内处理的操作发送的任何其他确认都作为响应发送。Any other acknowledgements to be sent for operations processed within this interval are sent as one response.
ReplicatorEndpointReplicatorEndpoint 不适用N/A 无默认值--必选参数No default--required parameter 主要/辅助复制器用于与副本集中其他复制器通信的 IP 地址和端口。IP address and port that the primary/secondary replicator will use to communicate with other replicators in the replica set. 这应该引用服务清单中的 TCP 资源终结点。This should reference a TCP resource endpoint in the service manifest. 若要详细了解如何在服务清单中定义终结点资源,请参阅服务清单资源Refer to Service manifest resources to read more about defining endpoint resources in service manifest.
MaxReplicationMessageSizeMaxReplicationMessageSize 字节Bytes 50 MB50 MB 可以在单个消息中传输的复制数据的最大大小。Maximum size of replication data that can be transmitted in a single message.
MaxPrimaryReplicationQueueSizeMaxPrimaryReplicationQueueSize 操作的数量Number of operations 81928192 主要队列中的操作的最大数目。Maximum number of operations in the primary queue. 主复制器接收到来自所有辅助复制器的确认之后,释放一个操作。An operation is freed up after the primary replicator receives an acknowledgement from all the secondary replicators. 此值必须大于 64 和 2 的幂。This value must be greater than 64 and a power of 2.
MaxSecondaryReplicationQueueSizeMaxSecondaryReplicationQueueSize 操作的数量Number of operations 1638416384 辅助队列中的操作的最大数目。Maximum number of operations in the secondary queue. 会在使操作的状态在暂留期间高度可用后释放该操作。An operation is freed up after making its state highly available through persistence. 此值必须大于 64 和 2 的幂。This value must be greater than 64 and a power of 2.
CheckpointThresholdInMBCheckpointThresholdInMB MBMB 200200 创建状态检查点后的日志文件空间量。Amount of log file space after which the state is checkpointed.
MaxRecordSizeInKBMaxRecordSizeInKB KBKB 10241024 复制器可以在日志中写入的最大记录大小。Largest record size that the replicator may write in the log. 此值必须是 4 的倍数,且大于 16。This value must be a multiple of 4 and greater than 16.
OptimizeLogForLowerDiskUsageOptimizeLogForLowerDiskUsage 布尔Boolean true 为 true 时会配置日志,以便使用 NTFS 稀疏文件创建副本的专用日志文件。When true, the log is configured so that the replica's dedicated log file is created by using an NTFS sparse file. 这会降低文件的实际磁盘空间使用率。This lowers the actual disk space usage for the file. 为 false 时,会使用固定分配创建文件,这可提供最佳写入性能。When false, the file is created with fixed allocations, which provide the best write performance.
SharedLogIdSharedLogId GUIDguid """" 指定要用于标识与此副本一起使用的共享日志文件的唯一 guid。Specifies a unique guid to use for identifying the shared log file used with this replica. 通常情况下,服务不应使用此设置。Typically, services should not use this setting. 但是如果指定了 SharedLogId,还必须指定 SharedLogPath。However, if SharedLogId is specified, then SharedLogPath must also be specified.
SharedLogPathSharedLogPath 完全限定的路径名Fully qualified path name """" 指定要在其中创建此副本共享日志文件的完全限定路径。Specifies the fully qualified path where the shared log file for this replica will be created. 通常情况下,服务不应使用此设置。Typically, services should not use this setting. 但是如果指定了 SharedLogPath,还必须指定 SharedLogId。However, if SharedLogPath is specified, then SharedLogId must also be specified.

示例配置文件Sample configuration file

<?xml version="1.0" encoding="utf-8"?>
<Settings xmlns:xsd="https://www.w3.org/2001/XMLSchema" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2011/01/fabric">
   <Section Name="MyActorServiceReplicatorConfig">
      <Parameter Name="ReplicatorEndpoint" Value="MyActorServiceReplicatorEndpoint" />
      <Parameter Name="BatchAcknowledgementInterval" Value="0.05"/>
      <Parameter Name="CheckpointThresholdInMB" Value="180" />
   </Section>
   <Section Name="MyActorServiceReplicatorSecurityConfig">
      <Parameter Name="CredentialType" Value="X509" />
      <Parameter Name="FindType" Value="FindByThumbprint" />
      <Parameter Name="FindValue" Value="9d c9 06 b1 69 dc 4f af fd 16 97 ac 78 1e 80 67 90 74 9d 2f" />
      <Parameter Name="StoreLocation" Value="LocalMachine" />
      <Parameter Name="StoreName" Value="My" />
      <Parameter Name="ProtectionLevel" Value="EncryptAndSign" />
      <Parameter Name="AllowedCommonNames" Value="My-Test-SAN1-Alice,My-Test-SAN1-Bob" />
   </Section>
</Settings>

备注Remarks

BatchAcknowledgementInterval 参数用于控制复制延迟。The BatchAcknowledgementInterval parameter controls replication latency. “0”值导致可能的最低延迟,但代价是牺牲吞吐量(因为必须发送和处理更多确认消息,每个包含较少的确认)。A value of '0' results in the lowest possible latency, at the cost of throughput (as more acknowledgement messages must be sent and processed, each containing fewer acknowledgements). BatchAcknowledgementInterval 的值越大,整体复制吞吐量就越高,但代价是会造成更高的操作延迟。The larger the value for BatchAcknowledgementInterval, the higher the overall replication throughput, at the cost of higher operation latency. 这直接转换为事务提交的延迟。This directly translates to the latency of transaction commits.

CheckpointThresholdInMB 参数控制复制器可以用于将状态信息存储在副本的专用日志文件中的磁盘空间量。The CheckpointThresholdInMB parameter controls the amount of disk space that the replicator can use to store state information in the replica's dedicated log file. 将此值提高到大于默认值可以在将副本添加到集时缩短重新配置的时间。Increasing this to a higher value than the default could result in faster reconfiguration times when a new replica is added to the set. 这是因为日志中会提供更多的操作历史记录,从而发生部分状态传输。This is due to the partial state transfer that takes place due to the availability of more history of operations in the log. 在崩溃后,这可能会延长副本恢复时间。This can potentially increase the recovery time of a replica after a crash.

如果将 OptimizeForLowerDiskUsage 设置为 true,则会过度预配日志文件空间,以便活动副本可以将更多状态信息存储在其日志文件中,而非活动副本使用较少的磁盘空间。If you set OptimizeForLowerDiskUsage to true, log file space will be over-provisioned so that active replicas can store more state information in their log files, while inactive replicas will use less disk space. 这样可以在节点上托管多个副本。This makes it possible to host more replicas on a node. 如果将 OptimizeForLowerDiskUsage 设置为 false,状态信息会更快地写入日志文件。If you set OptimizeForLowerDiskUsage to false, the state information is written to the log files more quickly.

MaxRecordSizeInKB 设置用于定义可由复制器写入日志文件的记录的最大大小。The MaxRecordSizeInKB setting defines the maximum size of a record that can be written by the replicator into the log file. 大多数情况下,默认的 1024-KB 记录大小是最佳大小。In most cases, the default 1024-KB record size is optimal. 但是,如果服务使更大数据项成为状态信息的一部分,则可能需要增加此值。However, if the service is causing larger data items to be part of the state information, then this value might need to be increased. 使 MaxRecordSizeInKB 小于 1024 几乎没什么好处,因为较小记录仅使用较小记录所需的空间。There is little benefit in making MaxRecordSizeInKB smaller than 1024, as smaller records use only the space needed for the smaller record. 我们预期此值只在极少数情况下需要更改。We expect that this value would need to be changed only in rare cases.

SharedLogId 和 SharedLogPath 设置始终一起使用,使服务可以使用与节点的默认共享日志不同的共享日志。The SharedLogId and SharedLogPath settings are always used together to make a service use a separate shared log from the default shared log for the node. 为获得最佳效率,应让尽可能多的服务指定相同共享日志。For best efficiency, as many services as possible should specify the same shared log. 共享日志文件应置于仅用于共享日志文件的磁盘上,以便减少磁头运动争用。Shared log files should be placed on disks that are used solely for the shared log file, to reduce head movement contention. 我们预期这些值只在极少数情况下需要更改。We expect that these values would need to be changed only in rare cases.