Skip to content

perf(auditlogs,localization): reduce per-request overhead#124

Merged
antosubash merged 3 commits intomainfrom
perf/reduce-request-overhead
Apr 27, 2026
Merged

perf(auditlogs,localization): reduce per-request overhead#124
antosubash merged 3 commits intomainfrom
perf/reduce-request-overhead

Conversation

@antosubash
Copy link
Copy Markdown
Owner

Summary

Trims work on the AuditLogs and Localization request hot paths, plus a small DoS-hardening tweak.

  • Logging noise: silenced ZiggyCreatures.Caching.Fusion and EF Core Database.Command at Information so cache calls and SQL commands no longer log per request.
  • AuditMiddleware: collapsed the 5 separate ISettingsContracts + FusionCache lookups into one composite cache entry (auditlogs:request-config, 60s TTL). Cache hits do zero scoped DI work — ISettingsContracts is resolved only inside the cache-miss factory. New Wolverine handler (AuditConfigCacheInvalidator) listens on SettingChangedEvent and evicts the entry when an auditlogs.* setting changes, so updates land immediately instead of waiting out the TTL. ExcludedPaths switched to string[] for span-friendly iteration.
  • AuditWriterService: replaced the per-iteration linger CTS with a single linked source scoping the whole batch fill, and removed the OperationCanceledException filter so a shutdown mid-linger now persists already-drained entries instead of dropping them. Dead CancellationToken parameter on FlushBatchAsync removed.
  • LocaleResolutionMiddleware: cache an empty sentinel when a user has no app.language setting so we stop probing settings on every subsequent request. Cap Accept-Language cache keys at 256 chars so a hostile client can't pin multi-KB strings in the L1 cache.

Test plan

  • dotnet build clean (no warnings/errors)
  • dotnet test modules/AuditLogs/tests/SimpleModule.AuditLogs.Tests — 37/37 passing
  • Sanity-run the host: confirm cache-hit path no longer resolves ISettingsContracts per request (logs / profiler)
  • Toggle an auditlogs.* setting in dev and confirm the change takes effect on the next request rather than after 60s
  • Verify the writer flushes a partial batch on graceful shutdown (no dropped entries)

- Quiet ZiggyCreatures.Caching.Fusion + EF Core Database.Command at Information level — was producing two log lines per cache call and one per SQL command on every request.
- AuditMiddleware: wrap the 5-setting parallel batch in a single FusionCache entry (auditlogs:request-config, 60s TTL) so subsequent requests do one cache lookup instead of five.
- AuditWriterService: add a linger window after the first read so the writer accumulates a real batch instead of flushing one entry per request.
- LocaleResolutionMiddleware: cache an empty sentinel when a user has no app.language setting so we stop probing the settings cache on every subsequent request.
- AuditMiddleware: inject IFusionCache via the primary constructor and defer the scoped ISettingsContracts resolution to the cache-miss factory, so cache hits do zero scoped DI work. Move the cache key to a shared AuditCacheKeys constant and switch ExcludedPaths to string[] for span-friendly iteration.
- AuditLogs: add AuditConfigCacheInvalidator (Wolverine handler on SettingChangedEvent) so auditlogs.* setting changes evict the composite request-config entry instead of waiting for the 60s TTL. Register the assembly with Wolverine via AuditLogsWolverineExtension.
- AuditWriterService: collapse the per-iteration linger CTS into a single linked source scoping the whole batch fill, drop the OperationCanceledException filter so shutdown mid-linger persists already-drained entries instead of dropping them, and remove the unused CancellationToken parameter from FlushBatchAsync.
- LocaleResolutionMiddleware: cap Accept-Language cache keys at 256 chars so a hostile client cannot pin multi-KB strings in the L1 cache.
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 26, 2026

Deploying simplemodule-website with  Cloudflare Pages  Cloudflare Pages

Latest commit: b59b4c5
Status: ✅  Deploy successful!
Preview URL: https://9709ca7a.simplemodule-website.pages.dev
Branch Preview URL: https://perf-reduce-request-overhead.simplemodule-website.pages.dev

View logs

OpenTelemetry.Api 1.14.0 and OpenTelemetry.Exporter.OpenTelemetryProtocol
1.14.0 picked up GHSA advisories (g94r-2vxg-569j, mr8r-92fq-pj8p,
q834-8qmm-v933) that NuGetAudit + TreatWarningsAsErrors elevate to NU1902
build failures. Bump direct refs to the highest stable for each package
so the transitive Api resolves to a non-vulnerable version.
@antosubash antosubash merged commit 65e8b26 into main Apr 27, 2026
5 checks passed
@antosubash antosubash deleted the perf/reduce-request-overhead branch April 27, 2026 16:18
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.

1 participant