@zlink-systems/framework 0.29.1 → 0.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +150 -68
- package/dist/.tsbuildinfo +1 -1
- package/dist/contracts/Actors/ZLinkActorClient.d.ts +2 -1
- package/dist/contracts/Channels/Calls.d.ts +2 -1
- package/dist/contracts/Common/ZLinkMessageMetadata.js +11 -5
- package/dist/contracts/Configuration/Builders.d.ts +1 -2
- package/dist/contracts/Configuration/Configs.d.ts +0 -5
- package/dist/contracts/Configuration/RegistrationBuilders.js +6 -4
- package/dist/contracts/Configuration/RegistrationTypes.d.ts +1 -6
- package/dist/contracts/Configuration/RegistrationValidators.js +4 -4
- package/dist/contracts/Configuration/index.d.ts +1 -1
- package/dist/contracts/Handlers/Attributes.d.ts +5 -13
- package/dist/contracts/Handlers/Attributes.js +7 -11
- package/dist/contracts/Handlers/JsonContract.d.ts +2 -46
- package/dist/contracts/Handlers/JsonContract.js +4 -153
- package/dist/contracts/Spots/Contracts.d.ts +2 -1
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +3 -1
- package/dist/nest-integration.d.ts +1 -1
- package/dist/nest-integration.js +2 -1
- package/dist/runtime/actors/actor-client.d.ts +1 -1
- package/dist/runtime/actors/actor-client.js +14 -12
- package/dist/runtime/actors/actor-handoff.d.ts +3 -2
- package/dist/runtime/actors/actor-handoff.js +15 -7
- package/dist/runtime/actors/actor-join-relocation.d.ts +1 -0
- package/dist/runtime/actors/actor-local-native-join.js +9 -12
- package/dist/runtime/actors/actor-remote-wire.js +15 -0
- package/dist/runtime/actors/actor-routed-join-transport.d.ts +6 -2
- package/dist/runtime/actors/actor-routed-json-request.d.ts +2 -0
- package/dist/runtime/actors/index.d.ts +2 -1
- package/dist/runtime/actors/index.js +18 -6
- package/dist/runtime/actors/spot-actor-dispatch.js +2 -2
- package/dist/runtime/admission.d.ts +1 -1
- package/dist/runtime/admission.js +15 -5
- package/dist/runtime/application-jobs/application-ingress-record-owner.d.ts +9 -9
- package/dist/runtime/application-jobs/application-ingress-record-owner.js +45 -23
- package/dist/runtime/application-jobs/application-job-queue-scope.d.ts +5 -2
- package/dist/runtime/application-jobs/application-job-queue-scope.js +41 -21
- package/dist/runtime/application-jobs/contracts.d.ts +15 -2
- package/dist/runtime/backend/contracts/index.d.ts +27 -27
- package/dist/runtime/backend/mesh-completion-table.d.ts +15 -5
- package/dist/runtime/backend/mesh-completion-table.js +160 -50
- package/dist/runtime/backend/mesh-dispatch-pump.d.ts +3 -0
- package/dist/runtime/backend/mesh-dispatch-pump.js +53 -36
- package/dist/runtime/backend/node/node-backend-adapter-factory.js +6 -1
- package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +3 -3
- package/dist/runtime/backend/node/node-backend-adapter-support.js +33 -31
- package/dist/runtime/backend/node/node-dealer-channel-client-transport.d.ts +1 -1
- package/dist/runtime/backend/node/node-dealer-channel-client-transport.js +5 -2
- package/dist/runtime/backend/node/node-mesh-backend-adapter.d.ts +1 -9
- package/dist/runtime/backend/node/node-mesh-backend-adapter.js +1 -1
- package/dist/runtime/backend/node/node-raw-binding-port.js +50 -25
- package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +22 -16
- package/dist/runtime/backend/node/node-raw-mesh-backend.js +133 -149
- package/dist/runtime/backend/node/node-socket-backend-adapter.js +15 -10
- package/dist/runtime/backend/raw-binding-port.d.ts +10 -3
- package/dist/runtime/backend/runtime-message.d.ts +1 -0
- package/dist/runtime/backend/runtime-message.js +5 -0
- package/dist/runtime/backend/runtime-values.d.ts +1 -0
- package/dist/runtime/backend/runtime-values.js +2 -1
- package/dist/runtime/channels/channel-clients.d.ts +1 -0
- package/dist/runtime/channels/channel-clients.js +58 -21
- package/dist/runtime/channels/channel-dispatch-pipeline.d.ts +3 -2
- package/dist/runtime/channels/channel-dispatch-pipeline.js +20 -11
- package/dist/runtime/channels/channel-dispatch-services.d.ts +1 -0
- package/dist/runtime/channels/channel-dispatch-services.js +45 -0
- package/dist/runtime/channels/channel-dispatchers.d.ts +1 -1
- package/dist/runtime/channels/channel-dispatchers.js +27 -26
- package/dist/runtime/channels/channel-envelope-inspection.d.ts +1 -2
- package/dist/runtime/channels/channel-envelope-inspection.js +1 -16
- package/dist/runtime/channels/channel-envelope.d.ts +1 -0
- package/dist/runtime/channels/channel-envelope.js +83 -8
- package/dist/runtime/channels/channel-outbound-operations.d.ts +2 -2
- package/dist/runtime/channels/channel-outbound-operations.js +8 -8
- package/dist/runtime/channels/channel-receive-loops.js +3 -3
- package/dist/runtime/channels/channel-runtime-lifecycle.js +2 -1
- package/dist/runtime/channels/channel-runtime-manager.d.ts +6 -6
- package/dist/runtime/channels/channel-runtime-manager.js +12 -12
- package/dist/runtime/channels/channel-socket-registry.d.ts +10 -3
- package/dist/runtime/channels/channel-socket-registry.js +59 -82
- package/dist/runtime/channels/channel-transports.d.ts +18 -15
- package/dist/runtime/channels/channel-transports.js +48 -31
- package/dist/runtime/channels/local-spot-route-transport.d.ts +1 -1
- package/dist/runtime/channels/local-spot-route-transport.js +2 -1
- package/dist/runtime/channels/router-socket-spot-route-transport.d.ts +2 -2
- package/dist/runtime/channels/router-socket-spot-route-transport.js +4 -4
- package/dist/runtime/channels/source-spot-router.d.ts +2 -2
- package/dist/runtime/channels/source-spot-router.js +4 -4
- package/dist/runtime/channels/spot-node-route-transport.d.ts +2 -2
- package/dist/runtime/channels/spot-node-route-transport.js +4 -4
- package/dist/runtime/channels/spot-route-bridge-transport.d.ts +2 -2
- package/dist/runtime/channels/spot-route-bridge-transport.js +4 -4
- package/dist/runtime/channels/spot-route-dispatch-strategy.d.ts +5 -4
- package/dist/runtime/channels/spot-route-dispatch-strategy.js +18 -18
- package/dist/runtime/diagnostics/message-flow.d.ts +1 -0
- package/dist/runtime/diagnostics/message-flow.js +3 -3
- package/dist/runtime/execution/serial-execution-queue.d.ts +1 -0
- package/dist/runtime/execution/serial-execution-queue.js +1 -0
- package/dist/runtime/foundation/actor-join-recovery-codec.js +2 -2
- package/dist/runtime/foundation/durable-service-request.d.ts +14 -0
- package/dist/runtime/foundation/durable-service-request.js +98 -0
- package/dist/runtime/foundation/operation-identity.d.ts +1 -0
- package/dist/runtime/foundation/operation-identity.js +5 -1
- package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +37 -6
- package/dist/runtime/foundation/raw-service-mesh-runtime.js +473 -220
- package/dist/runtime/foundation/service-liveness-registry.d.ts +20 -8
- package/dist/runtime/foundation/service-liveness-registry.js +57 -44
- package/dist/runtime/foundation/service-mailbox.d.ts +3 -0
- package/dist/runtime/foundation/service-mailbox.js +2 -1
- package/dist/runtime/foundation/service-relocation-object-owner.d.ts +1 -0
- package/dist/runtime/foundation/service-relocation-object-owner.js +1 -0
- package/dist/runtime/foundation/service-relocation-runtime.d.ts +2 -0
- package/dist/runtime/foundation/service-relocation-runtime.js +13 -1
- package/dist/runtime/foundation/service-runtime-contracts.d.ts +2 -0
- package/dist/runtime/foundation/service-stateful-runtime.d.ts +10 -9
- package/dist/runtime/foundation/service-stateful-runtime.js +78 -126
- package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +5 -7
- package/dist/runtime/foundation/service-stateful-wire-codec.js +43 -61
- package/dist/runtime/foundation/service-topology-registry.d.ts +16 -4
- package/dist/runtime/foundation/service-topology-registry.js +69 -30
- package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +3 -3
- package/dist/runtime/foundation/service-wire-m6a-codec.js +36 -38
- package/dist/runtime/handlers/handler-instance-scope.d.ts +8 -0
- package/dist/runtime/handlers/handler-instance-scope.js +54 -11
- package/dist/runtime/host/actor-packet-relay.js +7 -7
- package/dist/runtime/host/actor-runtime-options-factory.js +2 -2
- package/dist/runtime/host/application-job-queue.d.ts +28 -9
- package/dist/runtime/host/application-job-queue.js +214 -50
- package/dist/runtime/host/entry-actor-runtime.d.ts +1 -0
- package/dist/runtime/host/entry-actor-runtime.js +4 -1
- package/dist/runtime/host/index.d.ts +7 -1
- package/dist/runtime/host/index.js +154 -126
- package/dist/runtime/host/instance-activation-authority.d.ts +2 -1
- package/dist/runtime/host/instance-activation-authority.js +89 -25
- package/dist/runtime/host/remote-bound-session-relay.js +2 -18
- package/dist/runtime/host/route-mesh-runtime.js +1 -1
- package/dist/runtime/host/service-relocation-control.d.ts +1 -0
- package/dist/runtime/host/service-relocation-control.js +10 -4
- package/dist/runtime/host/service-relocation-host-runtime.d.ts +6 -8
- package/dist/runtime/host/service-relocation-host-runtime.js +215 -243
- package/dist/runtime/host/spot-address-transport.d.ts +1 -0
- package/dist/runtime/host/spot-address-transport.js +28 -14
- package/dist/runtime/host/spot-runtime-options-factory.js +3 -2
- package/dist/runtime/host/user-spot-creation-coordinator.d.ts +1 -0
- package/dist/runtime/host/user-spot-creation-coordinator.js +1 -0
- package/dist/runtime/locations/actor-location-claims.d.ts +2 -2
- package/dist/runtime/locations/actor-location-claims.js +34 -19
- package/dist/runtime/locations/domain-store-contract.d.ts +2 -2
- package/dist/runtime/locations/in-memory-authority-store.d.ts +4 -2
- package/dist/runtime/locations/in-memory-authority-store.js +80 -8
- package/dist/runtime/locations/in-memory-location-store.d.ts +2 -2
- package/dist/runtime/locations/in-memory-location-store.js +19 -3
- package/dist/runtime/locations/internal-location-contracts.d.ts +3 -0
- package/dist/runtime/locations/lifecycle.d.ts +1 -2
- package/dist/runtime/locations/lifecycle.js +2 -5
- package/dist/runtime/locations/location-store-repository.d.ts +3 -2
- package/dist/runtime/locations/location-store-repository.js +165 -22
- package/dist/runtime/locations/resolvers.d.ts +2 -1
- package/dist/runtime/locations/resolvers.js +10 -1
- package/dist/runtime/locations/runtime.d.ts +1 -1
- package/dist/runtime/locations/runtime.js +24 -23
- package/dist/runtime/messaging/framework-json-v1.d.ts +4 -6
- package/dist/runtime/messaging/framework-json-v1.js +38 -294
- package/dist/runtime/messaging/packet-name.d.ts +1 -1
- package/dist/runtime/messaging/packet-name.js +8 -24
- package/dist/runtime/messaging/request-result.d.ts +2 -0
- package/dist/runtime/messaging/request-result.js +54 -0
- package/dist/runtime/messaging/submission-result.d.ts +2 -1
- package/dist/runtime/messaging/submission-result.js +7 -4
- package/dist/runtime/protocol/service_wire_codec.generated.d.ts +15 -0
- package/dist/runtime/protocol/service_wire_codec.generated.js +144 -0
- package/dist/runtime/protocol/service_wire_pilot_codec.generated.d.ts +9 -0
- package/dist/runtime/protocol/service_wire_pilot_codec.generated.js +14 -1
- package/dist/runtime/spots/formal-remote-actor-admission-registry.d.ts +9 -2
- package/dist/runtime/spots/formal-remote-actor-admission-registry.js +33 -19
- package/dist/runtime/spots/index.d.ts +7 -3
- package/dist/runtime/spots/index.js +23 -16
- package/dist/runtime/spots/spot-activation.d.ts +3 -1
- package/dist/runtime/spots/spot-activation.js +21 -12
- package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +2 -1
- package/dist/runtime/spots/spot-actor-admission-coordinator.js +11 -10
- package/dist/runtime/spots/spot-actor-packet-dispatch.d.ts +4 -1
- package/dist/runtime/spots/spot-actor-packet-dispatch.js +7 -5
- package/dist/runtime/spots/spot-actor-packet-drain.js +2 -0
- package/dist/runtime/spots/spot-actor-packet-relay-dispatch.js +1 -0
- package/dist/runtime/spots/spot-entry-activation.js +9 -3
- package/dist/runtime/spots/spot-handler-registry.d.ts +3 -1
- package/dist/runtime/spots/spot-handler-registry.js +18 -8
- package/dist/runtime/spots/spot-node-autoconnect.js +4 -3
- package/dist/runtime/spots/spot-node-runtime-manager.d.ts +2 -1
- package/dist/runtime/spots/spot-node-runtime-manager.js +4 -11
- package/dist/runtime/spots/spot-outbound.d.ts +3 -0
- package/dist/runtime/spots/spot-outbound.js +24 -15
- package/dist/runtime/spots/spot-routed-spot-packet-dispatch.d.ts +1 -0
- package/dist/runtime/spots/spot-routed-spot-packet-dispatch.js +1 -1
- package/dist/runtime/spots/spot-routing-internal.d.ts +6 -0
- package/dist/runtime/spots/spot-runtime-ports.d.ts +3 -1
- package/dist/runtime/spots/spot-subscription-dispatch.js +0 -3
- package/dist/runtime/spots/spot-timer.js +1 -0
- package/dist/runtime/streams/stream-session-runtime.d.ts +1 -1
- package/dist/runtime/streams/stream-session-runtime.js +14 -28
- package/package.json +3 -3
- package/src/contracts/Actors/ZLinkActorClient.ts +2 -1
- package/src/contracts/Channels/Calls.ts +2 -1
- package/src/contracts/Common/ZLinkMessageMetadata.ts +13 -8
- package/src/contracts/Configuration/Builders.ts +1 -2
- package/src/contracts/Configuration/Configs.ts +0 -6
- package/src/contracts/Configuration/RegistrationBuilders.ts +8 -12
- package/src/contracts/Configuration/RegistrationTypes.ts +1 -6
- package/src/contracts/Configuration/RegistrationValidators.ts +9 -10
- package/src/contracts/Configuration/index.ts +1 -6
- package/src/contracts/Handlers/Attributes.ts +14 -21
- package/src/contracts/Handlers/JsonContract.ts +8 -216
- package/src/contracts/Spots/Contracts.ts +2 -1
- package/src/internal.ts +1 -0
- package/src/nest-integration.ts +1 -0
- package/src/runtime/actors/actor-client.ts +40 -16
- package/src/runtime/actors/actor-handoff.ts +22 -8
- package/src/runtime/actors/actor-join-relocation.ts +1 -0
- package/src/runtime/actors/actor-local-native-join.ts +17 -26
- package/src/runtime/actors/actor-remote-wire.ts +17 -0
- package/src/runtime/actors/actor-routed-join-transport.ts +14 -4
- package/src/runtime/actors/actor-routed-json-request.ts +10 -2
- package/src/runtime/actors/index.ts +19 -5
- package/src/runtime/actors/spot-actor-dispatch.ts +4 -2
- package/src/runtime/admission.ts +18 -5
- package/src/runtime/application-jobs/application-ingress-record-owner.ts +53 -27
- package/src/runtime/application-jobs/application-job-queue-scope.ts +56 -22
- package/src/runtime/application-jobs/contracts.ts +28 -2
- package/src/runtime/backend/contracts/index.ts +63 -32
- package/src/runtime/backend/mesh-completion-table.ts +175 -59
- package/src/runtime/backend/mesh-dispatch-pump.ts +59 -32
- package/src/runtime/backend/node/node-backend-adapter-factory.ts +12 -5
- package/src/runtime/backend/node/node-backend-adapter-support.ts +42 -31
- package/src/runtime/backend/node/node-dealer-channel-client-transport.ts +12 -2
- package/src/runtime/backend/node/node-mesh-backend-adapter.ts +3 -10
- package/src/runtime/backend/node/node-raw-binding-port.ts +73 -37
- package/src/runtime/backend/node/node-raw-mesh-backend.ts +209 -176
- package/src/runtime/backend/node/node-socket-backend-adapter.ts +32 -13
- package/src/runtime/backend/raw-binding-port.ts +18 -3
- package/src/runtime/backend/runtime-message.ts +6 -0
- package/src/runtime/backend/runtime-values.ts +1 -0
- package/src/runtime/channels/channel-clients.ts +90 -41
- package/src/runtime/channels/channel-dispatch-pipeline.ts +69 -34
- package/src/runtime/channels/channel-dispatch-services.ts +69 -1
- package/src/runtime/channels/channel-dispatchers.ts +29 -27
- package/src/runtime/channels/channel-envelope-inspection.ts +2 -16
- package/src/runtime/channels/channel-envelope.ts +133 -8
- package/src/runtime/channels/channel-outbound-operations.ts +22 -8
- package/src/runtime/channels/channel-receive-loops.ts +3 -3
- package/src/runtime/channels/channel-runtime-lifecycle.ts +7 -1
- package/src/runtime/channels/channel-runtime-manager.ts +29 -12
- package/src/runtime/channels/channel-socket-registry.ts +84 -130
- package/src/runtime/channels/channel-transports.ts +128 -60
- package/src/runtime/channels/local-spot-route-transport.ts +3 -1
- package/src/runtime/channels/router-socket-spot-route-transport.ts +13 -4
- package/src/runtime/channels/source-spot-router.ts +8 -4
- package/src/runtime/channels/spot-node-route-transport.ts +8 -4
- package/src/runtime/channels/spot-route-bridge-transport.ts +6 -4
- package/src/runtime/channels/spot-route-dispatch-strategy.ts +47 -18
- package/src/runtime/diagnostics/message-flow.ts +1 -1
- package/src/runtime/execution/serial-execution-queue.ts +2 -0
- package/src/runtime/foundation/actor-join-recovery-codec.ts +2 -2
- package/src/runtime/foundation/durable-service-request.ts +137 -0
- package/src/runtime/foundation/operation-identity.ts +5 -1
- package/src/runtime/foundation/raw-service-mesh-runtime.ts +642 -253
- package/src/runtime/foundation/service-liveness-registry.ts +68 -59
- package/src/runtime/foundation/service-mailbox.ts +7 -1
- package/src/runtime/foundation/service-relocation-object-owner.ts +2 -0
- package/src/runtime/foundation/service-relocation-runtime.ts +18 -1
- package/src/runtime/foundation/service-runtime-contracts.ts +7 -1
- package/src/runtime/foundation/service-stateful-runtime.ts +128 -160
- package/src/runtime/foundation/service-stateful-wire-codec.ts +55 -84
- package/src/runtime/foundation/service-topology-registry.ts +103 -42
- package/src/runtime/foundation/service-wire-m6a-codec.ts +57 -38
- package/src/runtime/handlers/handler-instance-scope.ts +67 -16
- package/src/runtime/host/actor-packet-relay.ts +7 -0
- package/src/runtime/host/actor-runtime-options-factory.ts +14 -2
- package/src/runtime/host/application-job-queue.ts +249 -48
- package/src/runtime/host/entry-actor-runtime.ts +5 -0
- package/src/runtime/host/index.ts +224 -160
- package/src/runtime/host/instance-activation-authority.ts +132 -27
- package/src/runtime/host/remote-bound-session-relay.ts +2 -23
- package/src/runtime/host/route-mesh-runtime.ts +1 -1
- package/src/runtime/host/service-relocation-control.ts +11 -5
- package/src/runtime/host/service-relocation-host-runtime.ts +317 -291
- package/src/runtime/host/spot-address-transport.ts +49 -24
- package/src/runtime/host/spot-runtime-options-factory.ts +4 -0
- package/src/runtime/host/user-spot-creation-coordinator.ts +8 -0
- package/src/runtime/locations/actor-location-claims.ts +52 -30
- package/src/runtime/locations/domain-store-contract.ts +6 -2
- package/src/runtime/locations/in-memory-authority-store.ts +113 -9
- package/src/runtime/locations/in-memory-location-store.ts +25 -3
- package/src/runtime/locations/internal-location-contracts.ts +4 -0
- package/src/runtime/locations/lifecycle.ts +8 -26
- package/src/runtime/locations/location-store-repository.ts +220 -15
- package/src/runtime/locations/resolvers.ts +25 -2
- package/src/runtime/locations/runtime.ts +28 -24
- package/src/runtime/messaging/framework-json-v1.ts +5 -325
- package/src/runtime/messaging/packet-name.ts +5 -25
- package/src/runtime/messaging/request-result.ts +58 -0
- package/src/runtime/messaging/submission-result.ts +7 -3
- package/src/runtime/protocol/service_wire_codec.generated.ts +131 -1
- package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +4 -4
- package/src/runtime/spots/formal-remote-actor-admission-registry.ts +45 -23
- package/src/runtime/spots/index.ts +30 -2
- package/src/runtime/spots/spot-activation.ts +33 -10
- package/src/runtime/spots/spot-actor-admission-coordinator.ts +13 -0
- package/src/runtime/spots/spot-actor-packet-dispatch.ts +10 -0
- package/src/runtime/spots/spot-actor-packet-drain.ts +2 -0
- package/src/runtime/spots/spot-actor-packet-relay-dispatch.ts +1 -0
- package/src/runtime/spots/spot-entry-activation.ts +12 -2
- package/src/runtime/spots/spot-handler-registry.ts +41 -8
- package/src/runtime/spots/spot-node-autoconnect.ts +6 -2
- package/src/runtime/spots/spot-node-runtime-manager.ts +7 -12
- package/src/runtime/spots/spot-outbound.ts +36 -16
- package/src/runtime/spots/spot-routed-spot-packet-dispatch.ts +2 -1
- package/src/runtime/spots/spot-routing-internal.ts +14 -0
- package/src/runtime/spots/spot-runtime-ports.ts +3 -0
- package/src/runtime/spots/spot-subscription-dispatch.ts +0 -3
- package/src/runtime/spots/spot-timer.ts +5 -1
- package/src/runtime/streams/stream-session-runtime.ts +13 -30
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { SeverityNumber } from '@opentelemetry/api-logs';
|
|
2
|
+
import { telemetryLogger } from '../diagnostics/message-flow';
|
|
1
3
|
import { MILLISECONDS_PER_SECOND } from '../diagnostics/runtime-metrics';
|
|
2
4
|
import { ZLinkApplicationJobQueueProfile } from '../../contracts/Dispatch';
|
|
3
5
|
import {
|
|
@@ -11,7 +13,9 @@ import {
|
|
|
11
13
|
import { readFileSync } from 'node:fs';
|
|
12
14
|
import { availableParallelism } from 'node:os';
|
|
13
15
|
import type {
|
|
16
|
+
ApplicationJobOrigin,
|
|
14
17
|
ApplicationJobPermitPort,
|
|
18
|
+
ApplicationJobReceiveRotationPort,
|
|
15
19
|
ApplicationJobQueuePort
|
|
16
20
|
} from '../application-jobs/contracts';
|
|
17
21
|
import {
|
|
@@ -119,10 +123,42 @@ export function resolveApplicationJobQueueConfiguration(
|
|
|
119
123
|
});
|
|
120
124
|
}
|
|
121
125
|
|
|
126
|
+
const enum QueuePermitCount {
|
|
127
|
+
Reserved,
|
|
128
|
+
Queued,
|
|
129
|
+
Peak,
|
|
130
|
+
Size
|
|
131
|
+
}
|
|
132
|
+
|
|
122
133
|
export class ApplicationJobQueuePermit implements ApplicationJobPermitPort {
|
|
123
|
-
|
|
134
|
+
detachedForHandlerTurn = false;
|
|
135
|
+
private state: 'idle' | 'reserved' | 'queued' | 'released';
|
|
136
|
+
|
|
137
|
+
constructor(
|
|
138
|
+
private readonly owner: ApplicationJobQueue,
|
|
139
|
+
readonly origin: ApplicationJobOrigin,
|
|
140
|
+
private readonly reusable = false
|
|
141
|
+
) {
|
|
142
|
+
this.state = reusable ? 'idle' : 'reserved';
|
|
143
|
+
}
|
|
124
144
|
|
|
125
|
-
|
|
145
|
+
reserveStorage(): boolean {
|
|
146
|
+
if (this.state !== 'idle') return false;
|
|
147
|
+
this.state = 'reserved';
|
|
148
|
+
this.detachedForHandlerTurn = false;
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
releaseStorage(): void {
|
|
153
|
+
if (!this.reusable || this.state === 'idle') return;
|
|
154
|
+
if (this.state !== 'released')
|
|
155
|
+
throw new Error('Reservation storage still owns queue capacity.');
|
|
156
|
+
this.state = 'idle';
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
detachForHandlerTurn(): void {
|
|
160
|
+
this.detachedForHandlerTurn = true;
|
|
161
|
+
}
|
|
126
162
|
|
|
127
163
|
markApplicationQueued(): void {
|
|
128
164
|
if (this.state !== 'reserved') {
|
|
@@ -134,21 +170,78 @@ export class ApplicationJobQueuePermit implements ApplicationJobPermitPort {
|
|
|
134
170
|
|
|
135
171
|
releaseBeforeHandler(): void {
|
|
136
172
|
if (this.owner.shouldHoldPermitBeforeHandler()) return;
|
|
137
|
-
this.
|
|
173
|
+
this.owner.releasePermit(this);
|
|
138
174
|
}
|
|
139
175
|
|
|
140
176
|
releaseAfterInternalProcessing(): void {
|
|
141
|
-
this.
|
|
177
|
+
this.owner.releasePermit(this);
|
|
142
178
|
}
|
|
143
179
|
|
|
144
|
-
|
|
145
|
-
if (this.state === 'released') return;
|
|
146
|
-
this.
|
|
180
|
+
takeReleaseState(): 'reserved' | 'queued' | undefined {
|
|
181
|
+
if (this.state === 'released' || this.state === 'idle') return undefined;
|
|
182
|
+
const state = this.state;
|
|
147
183
|
this.state = 'released';
|
|
184
|
+
return state;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Connection-owned storage; queue accounting remains with the host queue. */
|
|
189
|
+
class ApplicationJobReceiveRotation implements ApplicationJobReceiveRotationPort {
|
|
190
|
+
private readonly storage: ApplicationJobQueuePermit[] = [];
|
|
191
|
+
private readonly grants: (ApplicationJobQueuePermit | undefined)[];
|
|
192
|
+
private granted = 0;
|
|
193
|
+
private consumed = 0;
|
|
194
|
+
|
|
195
|
+
constructor(
|
|
196
|
+
private readonly owner: ApplicationJobQueue,
|
|
197
|
+
private readonly capacity: number,
|
|
198
|
+
private readonly origin: ApplicationJobOrigin
|
|
199
|
+
) {
|
|
200
|
+
this.grants = new Array<ApplicationJobQueuePermit | undefined>(capacity);
|
|
201
|
+
this.prepareStorage();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
private prepareStorage(): void {
|
|
205
|
+
for (let index = 0; index < this.capacity; index++)
|
|
206
|
+
this.storage.push(new ApplicationJobQueuePermit(this.owner, this.origin, true));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
reserve(): void {
|
|
210
|
+
this.releaseUnused();
|
|
211
|
+
const count = this.owner.receiveRotationCapacity(this.capacity);
|
|
212
|
+
if (count === 0) return;
|
|
213
|
+
for (let index = 0; index < this.storage.length; index++) {
|
|
214
|
+
const permit = this.storage[index]!;
|
|
215
|
+
if (permit.reserveStorage()) this.grants[this.granted++] = permit;
|
|
216
|
+
if (this.granted === count) break;
|
|
217
|
+
}
|
|
218
|
+
if (this.granted < count) {
|
|
219
|
+
const start = this.storage.length;
|
|
220
|
+
this.prepareStorage();
|
|
221
|
+
for (let index = start; this.granted < count; index++) {
|
|
222
|
+
const permit = this.storage[index]!;
|
|
223
|
+
permit.reserveStorage();
|
|
224
|
+
this.grants[this.granted++] = permit;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
this.owner.reserveReceiveRotation(count);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
take(): ApplicationJobQueuePermit | undefined {
|
|
231
|
+
if (this.consumed === this.granted) return undefined;
|
|
232
|
+
return this.grants[this.consumed++];
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
releaseUnused(): void {
|
|
236
|
+
this.owner.releaseUnusedReceiveRotation(this.grants, this.consumed, this.granted);
|
|
237
|
+
// Keep the prepared grant slots and reset only the logical count.
|
|
238
|
+
this.granted = 0;
|
|
239
|
+
this.consumed = 0;
|
|
148
240
|
}
|
|
149
241
|
}
|
|
150
242
|
|
|
151
243
|
interface CapacityWaiter {
|
|
244
|
+
readonly origin: ApplicationJobOrigin;
|
|
152
245
|
readonly resolve: (permit: ApplicationJobQueuePermit) => void;
|
|
153
246
|
readonly reject: (reason: unknown) => void;
|
|
154
247
|
readonly signal?: AbortSignal;
|
|
@@ -164,9 +257,13 @@ interface CapacityWaiter {
|
|
|
164
257
|
* directly to the oldest live waiter without allocating the configured limit.
|
|
165
258
|
*/
|
|
166
259
|
export class ApplicationJobQueue implements ApplicationJobQueuePort {
|
|
167
|
-
private
|
|
168
|
-
private
|
|
169
|
-
|
|
260
|
+
private localWaiters = 0;
|
|
261
|
+
private localBacklogLogged = false;
|
|
262
|
+
// The contract bounds capacity by INT32_MAX; public snapshots remain bigint.
|
|
263
|
+
private readonly permitCounts = new Uint32Array(QueuePermitCount.Size);
|
|
264
|
+
private readonly limitCount: number;
|
|
265
|
+
private readonly pauseCount: number;
|
|
266
|
+
private readonly resumeCount: number;
|
|
170
267
|
private capacityWaitCount = 0n;
|
|
171
268
|
private capacityWaitDurationSeconds = 0;
|
|
172
269
|
private metricsEpoch = 0n;
|
|
@@ -191,8 +288,12 @@ export class ApplicationJobQueue implements ApplicationJobQueuePort {
|
|
|
191
288
|
constructor(
|
|
192
289
|
private readonly configuration: ApplicationJobQueueConfiguration,
|
|
193
290
|
private readonly nowMs: () => number = () => performance.now(),
|
|
194
|
-
private readonly handlerStartGate?: () => boolean
|
|
291
|
+
private readonly handlerStartGate?: () => boolean,
|
|
292
|
+
private readonly loggerFailureReporter?: (error: unknown) => void
|
|
195
293
|
) {
|
|
294
|
+
this.limitCount = Number(configuration.effectiveMaxQueuedApplicationJobs);
|
|
295
|
+
this.pauseCount = Number(configuration.pausePermitCount);
|
|
296
|
+
this.resumeCount = Number(configuration.resumePermitCount);
|
|
196
297
|
this.receiveFlowController = new ApplicationJobReceiveFlowController(this, (state) => state);
|
|
197
298
|
}
|
|
198
299
|
|
|
@@ -200,6 +301,24 @@ export class ApplicationJobQueue implements ApplicationJobQueuePort {
|
|
|
200
301
|
return this.handlerStartGate?.() === true;
|
|
201
302
|
}
|
|
202
303
|
|
|
304
|
+
createReceiveRotation(
|
|
305
|
+
capacity: number,
|
|
306
|
+
origin: ApplicationJobOrigin
|
|
307
|
+
): ApplicationJobReceiveRotationPort {
|
|
308
|
+
if (!Number.isSafeInteger(capacity) || capacity < 1)
|
|
309
|
+
throw new RangeError('Receive capacity must be positive.');
|
|
310
|
+
return new ApplicationJobReceiveRotation(this, capacity, origin);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
receiveRotationCapacity(capacity: number): number {
|
|
314
|
+
if (this.waiters.length !== 0) return 0;
|
|
315
|
+
return Math.min(capacity, this.limitCount - this.permitsInUse());
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
reserveReceiveRotation(count: number): void {
|
|
319
|
+
this.reserveSupply(count);
|
|
320
|
+
}
|
|
321
|
+
|
|
203
322
|
registerReceiveFlowTarget(
|
|
204
323
|
identity: object,
|
|
205
324
|
applyState: (state: ApplicationJobQueuePressureState) => void,
|
|
@@ -242,16 +361,33 @@ export class ApplicationJobQueue implements ApplicationJobQueuePort {
|
|
|
242
361
|
this.receiveFlowController.unregister(target);
|
|
243
362
|
}
|
|
244
363
|
|
|
245
|
-
acquire(
|
|
364
|
+
acquire(
|
|
365
|
+
signal: AbortSignal | undefined,
|
|
366
|
+
origin: ApplicationJobOrigin
|
|
367
|
+
): Promise<ApplicationJobQueuePermit> {
|
|
368
|
+
return new Promise((resolve, reject) => {
|
|
369
|
+
const permit = this.acquireOrResume(resolve, reject, signal, origin);
|
|
370
|
+
if (permit !== undefined) resolve(permit);
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
acquireOrResume(
|
|
375
|
+
resume: (permit: ApplicationJobQueuePermit) => void,
|
|
376
|
+
reject: (reason: unknown) => void,
|
|
377
|
+
signal: AbortSignal | undefined,
|
|
378
|
+
origin: ApplicationJobOrigin
|
|
379
|
+
): ApplicationJobQueuePermit | undefined {
|
|
246
380
|
if (signal?.aborted === true) {
|
|
247
|
-
|
|
381
|
+
reject(abortReason(signal));
|
|
382
|
+
return undefined;
|
|
248
383
|
}
|
|
249
|
-
if (this.waiters.length === 0 && this.permitsInUse() < this.
|
|
250
|
-
return
|
|
384
|
+
if (this.waiters.length === 0 && this.permitsInUse() < this.limitCount) {
|
|
385
|
+
return this.reserve(origin);
|
|
251
386
|
}
|
|
252
387
|
|
|
253
|
-
|
|
388
|
+
new Promise<ApplicationJobQueuePermit>((resolve, reject) => {
|
|
254
389
|
const waiter: CapacityWaiter = {
|
|
390
|
+
origin,
|
|
255
391
|
resolve,
|
|
256
392
|
reject,
|
|
257
393
|
signal,
|
|
@@ -262,9 +398,14 @@ export class ApplicationJobQueue implements ApplicationJobQueuePort {
|
|
|
262
398
|
};
|
|
263
399
|
this.waiters.push(waiter);
|
|
264
400
|
this.capacityWaitCount += 1n;
|
|
401
|
+
const warningCount = this.updateLocalWaiters(origin, 1);
|
|
265
402
|
signal?.addEventListener('abort', waiter.abort, { once: true });
|
|
266
403
|
this.drainWaiters();
|
|
267
|
-
|
|
404
|
+
if (warningCount !== undefined) this.logLocalBacklog(warningCount);
|
|
405
|
+
})
|
|
406
|
+
.then(resume)
|
|
407
|
+
.catch(reject);
|
|
408
|
+
return undefined;
|
|
268
409
|
}
|
|
269
410
|
|
|
270
411
|
snapshot(): ApplicationJobQueueSnapshot {
|
|
@@ -272,10 +413,10 @@ export class ApplicationJobQueue implements ApplicationJobQueuePort {
|
|
|
272
413
|
const now = this.nowMs();
|
|
273
414
|
return Object.freeze({
|
|
274
415
|
...this.configuration,
|
|
275
|
-
reservedSupplyPermits: this.
|
|
276
|
-
queuedApplicationJobs: this.
|
|
277
|
-
permitsInUse,
|
|
278
|
-
peakPermitsInUse: this.
|
|
416
|
+
reservedSupplyPermits: BigInt(this.permitCounts[QueuePermitCount.Reserved]!),
|
|
417
|
+
queuedApplicationJobs: BigInt(this.permitCounts[QueuePermitCount.Queued]!),
|
|
418
|
+
permitsInUse: BigInt(permitsInUse),
|
|
419
|
+
peakPermitsInUse: BigInt(this.permitCounts[QueuePermitCount.Peak]!),
|
|
279
420
|
capacityWaiters: BigInt(this.waiters.length),
|
|
280
421
|
capacityWaitCount: this.capacityWaitCount,
|
|
281
422
|
capacityWaitDurationSeconds: this.capacityWaitDurationSeconds,
|
|
@@ -291,7 +432,7 @@ export class ApplicationJobQueue implements ApplicationJobQueuePort {
|
|
|
291
432
|
|
|
292
433
|
resetMetrics(): void {
|
|
293
434
|
this.metricsEpoch += 1n;
|
|
294
|
-
this.
|
|
435
|
+
this.permitCounts[QueuePermitCount.Peak] = this.permitsInUse();
|
|
295
436
|
this.capacityWaitCount = 0n;
|
|
296
437
|
this.capacityWaitDurationSeconds = 0;
|
|
297
438
|
this.runningTransitionCount = 0n;
|
|
@@ -325,25 +466,42 @@ export class ApplicationJobQueue implements ApplicationJobQueuePort {
|
|
|
325
466
|
}
|
|
326
467
|
|
|
327
468
|
markQueued(): void {
|
|
328
|
-
if (this.
|
|
469
|
+
if (this.permitCounts[QueuePermitCount.Reserved] === 0) {
|
|
329
470
|
throw new Error('Application job queue has no reserved supply permit.');
|
|
330
471
|
}
|
|
331
|
-
this.
|
|
332
|
-
|
|
472
|
+
this.permitCounts[QueuePermitCount.Reserved] =
|
|
473
|
+
this.permitCounts[QueuePermitCount.Reserved]! - 1;
|
|
474
|
+
this.permitCounts[QueuePermitCount.Queued] = this.permitCounts[QueuePermitCount.Queued]! + 1;
|
|
333
475
|
}
|
|
334
476
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
477
|
+
releasePermit(permit: ApplicationJobQueuePermit): void {
|
|
478
|
+
const state = permit.takeReleaseState();
|
|
479
|
+
if (state !== undefined) this.release(state);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
releaseUnusedReceiveRotation(
|
|
483
|
+
grants: readonly (ApplicationJobQueuePermit | undefined)[],
|
|
484
|
+
consumed: number,
|
|
485
|
+
granted: number
|
|
486
|
+
): void {
|
|
487
|
+
const count = granted - consumed;
|
|
488
|
+
if (count === 0) return;
|
|
489
|
+
// Unconsumed grants still belong to this receive round; no record has acquired them.
|
|
490
|
+
for (let index = consumed; index < granted; index++) {
|
|
491
|
+
const permit = grants[index]!;
|
|
492
|
+
permit.takeReleaseState();
|
|
493
|
+
permit.releaseStorage();
|
|
494
|
+
}
|
|
495
|
+
this.release('reserved', count);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
release(state: 'reserved' | 'queued', count = 1): void {
|
|
499
|
+
const index = state === 'reserved' ? QueuePermitCount.Reserved : QueuePermitCount.Queued;
|
|
500
|
+
const available = this.permitCounts[index]!;
|
|
501
|
+
if (available < count) {
|
|
502
|
+
throw new Error(`Application job queue ${state} permit accounting underflow.`);
|
|
346
503
|
}
|
|
504
|
+
this.permitCounts[index] = available - count;
|
|
347
505
|
this.drainWaiters();
|
|
348
506
|
this.evaluatePressure();
|
|
349
507
|
}
|
|
@@ -352,26 +510,38 @@ export class ApplicationJobQueue implements ApplicationJobQueuePort {
|
|
|
352
510
|
return this.configuration.effectiveMaxQueuedApplicationJobs;
|
|
353
511
|
}
|
|
354
512
|
|
|
355
|
-
private permitsInUse():
|
|
356
|
-
return
|
|
513
|
+
private permitsInUse(): number {
|
|
514
|
+
return (
|
|
515
|
+
this.permitCounts[QueuePermitCount.Reserved]! + this.permitCounts[QueuePermitCount.Queued]!
|
|
516
|
+
);
|
|
357
517
|
}
|
|
358
518
|
|
|
359
|
-
private
|
|
360
|
-
this.
|
|
361
|
-
|
|
362
|
-
|
|
519
|
+
private reserveSupply(count: number, evaluatePressure = true): void {
|
|
520
|
+
this.permitCounts[QueuePermitCount.Reserved] =
|
|
521
|
+
this.permitCounts[QueuePermitCount.Reserved]! + count;
|
|
522
|
+
this.permitCounts[QueuePermitCount.Peak] = Math.max(
|
|
523
|
+
this.permitCounts[QueuePermitCount.Peak]!,
|
|
524
|
+
this.permitsInUse()
|
|
525
|
+
);
|
|
363
526
|
if (evaluatePressure) this.evaluatePressure();
|
|
364
|
-
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
private reserve(
|
|
530
|
+
origin: ApplicationJobOrigin,
|
|
531
|
+
evaluatePressure = true
|
|
532
|
+
): ApplicationJobQueuePermit {
|
|
533
|
+
this.reserveSupply(1, evaluatePressure);
|
|
534
|
+
return new ApplicationJobQueuePermit(this, origin);
|
|
365
535
|
}
|
|
366
536
|
|
|
367
537
|
private drainWaiters(): void {
|
|
368
|
-
while (this.waiters.length > 0 && this.permitsInUse() < this.
|
|
538
|
+
while (this.waiters.length > 0 && this.permitsInUse() < this.limitCount) {
|
|
369
539
|
const waiter = this.waiters.shift()!;
|
|
370
540
|
if (!waiter.active) continue;
|
|
371
541
|
waiter.active = false;
|
|
372
542
|
waiter.signal?.removeEventListener('abort', waiter.abort);
|
|
373
543
|
this.recordCompletedWait(waiter);
|
|
374
|
-
waiter.resolve(this.reserve(false));
|
|
544
|
+
waiter.resolve(this.reserve(waiter.origin, false));
|
|
375
545
|
}
|
|
376
546
|
}
|
|
377
547
|
|
|
@@ -387,19 +557,50 @@ export class ApplicationJobQueue implements ApplicationJobQueuePort {
|
|
|
387
557
|
}
|
|
388
558
|
|
|
389
559
|
private recordCompletedWait(waiter: CapacityWaiter): void {
|
|
560
|
+
this.updateLocalWaiters(waiter.origin, -1);
|
|
390
561
|
if (waiter.metricsEpoch !== this.metricsEpoch) return;
|
|
391
562
|
const durationMs = Math.max(0, this.nowMs() - waiter.startedAtMs);
|
|
392
563
|
this.capacityWaitDurationSeconds += durationMs / MILLISECONDS_PER_SECOND;
|
|
393
564
|
}
|
|
394
565
|
|
|
566
|
+
private updateLocalWaiters(origin: ApplicationJobOrigin, delta: number): number | undefined {
|
|
567
|
+
if (origin !== 'local') return undefined;
|
|
568
|
+
this.localWaiters += delta;
|
|
569
|
+
if (this.localWaiters === 0) this.localBacklogLogged = false;
|
|
570
|
+
if (!this.localBacklogLogged && this.localWaiters > Number(this.limit())) {
|
|
571
|
+
this.localBacklogLogged = true;
|
|
572
|
+
return this.localWaiters;
|
|
573
|
+
}
|
|
574
|
+
return undefined;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
private logLocalBacklog(localWaiters: number): void {
|
|
578
|
+
try {
|
|
579
|
+
telemetryLogger.emit({
|
|
580
|
+
eventName: 'zlink.runtime.host.local_job_backlog_exceeded',
|
|
581
|
+
timestamp: new Date(),
|
|
582
|
+
severityNumber: SeverityNumber.WARN,
|
|
583
|
+
severityText: 'WARN',
|
|
584
|
+
body: 'Same-host jobs waiting for a host permit exceeded the application job queue maximum.',
|
|
585
|
+
attributes: {
|
|
586
|
+
source_kind: 'host',
|
|
587
|
+
source_name: 'zlink.runtime.host',
|
|
588
|
+
local_waiters: localWaiters,
|
|
589
|
+
effective_maximum: Number(this.limit())
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
} catch (error) {
|
|
593
|
+
this.loggerFailureReporter?.(error);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
395
597
|
private evaluatePressure(): void {
|
|
396
|
-
const permitsInUse = this.permitsInUse();
|
|
397
598
|
const next =
|
|
398
599
|
this.pressureStateValue === 'running'
|
|
399
|
-
? permitsInUse >= this.
|
|
600
|
+
? this.permitsInUse() >= this.pauseCount
|
|
400
601
|
? 'paused'
|
|
401
602
|
: 'running'
|
|
402
|
-
: permitsInUse <= this.
|
|
603
|
+
: this.permitsInUse() <= this.resumeCount
|
|
403
604
|
? 'running'
|
|
404
605
|
: 'paused';
|
|
405
606
|
if (next === this.pressureStateValue) return;
|
|
@@ -33,6 +33,10 @@ export class ZLinkEntryActorRuntimeService implements ZLinkEntryActorRuntime {
|
|
|
33
33
|
return this.options.actorManager()?.getState(actorId)?.actor;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
async releaseMembers(meshName: string): Promise<void> {
|
|
37
|
+
await this.options.actorManager()?.releaseSpotActorMembers(meshName);
|
|
38
|
+
}
|
|
39
|
+
|
|
36
40
|
async commitActorTransaction(actor: ZLinkActor, onJoined: () => Promise<void>): Promise<void> {
|
|
37
41
|
const state = this.options.actorManager()?.getState(actor.context.actorId);
|
|
38
42
|
const entryNode = this.options.spotNodeRuntime()?.primaryMeshNode;
|
|
@@ -95,6 +99,7 @@ export class ZLinkEntryActorRuntimeService implements ZLinkEntryActorRuntime {
|
|
|
95
99
|
return {
|
|
96
100
|
handled: true,
|
|
97
101
|
response: await spotManager.dispatchRoutedActorPacket(
|
|
102
|
+
'remote',
|
|
98
103
|
spotId,
|
|
99
104
|
actorId,
|
|
100
105
|
parts,
|