Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
docs(events): say what the socket deadline frees and when
Yudhi Armyndharis6506667be53d
diff --git a/docs/13-horizontal-scaling.md b/docs/13-horizontal-scaling.mdindex 7f38d4af3..609e3d401 100644--- a/docs/13-horizontal-scaling.md+++ b/docs/13-horizontal-scaling.md@@ -158,11 +158,12 @@> disconnected, plus its reconnect backoff of up to 5 s once Redis is back, are dropped for the clients> connected to the other replicas: they are not delivered late and not twice. Clients connected to the node> that raised an event are served directly, and webhooks do not use this path, so neither is affected. Memory-> is bounded in two ways. A Redis that sends nothing for 10 s has the connection destroyed, which releases-> what the node held for it: at most 10 s of events. A Redis that keeps answering, but slower than events are-> raised, is never silent for 10 s, so the node holds at most 12,000 unanswered events (10 s at 1,000 events a-> second, with a fifth to spare) and drops further frames for the other replicas, with one warning per burst,-> until Redis catches up. A replica whose own Redis connection is reconnecting also misses what the others+> is bounded in two ways. A Redis that sends nothing for 10 s has the connection destroyed, and the node holds+> nothing more for it; what it had already held, at most 10 s of events, is freed once the node has reconnected.+> A Redis that keeps answering, but slower than events are raised, is never silent for 10 s, so the node holds+> at most 12,000 unanswered events (10 s at 1,000 events a second, with a fifth to spare) and drops further+> frames for the other replicas until Redis catches up, with a warning when dropping starts and another, with+> the count, when it ends. A replica whose own Redis connection is reconnecting also misses what the others> publish meanwhile.>> **Mid-connection key eviction converges on a timer, not a broadcast, and only on one node.** Thediff --git a/src/modules/events/redis-io.adapter.ts b/src/modules/events/redis-io.adapter.tsindex 6bac830e1..d6ccc8110 100644--- a/src/modules/events/redis-io.adapter.ts+++ b/src/modules/events/redis-io.adapter.ts@@ -19,11 +19,12 @@ export const WS_REDIS_COMMAND_TIMEOUT_MS = 2000;/*** How long the publish client's socket may stay silent after a write before it is destroyed, which is what- * releases what a stalled Redis left in the client. The timer runs on this process's own event loop, so a healthy+ * stops a stalled Redis from filling the client. The timer runs on this process's own event loop, so a healthy* Redis looks silent whenever the loop stays blocked for that long right after a write, and the connection would* be dropped for nothing. That is why it sits far above any block this process runs, and above the command- * timeout. It bounds a Redis that sends nothing: after this long the socket is destroyed and what the client- * holds is released. A Redis that answers, however slowly, resets it with every reply, and is bounded by+ * timeout. It bounds a Redis that sends nothing: after this long the socket is destroyed and nothing more is+ * held. What was already held, at most this many seconds of events, stays until the client has reconnected. A+ * Redis that answers, however slowly, resets the timer with every reply, and is bounded by* WS_REDIS_MAX_UNANSWERED instead.*/export const WS_REDIS_SOCKET_TIMEOUT_MS = 10_000;@@ -31,9 +32,10 @@ export const WS_REDIS_SOCKET_TIMEOUT_MS = 10_000;/*** Most commands the publisher keeps written and unanswered. A Redis that answers slower than events are raised* never trips the socket deadline, so without a cap the backlog grows with the load for as long as the slowness- * lasts. Frames raised above the cap are dropped for the other replicas, once warned per burst, until the queue- * drains. 12,000 holds a full socket deadline of traffic at 1,000 events a second with a fifth to spare, which- * measured about 25 MB of heap with 1 KiB frames. It counts commands, not bytes: events with inline media are larger.+ * lasts. Frames raised above the cap are dropped for the other replicas until the queue drains, with a warning+ * when dropping starts and another, with the count, when Redis catches up. 12,000 holds a full socket deadline of+ * traffic at 1,000 events a second with a fifth to spare, which measured about 25 MB of heap with 1 KiB frames.+ * It counts commands, not bytes: events with inline media are larger.*/export const WS_REDIS_MAX_UNANSWERED = 12_000;