Skip to content

Optimize Access Log and MQTT Session Paths#1502

Merged
xxx7xxxx merged 3 commits intoeasegress-io:mainfrom
LokiWager:codex/combine-pr-3-4-5
Feb 28, 2026
Merged

Optimize Access Log and MQTT Session Paths#1502
xxx7xxxx merged 3 commits intoeasegress-io:mainfrom
LokiWager:codex/combine-pr-3-4-5

Conversation

@LokiWager
Copy link
Collaborator

Summary

This PR combines three performance optimizations:

  1. Access log formatter regex optimization (pkg/object/httpserver/mux.go)
  • Move regex compilation to package-level variables.
  • Avoid recompiling regexes during repeated formatter creation (for example, config reloads).
  1. MQTT session loop optimization (pkg/object/mqttproxy/session.go)
  • Reuse timestamp values from ticker.C instead of repeated time.Now() calls in the background loop.
  • Reduce loop overhead from redundant system calls.
  1. MQTT session pagination optimization (pkg/object/mqttproxy/broker.go)
  • Add an in-memory session cache in Broker (map + sorted key slice).
  • Keep cache synchronized through existing store watcher updates.
  • Remove full-store fetch + full iteration from every paginated request.
  • Make pagination deterministic via sorted keys.

Why

The previous implementation had repeated compute/system-call overhead and O(N) storage/CPU cost in hot paths:

  • regex compilation during formatter construction
  • repeated time.Now() calls in high-frequency loop
  • full session scan + backend fetch on each pagination request

This PR reduces those costs while preserving behavior.

Measured Improvements (from original PR benchmarks)

  • Access log formatter:

    • ~20473 ns/op -> ~12821 ns/op (~37% faster)
    • 112 allocs/op -> 74 allocs/op (~34% fewer)
    • 8758 B/op -> 4774 B/op (~45% less memory)
  • MQTT session loop:

    • ~174.4 ns/op -> ~69.01 ns/op (~2.5x faster)
  • MQTT session pagination:

    • ~206,380 ns/op -> ~3,917 ns/op (~52x faster)
    • eliminates O(N) backend getPrefix call per list request

Safety / Compatibility

  • No intentional functional behavior changes.
  • Broker cache access is protected by existing RWMutex usage.
  • Existing pagination/filter behavior is preserved.

google-labs-jules bot and others added 3 commits February 24, 2026 17:29
Co-authored-by: LokiWager <32408858+LokiWager@users.noreply.github.com>
Replaced redundant time.Now() calls with the time value received from ticker.C in the background session task loop. This reduces syscall overhead. Verified with microbenchmarks (~2.5x speedup in loop overhead).

Co-authored-by: LokiWager <32408858+LokiWager@users.noreply.github.com>
- Added `sessionCache` and `sortedSessionKeys` to `Broker`.
- Initialized and updated cache via `connectWatcher` and `processWatcherEvent`.
- Rewrote `queryAllSessions` to use cached sorted keys for efficient pagination.
- Updated `httpGetAllSessionHandler` to use the cache instead of fetching all sessions from store.
- Replaced random map iteration with deterministic sorted slice iteration.

Co-authored-by: LokiWager <32408858+LokiWager@users.noreply.github.com>
@xxx7xxxx xxx7xxxx added this pull request to the merge queue Feb 28, 2026
Merged via the queue into easegress-io:main with commit b21c3ee Feb 28, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants