Skip to content

perf(loggly): hoist per-request closure out of log phase#13648

Open
shreemaan-abhishek wants to merge 1 commit into
apache:masterfrom
shreemaan-abhishek:fix/loggly-per-request-closure
Open

perf(loggly): hoist per-request closure out of log phase#13648
shreemaan-abhishek wants to merge 1 commit into
apache:masterfrom
shreemaan-abhishek:fix/loggly-per-request-closure

Conversation

@shreemaan-abhishek

Copy link
Copy Markdown
Contributor

Description

The loggly logger reassigned the handle_http_payload closure on every request inside _M.log(), solely to capture conf. Each request therefore allocated a fresh function object, adding avoidable GC pressure in the log phase. Benchmarking loggers showed loggly carrying a disproportionately high per-request overhead compared to peers in the same class, and this per-request allocation was the cause (P50 is unaffected since the actual send happens in the async batch-processor timer).

This PR hoists the handler to module scope: conf is threaded into handle_log(entries, conf) directly, and the small binding closure is created once per batch processor (i.e. once per config version) rather than once per request. The separate handle_http_payload indirection is removed.

As a side effect this also removes a latent correctness bug: the shared module-level handle_http_payload was overwritten by whichever request ran _M.log() last, so with two routes using different loggly configs the async handler could send a batch with the wrong conf. Binding conf per processor fixes that.

Behavior is otherwise unchanged; existing t/plugin/loggly.t cases (including TEST 15, the http bulk path that asserts conf.tags) continue to cover both the syslog and http paths.

Which issue(s) this PR fixes:

Fixes #

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

The log phase reassigned the handle_http_payload closure on every
request just to capture conf, allocating a new function object per
request and adding GC pressure. Thread conf into handle_log directly
and build the batch-processor handler once per config version instead
of per request. This also removes a latent bug where the shared
module-level closure could resolve the wrong conf when multiple routes
use different loggly configs.
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. performance generate flamegraph for the current PR labels Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance generate flamegraph for the current PR size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant