TemporalSdk.Node (temporal_sdk v0.2.11)

View Source

SDK node configuration and management module.

The SDK node is a top level SDK library supervisor process running on the Erlang node.

SDK node responsibilities:

  • configure and start SDK node-level statistics telemetry poller,
  • configure SDK node-level fixed window rate limiter time windows,
  • configure and attach SDK-wide telemetry events handlers,
  • configure SDK node-wide options, such as :scope_config,
  • configure, start and supervise workflow execution scope processes,
  • configure, start and supervise SDK cluster processes.

SDK Configuration

:node - property list or map with SDK node configuration options as described in the SDK Node Configuration section. Example:

Elixir

node: %{:scope_config => [{:cluster_1, 5}]}

Erlang

{node, #{scope_config => [{cluster_1, 5}]}}

:clusters - property list containing SDK cluster configurations. The proplist key is a cluster name :temporal_sdk_cluster.cluster_name/0, and the proplist value is a cluster configuration defined as a map or proplist. Refer to TemporalSdk.Cluster for details about SDK cluster configuration.

Example :temporal_sdk configuration with one SDK cluster :cluster_1 and workflow execution scope shard size set to 5:

Elixir

config :temporal_sdk,
  node: %{:scope_config => [{:cluster_1, 5}]},
  clusters: [
    cluster_1: [
      activities: [%{:task_queue => "default"}],
      workflows: [%{:task_queue => "default"}]
    ]
  ]

Erlang

{temporal_sdk, [
    {node, #{scope_config => [{cluster_1, 5}]}},
    {clusters, [
        {cluster_1, [
            {activities, [#{task_queue => "default"}]},
            {workflows, [#{task_queue => "default"}]}
            ]}
        ]}
]}

SDK Node Configuration

:enable_single_distributed_workflow_execution - enables single workflow execution per Erlang cluster, see SDK Architecture - Workflow Execution Scope for details. Setting can be overwritten for each SDK cluster individually by using the SDK cluster configuration option with the same name, see TemporalSdk.Cluster. Default: true.

:limiter_time_windows - SDK node-level fixed window rate limiter time windows configuration. Values specified here also serve as the time intervals at which telemetry events [:temporal_sdk, :task_counter, :node] are emitted. See :temporal_sdk_limiter for details. By default, the fixed window rate limiter time window is set to 60 seconds:

Elixir

[
  activity_direct: 60_000,
  activity_eager: 60_000,
  activity_regular: 60_000,
  activity_session: 60_000,
  nexus: 60_000,
  workflow: 60_000
]

Erlang

[
  {activity_direct, 60_000},
  {activity_eager, 60_000},
  {activity_regular, 60_000},
  {activity_session, 60_000},
  {nexus, 60_000},
  {workflow, 60_000}
]

:scope_config - SDK node workflow execution scope configuration defined as a property list. Proplist key is the :workflow_scope scope name set in the SDK cluster configuration and the proplist value is the given cluster scope shards count. If :workflow_scope option is not set in the cluster configuration, the scope name will be the same as the cluster name. See SDK Architecture - Workflow Execution Scope section for details. Setting must be consistent across all Erlang cluster SDK nodes. By default, the shards count is set to 10 for each SDK cluster. Example: [cluster_1: 20].

:telemetry_events_handlers - telemetry events handlers. See :temporal_sdk_telemetry.events_handlers/0 for details. By default, all SDK telemetry events with the :exception suffix are logged with the :error log level using the built-in telemetry event handler function :temporal_sdk_telemetry.handle_log/4:

[
    {
        fun() -> temporal_sdk_telemetry:events_by_suffix([exception]) end,
        fun temporal_sdk_telemetry:handle_log/4
    }
]

:telemetry_poll_interval - the time interval at which the SDK node telemetry poller polls for SDK node statistics and emits [:temporal_sdk, :node, :stats] telemetry event. Default poll time interval is 10 seconds.

Summary

Functions

Returns a list of mounted OS disks and partitions.

Retrieves the current OS statistics from the SDK OS rate limiter.

Retrieves the current concurrency statistics from the SDK node-level concurrency rate limiter.

Functions

os_disk_mounts()

@spec os_disk_mounts() :: [id :: charlist()]

Returns a list of mounted OS disks and partitions.

During SDK startup, :disksup.get_disk_data/0 is invoked once, and the list of disks or partitions id is cached with :persistent_term. This function returns a cached value, meaning it does not update when disks or partitions are mounted or unmounted at runtime. Function is internally used when initializing and validating OS rate limiter :disk settings for new task workers.

Requires :disksup.

Example:

Elixir

iex(1)> TemporalSdk.Node.os_disk_mounts()
[~c"/dev", ~c"/run", ~c"/", ~c"/dev/shm", ~c"/run/lock", ~c"/tmp",
 ~c"/boot/efi", ~c"/run/user/1001"]

Erlang

1> temporal_sdk_node:os_disk_mounts().
["/dev","/run","/","/dev/shm","/run/lock","/tmp",
 "/boot/efi","/run/user/1001"]

os_stats()

@spec os_stats() :: :temporal_sdk_limiter.stats()

Retrieves the current OS statistics from the SDK OS rate limiter.

Function returns OS rate limiter limitables statistics as a map(). See :temporal_sdk_limiter for details about OS limitables.

Example:

Elixir

iex(1)> TemporalSdk.Node.os_stats()
%{
  :mem => 84,
  :cpu1 => 156,
  :cpu5 => 202,
  :cpu15 => 197,
  {:disk, ~c"/"} => 21,
  {:disk, ~c"/boot/efi"} => 2,
  {:disk, ~c"/dev"} => 0,
  {:disk, ~c"/dev/shm"} => 1,
  {:disk, ~c"/run"} => 1,
  {:disk, ~c"/run/lock"} => 0,
  {:disk, ~c"/run/user/1001"} => 1,
  {:disk, ~c"/tmp"} => 56
}

Erlang

1> temporal_sdk_node:os_stats().
#{mem => 84,cpu1 => 187,cpu15 => 200,cpu5 => 215,
  {disk,"/"} => 21,
  {disk,"/boot/efi"} => 2,
  {disk,"/dev"} => 0,
  {disk,"/dev/shm"} => 1,
  {disk,"/run"} => 1,
  {disk,"/run/lock"} => 0,
  {disk,"/run/user/1001"} => 1,
  {disk,"/tmp"} => 56}

stats()

@spec stats() :: :temporal_sdk_limiter.stats()

Retrieves the current concurrency statistics from the SDK node-level concurrency rate limiter.

Function returns a :temporal_sdk_limiter.stats/0 map, where the map key is the :temporal_sdk_limiter.temporal_limitable/0 and the value is the number of currently running limitable task executions at the SDK node-level. The number of task executions at the SDK node-level corresponds to the sum of task executions across all SDK clusters. A limitable here refers to a Temporal task, such as a Temporal activity, nexus, or workflow task, that is capable of rate limiting the polling rate of Temporal tasks.

See also:

Example:

Elixir

iex(1)> TemporalSdk.Node.stats()
%{
  nexus: 0,
  workflow: 5,
  activity_regular: 10,
  activity_session: 0,
  activity_eager: 0,
  activity_direct: 0
}

Erlang

1> temporal_sdk_node:stats().
#{activity_direct => 0,activity_eager => 0,
  activity_regular => 10,activity_session => 0,nexus => 0,
  workflow => 5}