Actor 运行时配置参数

修改默认的 Dapr actor 运行时配置行为

您可以使用以下配置参数修改默认的 Dapr actor 运行时行为。

参数说明默认值
108469主机支持的角色类型。N/A
actorIdleTimeout停用空闲 actor 前的超时。 每当经过 actorScanInterval 会进行一次超时检查。60分钟
actorScanInterval持续时间,指定多久扫描一次 Actors,以停用闲置的 Actors。 闲置时间超过 actor_idle_timeout 的 Actors 将被停用。30秒
drainOngoingCallTimeout重新平衡后的 Actors 重定位过程中的持续时间。 这将指定当前活动 actor 方法完成的超时时间。 如果没有当前 actor 方法调用,那么将忽略此时间。60秒
drainRebalancedActors如果为 true ,那么 Dapr 将等待 drainOngoingCallTimeout 以允许当前 actor 调用完成,然后再尝试停用 actor。true
reentrancy (ActorReentrancyConfig)配置 actor 的重入行为。 如果不提供,则禁用重入功能。disabled, false
remindersStoragePartitions配置 actor 提醒的分区数量。 如果未提供,则所有 reminder 将作为单个记录保存在 actor 的状态存储中。0
entitiesConfig通过配置阵列对每种 actor 类型进行单独配置。 在单个实体配置中指定的任何实体也必须在顶级 entities 字段中指定。N/A

示例

  1. // In Startup.cs
  2. public void ConfigureServices(IServiceCollection services)
  3. {
  4. // Register actor runtime with DI
  5. services.AddActors(options =>
  6. {
  7. // Register actor types and configure actor settings
  8. options.Actors.RegisterActor<MyActor>();
  9. // Configure default settings
  10. options.ActorIdleTimeout = TimeSpan.FromMinutes(60);
  11. options.ActorScanInterval = TimeSpan.FromSeconds(30);
  12. options.DrainOngoingCallTimeout = TimeSpan.FromSeconds(60);
  13. options.DrainRebalancedActors = true;
  14. options.RemindersStoragePartitions = 7;
  15. options.ReentrancyConfig = new() { Enabled = false };
  16. // Add a configuration for a specific actor type.
  17. // This actor type must have a matching value in the base level 'entities' field. If it does not, the configuration will be ignored.
  18. // If there is a matching entity, the values here will be used to overwrite any values specified in the root configuration.
  19. // In this example, `ReentrantActor` has reentrancy enabled; however, 'MyActor' will not have reentrancy enabled.
  20. options.Actors.RegisterActor<ReentrantActor>(typeOptions: new()
  21. {
  22. ReentrancyConfig = new()
  23. {
  24. Enabled = true,
  25. }
  26. });
  27. });
  28. // Register additional services for use with actors
  29. services.AddSingleton<BankService>();
  30. }

查看注册 Actors 的.NET SDK文档

  1. import { CommunicationProtocolEnum, DaprClient, DaprServer } from "@dapr/dapr";
  2. // Configure the actor runtime with the DaprClientOptions.
  3. const clientOptions = {
  4. actor: {
  5. actorIdleTimeout: "1h",
  6. actorScanInterval: "30s",
  7. drainOngoingCallTimeout: "1m",
  8. drainRebalancedActors: true,
  9. reentrancy: {
  10. enabled: true,
  11. maxStackDepth: 32,
  12. },
  13. remindersStoragePartitions: 0,
  14. },
  15. };
  16. // Use the options when creating DaprServer and DaprClient.
  17. // Note, DaprServer creates a DaprClient internally, which needs to be configured with clientOptions.
  18. const server = new DaprServer(serverHost, serverPort, daprHost, daprPort, clientOptions);
  19. const client = new DaprClient(daprHost, daprPort, CommunicationProtocolEnum.HTTP, clientOptions);

查看使用JavaScript SDK编写actors的文档

  1. from datetime import timedelta
  2. from dapr.actor.runtime.config import ActorRuntimeConfig, ActorReentrancyConfig
  3. ActorRuntime.set_actor_config(
  4. ActorRuntimeConfig(
  5. actor_idle_timeout=timedelta(hours=1),
  6. actor_scan_interval=timedelta(seconds=30),
  7. drain_ongoing_call_timeout=timedelta(minutes=1),
  8. drain_rebalanced_actors=True,
  9. reentrancy=ActorReentrancyConfig(enabled=False),
  10. remindersStoragePartitions=7
  11. )
  12. )

请参阅有关使用 Python SDK 运行 Actors 的文档

  1. // import io.dapr.actors.runtime.ActorRuntime;
  2. // import java.time.Duration;
  3. ActorRuntime.getInstance().getConfig().setActorIdleTimeout(Duration.ofMinutes(60));
  4. ActorRuntime.getInstance().getConfig().setActorScanInterval(Duration.ofSeconds(30));
  5. ActorRuntime.getInstance().getConfig().setDrainOngoingCallTimeout(Duration.ofSeconds(60));
  6. ActorRuntime.getInstance().getConfig().setDrainBalancedActors(true);
  7. ActorRuntime.getInstance().getConfig().setActorReentrancyConfig(false, null);
  8. ActorRuntime.getInstance().getConfig().setRemindersStoragePartitions(7);

请参阅有关使用Java SDK编写Actor的文档.

  1. const (
  2. defaultActorType = "basicType"
  3. reentrantActorType = "reentrantType"
  4. )
  5. type daprConfig struct {
  6. Entities []string `json:"entities,omitempty"`
  7. ActorIdleTimeout string `json:"actorIdleTimeout,omitempty"`
  8. ActorScanInterval string `json:"actorScanInterval,omitempty"`
  9. DrainOngoingCallTimeout string `json:"drainOngoingCallTimeout,omitempty"`
  10. DrainRebalancedActors bool `json:"drainRebalancedActors,omitempty"`
  11. Reentrancy config.ReentrancyConfig `json:"reentrancy,omitempty"`
  12. EntitiesConfig []config.EntityConfig `json:"entitiesConfig,omitempty"`
  13. }
  14. var daprConfigResponse = daprConfig{
  15. Entities: []string{defaultActorType, reentrantActorType},
  16. ActorIdleTimeout: actorIdleTimeout,
  17. ActorScanInterval: actorScanInterval,
  18. DrainOngoingCallTimeout: drainOngoingCallTimeout,
  19. DrainRebalancedActors: drainRebalancedActors,
  20. Reentrancy: config.ReentrancyConfig{Enabled: false},
  21. EntitiesConfig: []config.EntityConfig{
  22. {
  23. // Add a configuration for a specific actor type.
  24. // This actor type must have a matching value in the base level 'entities' field. If it does not, the configuration will be ignored.
  25. // If there is a matching entity, the values here will be used to overwrite any values specified in the root configuration.
  26. // In this example, `reentrantActorType` has reentrancy enabled; however, 'defaultActorType' will not have reentrancy enabled.
  27. Entities: []string{reentrantActorType},
  28. Reentrancy: config.ReentrancyConfig{
  29. Enabled: true,
  30. MaxStackDepth: &maxStackDepth,
  31. },
  32. },
  33. },
  34. }
  35. func configHandler(w http.ResponseWriter, r *http.Request) {
  36. w.Header().Set("Content-Type", "application/json")
  37. w.WriteHeader(http.StatusOK)
  38. json.NewEncoder(w).Encode(daprConfigResponse)
  39. }

查看使用 Go SDK 与 actors 的示例

下一步

启用actor提醒分区

相关链接