/** * Configures how an Effect Cluster runner participates in sharding. * * `ShardingConfig` describes the runner address, shard group membership, shard * counts and weights, lock timing, entity mailbox and lifecycle limits, polling * intervals, health checks, and local serialization simulation. This module * includes the service, default values, programmatic and environment-based * layers, a `Config` description for loading values, and helpers for normalizing * assigned shard groups. * * @stability unstable * @since 4.0.0 */ import * as Config from "../Config.ts"; import * as Context from "../Context.ts"; import * as Duration from "../Duration.ts"; import * as Effect from "../Effect.ts"; import * as Layer from "../Layer.ts"; import * as Option from "../Option.ts"; import { RunnerAddress } from "./RunnerAddress.ts"; declare const ShardingConfig_base: Context.ServiceClass; /** * The listen address for the current runner. * * Defaults to the `runnerAddress`. */ readonly runnerListenAddress: Option.Option; /** * A number that determines how many shards this runner will be assigned * relative to other runners. * * Defaults to `1`. * * A value of `2` means that this runner should be assigned twice as many * shards as a runner with a weight of `1`. */ readonly runnerShardWeight: number; /** * The shard groups available across all runners. * * Defaults to `["default"]`. */ readonly availableShardGroups: ReadonlyArray; /** * The shard groups that are assigned to this runner. * * Defaults to `["default"]`. */ readonly assignedShardGroups: ReadonlyArray; /** * The number of shards to allocate per shard group. * * **Note**: this value should be consistent across all runners. */ readonly shardsPerGroup: number; /** * The maximum interval between shard lock refreshes. * * The runner may shorten this interval to one third of * `shardLockExpiration` to preserve enough time to stop entities safely if * lock storage becomes unavailable. */ readonly shardLockRefreshInterval: Duration.Input; /** * Shard lock expiration duration. * * A runner whose shard lock refreshes keep failing for this duration unregisters * itself until lock storage recovers, allowing peers to take over its shards. * * With PostgreSQL (14+) or MySQL advisory locks, this also bounds how long a * runner that stops refreshing, for example because its process is frozen, * keeps its shards: the server ends its idle lock session after this * duration, releasing the locks. On MySQL it is rounded up to whole * seconds. Vitess ignores the MySQL session timeout, so behind Vitess the * locks stay held until the runner's connection closes. */ readonly shardLockExpiration: Duration.Input; /** * Disable the use of advisory locks for shard locking. * * PGlite clients never use advisory locks. */ readonly shardLockDisableAdvisory: boolean; /** * Start shutting down as soon as an Entity has started shutting down. * * Defaults to `true`. */ readonly preemptiveShutdown: boolean; /** * The default capacity of the mailbox for entities. */ readonly entityMailboxCapacity: number | "unbounded"; /** * Report the mailbox size of each resident entity with the * `effect_cluster_entity_mailbox_size` gauge, unless overridden by the * `mailboxMetrics` entity option. * * Defaults to `false`. */ readonly entityMailboxMetrics: boolean; /** * The maximum number of entities that can be resident on this runner at the * same time. * * When the limit is reached, no new entities are spawned: the storage read * loop stops admitting messages for new entity addresses (they stay in * storage until a slot frees up), and volatile sends to new addresses fail * with `MailboxFull`. * * `"unbounded"` can only be set programmatically; the environment * configuration only accepts integers. * * Defaults to `10_000`. */ readonly maxResidentEntities: number | "unbounded"; /** * The maximum number of unprocessed messages read from storage in a single * poll. * * Defaults to `1024`. */ readonly unprocessedMessageBatchSize: number; /** * The maximum duration of inactivity (i.e. without receiving a message) * after which an entity will be interrupted. */ readonly entityMaxIdleTime: Duration.Input; /** * If an entity does not register itself within this time after a message is * sent to it, the message will be marked as failed. * * Defaults to 1 minute. */ readonly entityRegistrationTimeout: Duration.Input; /** * The maximum duration of time to wait for an entity to terminate. * * By default this is set to 15 seconds to stay within kubernetes defaults. */ readonly entityTerminationTimeout: Duration.Input; /** * The interval at which to poll for unprocessed messages from storage. */ readonly entityMessagePollInterval: Duration.Input; /** * The interval at which to poll for client replies from storage. */ readonly entityReplyPollInterval: Duration.Input; /** * The interval at which to poll for new runners and refresh shard * assignments. */ readonly refreshAssignmentsInterval: Duration.Input; /** * How long the healthy runners must stay unchanged before runners that * joined are added to shard assignments. A burst of joins, such as a * scale-up or a deployment with a large surge, is then published as one * assignment and each shard is handed off once instead of once per join. * In a rolling update that replaces one runner at a time, each departure is * still published immediately, so shards still move at every step. * * Only joins wait. The initial assignment, departures and unhealthy runners * are published immediately, together with any pending joins. A pending * runner that leaves has no shards to move, so it only restarts the quiet * period. * * While joins are pending, shards keep running where they are, the new * runners stay idle and no runner takes shards it does not already hold. * Runners publish on their own polls, so a shard released by one runner can * stay unlocked until its new owner publishes, usually within two * `refreshAssignmentsInterval`s. A runner that does not observe the joins, * for example because it cannot read membership, can still take shards from * its outdated assignment and hand them off again, as with `0`. * * Pending joins are published at most four times this duration after the * first one, even if runners keep joining. The quiet period is checked once * per `refreshAssignmentsInterval`, so the worst case delay is four times * this duration plus one interval, and values shorter than the interval * behave like a single quiet poll. * * Defaults to `0`, which publishes every change immediately. Leave it at * `0` for scale-ups driven by load, where idle new runners are costly. */ readonly runnerJoinDebounce: Duration.Input; /** * The interval to retry a send if EntityNotAssignedToRunner is returned. */ readonly sendRetryInterval: Duration.Input; /** * The interval at which runners are health checked. Unhealthy runners are * removed from shard assignments. * * The checks run on one runner, the host of the runner health singleton, so * they cannot detect a crash of that runner. It leaves shard assignments * only once runner storage stops listing it, which for `SqlRunnerStorage` * is when its last heartbeat is older than `shardLockExpiration`. Lowering * this interval detects crashes of other runners sooner, but not a crash of * the singleton's host. For that, lower `shardLockExpiration`, at the cost * of less tolerance for slow or unavailable lock storage. * * Defaults to 1 minute. */ readonly runnerHealthCheckInterval: Duration.Input; /** * Simulate serialization and deserialization to remote runners for local * entities. */ readonly simulateRemoteSerialization: boolean; }>; /** * Represents the configuration for the `Sharding` service on a given runner. * * @stability unstable * @category services * @since 4.0.0 */ export declare class ShardingConfig extends ShardingConfig_base { } /** * Default values for `ShardingConfig`, including the default local runner address, * shard group, shard count, mailbox settings, polling intervals, and remote * serialization simulation. * * @stability unstable * @category defaults * @since 4.0.0 */ export declare const defaults: ShardingConfig["Service"]; /** * Creates a `ShardingConfig` layer by merging the provided partial options over * `defaults`. * * **When to use** * * Use when you need to wire a cluster runner with explicit `ShardingConfig` * values, especially in tests, local development, or code paths where * configuration should be provided programmatically instead of loaded from * environment variables. * * **Details** * * The merge is shallow: omitted fields use `defaults`, and provided fields * replace the corresponding default value. * * **Gotchas** * * This layer only merges and provides configuration; it does not check that * cluster-wide settings are consistent across runners. Keep values such as * `shardsPerGroup` and `availableShardGroups` aligned for runners that should * share shard assignments. * * @see {@link defaults} for the values used when an option is omitted * @see {@link layerDefaults} for a layer with no overrides * @see {@link layerFromEnv} for loading configuration from environment variables before applying explicit overrides * * @stability unstable * @category layers * @since 4.0.0 */ export declare const layer: (options?: Partial) => Layer.Layer; /** * Layer that provides the default `ShardingConfig` values. * * @stability unstable * @category layers * @since 4.0.0 */ export declare const layerDefaults: Layer.Layer; /** * Describes how to load `ShardingConfig` values, applying the same * defaults used by the in-memory `defaults` object. * * @stability unstable * @category configuration * @since 4.0.0 */ export declare const config: Config.Config; /** * Effect that loads `ShardingConfig` from environment variables using the * constant-case config provider. * * @stability unstable * @category configuration * @since 4.0.0 */ export declare const configFromEnv: Effect.Effect<{ /** * The address for the current runner that other runners can use to * communicate with it. * * If `None`, the runner is not part of the cluster and will be in a client-only * mode. */ readonly runnerAddress: Option.Option; /** * The listen address for the current runner. * * Defaults to the `runnerAddress`. */ readonly runnerListenAddress: Option.Option; /** * A number that determines how many shards this runner will be assigned * relative to other runners. * * Defaults to `1`. * * A value of `2` means that this runner should be assigned twice as many * shards as a runner with a weight of `1`. */ readonly runnerShardWeight: number; /** * The shard groups available across all runners. * * Defaults to `["default"]`. */ readonly availableShardGroups: ReadonlyArray; /** * The shard groups that are assigned to this runner. * * Defaults to `["default"]`. */ readonly assignedShardGroups: ReadonlyArray; /** * The number of shards to allocate per shard group. * * **Note**: this value should be consistent across all runners. */ readonly shardsPerGroup: number; /** * The maximum interval between shard lock refreshes. * * The runner may shorten this interval to one third of * `shardLockExpiration` to preserve enough time to stop entities safely if * lock storage becomes unavailable. */ readonly shardLockRefreshInterval: Duration.Input; /** * Shard lock expiration duration. * * A runner whose shard lock refreshes keep failing for this duration unregisters * itself until lock storage recovers, allowing peers to take over its shards. * * With PostgreSQL (14+) or MySQL advisory locks, this also bounds how long a * runner that stops refreshing, for example because its process is frozen, * keeps its shards: the server ends its idle lock session after this * duration, releasing the locks. On MySQL it is rounded up to whole * seconds. Vitess ignores the MySQL session timeout, so behind Vitess the * locks stay held until the runner's connection closes. */ readonly shardLockExpiration: Duration.Input; /** * Disable the use of advisory locks for shard locking. * * PGlite clients never use advisory locks. */ readonly shardLockDisableAdvisory: boolean; /** * Start shutting down as soon as an Entity has started shutting down. * * Defaults to `true`. */ readonly preemptiveShutdown: boolean; /** * The default capacity of the mailbox for entities. */ readonly entityMailboxCapacity: number | "unbounded"; /** * Report the mailbox size of each resident entity with the * `effect_cluster_entity_mailbox_size` gauge, unless overridden by the * `mailboxMetrics` entity option. * * Defaults to `false`. */ readonly entityMailboxMetrics: boolean; /** * The maximum number of entities that can be resident on this runner at the * same time. * * When the limit is reached, no new entities are spawned: the storage read * loop stops admitting messages for new entity addresses (they stay in * storage until a slot frees up), and volatile sends to new addresses fail * with `MailboxFull`. * * `"unbounded"` can only be set programmatically; the environment * configuration only accepts integers. * * Defaults to `10_000`. */ readonly maxResidentEntities: number | "unbounded"; /** * The maximum number of unprocessed messages read from storage in a single * poll. * * Defaults to `1024`. */ readonly unprocessedMessageBatchSize: number; /** * The maximum duration of inactivity (i.e. without receiving a message) * after which an entity will be interrupted. */ readonly entityMaxIdleTime: Duration.Input; /** * If an entity does not register itself within this time after a message is * sent to it, the message will be marked as failed. * * Defaults to 1 minute. */ readonly entityRegistrationTimeout: Duration.Input; /** * The maximum duration of time to wait for an entity to terminate. * * By default this is set to 15 seconds to stay within kubernetes defaults. */ readonly entityTerminationTimeout: Duration.Input; /** * The interval at which to poll for unprocessed messages from storage. */ readonly entityMessagePollInterval: Duration.Input; /** * The interval at which to poll for client replies from storage. */ readonly entityReplyPollInterval: Duration.Input; /** * The interval at which to poll for new runners and refresh shard * assignments. */ readonly refreshAssignmentsInterval: Duration.Input; /** * How long the healthy runners must stay unchanged before runners that * joined are added to shard assignments. A burst of joins, such as a * scale-up or a deployment with a large surge, is then published as one * assignment and each shard is handed off once instead of once per join. * In a rolling update that replaces one runner at a time, each departure is * still published immediately, so shards still move at every step. * * Only joins wait. The initial assignment, departures and unhealthy runners * are published immediately, together with any pending joins. A pending * runner that leaves has no shards to move, so it only restarts the quiet * period. * * While joins are pending, shards keep running where they are, the new * runners stay idle and no runner takes shards it does not already hold. * Runners publish on their own polls, so a shard released by one runner can * stay unlocked until its new owner publishes, usually within two * `refreshAssignmentsInterval`s. A runner that does not observe the joins, * for example because it cannot read membership, can still take shards from * its outdated assignment and hand them off again, as with `0`. * * Pending joins are published at most four times this duration after the * first one, even if runners keep joining. The quiet period is checked once * per `refreshAssignmentsInterval`, so the worst case delay is four times * this duration plus one interval, and values shorter than the interval * behave like a single quiet poll. * * Defaults to `0`, which publishes every change immediately. Leave it at * `0` for scale-ups driven by load, where idle new runners are costly. */ readonly runnerJoinDebounce: Duration.Input; /** * The interval to retry a send if EntityNotAssignedToRunner is returned. */ readonly sendRetryInterval: Duration.Input; /** * The interval at which runners are health checked. Unhealthy runners are * removed from shard assignments. * * The checks run on one runner, the host of the runner health singleton, so * they cannot detect a crash of that runner. It leaves shard assignments * only once runner storage stops listing it, which for `SqlRunnerStorage` * is when its last heartbeat is older than `shardLockExpiration`. Lowering * this interval detects crashes of other runners sooner, but not a crash of * the singleton's host. For that, lower `shardLockExpiration`, at the cost * of less tolerance for slow or unavailable lock storage. * * Defaults to 1 minute. */ readonly runnerHealthCheckInterval: Duration.Input; /** * Simulate serialization and deserialization to remote runners for local * entities. */ readonly simulateRemoteSerialization: boolean; }, Config.ConfigError, never>; /** * Layer that loads `ShardingConfig` from environment variables and, when options * are provided, overlays those options on top of the loaded values. * * @stability unstable * @category layers * @since 4.0.0 */ export declare const layerFromEnv: (options?: Partial | undefined) => Layer.Layer; /** * Normalizes the provided `ShardingConfig` to calculate the `available` and * `assigned` shard groups. * * @stability unstable * @category converting * @since 4.0.0 */ export declare const shardGroupConfig: (config: ShardingConfig["Service"]) => { readonly available: ReadonlySet; readonly assigned: ReadonlySet; }; export {}; //# sourceMappingURL=ShardingConfig.d.ts.map