Skip to content

Filter SSE sessions by their thing IDs before the namespace access check - #2671

Open
thjaeckle wants to merge 1 commit into
eclipse-ditto:masterfrom
beyonnex-io:perf/sse-target-thing-ids-early-filter
Open

thjaeckle wants to merge 1 commit into
eclipse-ditto:masterfrom
beyonnex-io:perf/sse-target-thing-ids-early-filter

Conversation

@thjaeckle

@thjaeckle thjaeckle commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

The SSE session summary added in 3.9.9 showed that SSE sessions in production discard almost everything they process: within 6 days, ~94M signals reached SSE sessions and only ~155k (0.17%) were delivered to clients. All of these sessions subscribed with ids (/api/2/things?ids=...), mostly for a single thing, and none used namespaces or filter. A session whose subjects may read most things received ~300 signals/s, i.e. the change events of the whole fleet.

The reason: the SSE routes knew the requested thing IDs, but the StreamingSessionActor did not. It checked every signal the session's subjects may read, including the costly namespace access check, and published it to the SSE stream. Only there did ThingsSseRouteBuilder.postprocess drop the signals of all other things.

In addition, isSessionAllowedToReceiveSignal computed all checks before combining them, so the namespace access check also ran for signals the subscriber is not allowed to read.

Change

  • StartStreaming carries the requested thing IDs. The SSE routes set them for /things?ids=..., /things/<thingId>[/<path>] and the message inbox/outbox routes.
  • StreamingSession.matchesThingIds matches a signal's entity ID against them. An empty set matches all signals, so WebSocket sessions are unaffected.
  • StreamingSessionActor applies the checks cheapest first and stops at the first failing one: thing IDs, namespaces, read subjects, then namespace access. The changed order also benefits WebSocket sessions.
  • The thing ID and namespace checks in the SSE route are kept as before.

Compatibility

  • The signals delivered to SSE clients are unchanged.
  • sse-received of the SSE session summary no longer counts signals of other things, so it is now close to sse-targeted. The documentation in httpapi-sse.md is adapted.
  • No public API change. StartStreaming and StreamingSession are gateway-internal.
  • The commit applies cleanly to release-3.9, so it can be backported to a 3.9.x patch release.

Tests

  • StreamingSessionActorTest: only signals of the requested thing IDs are published, and the namespace access validator is not consulted for signals of other things.
  • StreamingSessionTest: unit tests for matchesThingIds.
  • ThingsSseRouteBuilderTest: a new ?ids=a,b test, and the per-thing route tests now check the thing IDs passed to StartStreaming.

SSE sessions for /things?ids=..., /things/<thingId> and the message
inbox/outbox routes only emit signals of the requested things, but the
streaming session actor did not know these thing IDs. It published every
signal the session's subjects may read to the SSE stream, where the route
dropped all signals of other things only after post-processing them.

Before that, every such signal went through the namespace access check,
which was evaluated even when the subscriber was not allowed to read the
signal at all, as all checks were computed before combining them.

In production, the SSE session summary logged ~94M signals received by
SSE sessions within 6 days, of which only 0.17% were delivered; all of
them subscribed with "ids" for mostly a single thing.

* StartStreaming carries the requested thing IDs, which the SSE routes
  set and the StreamingSession matches signals against
* the streaming session actor applies the checks cheapest first and
  stops at the first failing one: thing IDs, namespaces, read subjects,
  namespace access
* "sse-received" of the SSE session summary therefore no longer counts
  signals of other things

Assisted-by: Anthropic Claude Opus 5.5 (claude-opus-5-5)
Signed-off-by: Thomas Jäckle <thomas.jaeckle@beyonnex.io>
@thjaeckle thjaeckle self-assigned this Nov 25, 2026
@thjaeckle thjaeckle added this to the 3.9.11 milestone Nov 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant