Rate-limit PEXPIRE on entity event streams - #8032
Open
nicholaspcr wants to merge 2 commits into
Open
nicholaspcr wants to merge 2 commits into
nicholaspcr wants to merge 2 commits into
Conversation
nicholaspcr
marked this pull request as ready for review
September 21, 2026 13:11
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Backport of https://github.com/TheThingsIndustries/lorawan-stack/pull/4960
The events Redis store issued a
PEXPIREper entity event stream per published event, dominating write load on the events Redis. Streams are now refreshed at most once perevents.redis.store.entity-ttl / 2. Retention is unchanged.Changes
pkg/events/redis/expire_limiter.go: a fixed-size, pointer-free table that allows onePEXPIREper stream per interval. Anything uncertain allows aPEXPIRE, never skips one.publishnow gatesPExpireon the limiter, built inNewPubSub.events.redis.store.expire-limiter-size: streams tracked, 8 bytes each, defaulting to4194304(32 MiB). Negative refreshes the TTL on every event.Testing
Steps
go test -race -run TestExpireLimiter ./pkg/events/redis/go test -run XXX -bench BenchmarkExpireLimiter ./pkg/events/redis/tools/bin/mage dev:dbStart && TEST_REDIS=1 go test ./pkg/events/redis/golangci-lint run ./pkg/events/redis/...Results
Limiter tests pass under
-race;allowis 10.28 ns/op, zero allocations (Apple M4); lint reports no new issues.Regressions
Affects every component publishing events with
events.redis.store.enableset, most visibly the Application Server and Network Server. Covered by the existing suite plus limiter tests for counter wrap, eviction, concurrency, and refresh landing inside the jittered TTL.Checklist
README.mdfor the chosen target branch.CHANGELOG.md.CONTRIBUTING.md, there are no fixup commits left.