Actor runtime configuration parameters

Modify the default Dapr actor runtime configuration behavior

You can modify the default Dapr actor runtime behavior using the following configuration parameters.

ParameterDescriptionDefault
entitiesThe actor types supported by this host.N/A
actorIdleTimeoutThe timeout before deactivating an idle actor. Checks for timeouts occur every actorScanInterval interval.60 minutes
actorScanIntervalThe duration which specifies how often to scan for actors to deactivate idle actors. Actors that have been idle longer than actor_idle_timeout will be deactivated.30 seconds
drainOngoingCallTimeoutThe duration when in the process of draining rebalanced actors. This specifies the timeout for the current active actor method to finish. If there is no current actor method call, this is ignored.60 seconds
drainRebalancedActorsIf true, Dapr will wait for drainOngoingCallTimeout duration to allow a current actor call to complete before trying to deactivate an actor.true
reentrancy (ActorReentrancyConfig)Configure the reentrancy behavior for an actor. If not provided, reentrancy is disabled.disabled, false
remindersStoragePartitionsConfigure the number of partitions for actor’s reminders. If not provided, all reminders are saved as a single record in actor’s state store.0
entitiesConfigConfigure each actor type individually with an array of configurations. Any entity specified in the individual entity configurations must also be specified in the top level entities field.N/A

Examples

  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. }

See the .NET SDK documentation on registring actors.

  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);

See the documentation on writing actors with the JavaScript SDK.

  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. )

See the documentation on running actors with the Python SDK

  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);

See the documentation on writing actors with the Java SDK.

  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. }

See an example for using actors with the Go SDK.

Next steps

Enable actor reminder partitioning >>

Last modified October 12, 2023: Update config.toml (#3826) (0ffc2e7)