Skip to content

management: stop converting the whole unit config for every stream - #53726

Merged
shahzad31 merged 3 commits into
elastic:mainfrom
shahzad31:shahzad/management-global-processors-perf
Nov 9, 2026
Merged

shahzad31 merged 3 commits into
elastic:mainfrom
shahzad31:shahzad/management-global-processors-perf

Conversation

@shahzad31

@shahzad31 shahzad31 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Proposed commit message

management: stop converting the whole unit config for every stream

injectGlobalProcesssors called expected.GetSource().AsMap() for each stream.
The source of a unit holds all of its streams, so converting it for every
stream made building the inputs of a unit quadratic in its stream count. Elastic
Agent builds this config several times at startup, and with 10k Synthetics
streams in one component it spent about 140s doing so before it started the
collector.

Only the global processors are needed, so convert just that field. Injecting
processors into every stream of a unit with 8000 streams drops from 8.1s to 3ms.
With 10k streams the agent now starts the collector 4s after it starts, down
from about 143s.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added an entry in ./changelog/fragments using the changelog tool.

Disruptive User Impact

None, the resulting config is the same.

How to test this PR locally

go test -count=1 ./x-pack/libbeat/management/
go test -run xxx -bench BenchmarkInjectGlobalProcessors -benchtime 3x ./x-pack/libbeat/management/
Streams in a unit Before After
500 35 ms 0.2 ms
2,000 536 ms 1.1 ms
8,000 8.1 s 3.1 ms

End to end: Elastic Agent with 10k synthetics/http monitors, in one component in the OTel runtime (single_receiver: true). Agent started to collector started: 143s before, 4s after (the agent profile showed the time in injectGlobalProcesssors through structpb.Struct.AsMap, reached from getReceiversConfigForComponent). Time to the first check went from about 216s to about 90s. The rest is a 60s FQDN lookup timeout in the collector, which this PR does not touch.

Related issues

Use cases

Any receiver or component with thousands of streams in one unit: the agent builds the receiver config several times, and the time grew with the square of the stream count.

Logs

One run on a laptop, standalone agent, fake Elasticsearch sink. The agent only picks this up through a beats submodule bump.

injectGlobalProcesssors called expected.GetSource().AsMap() for each stream.
The source of a unit holds all of its streams, so converting it for every
stream made building the inputs of a unit quadratic in its stream count. Elastic
Agent builds this config several times at startup, and with 10k Synthetics
streams in one component it spent about 140s doing so before it started the
collector.

Only the global processors are needed, so convert just that field. Injecting
processors into every stream of a unit with 8000 streams drops from 8.1s to 3ms.
With 10k streams the agent now starts the collector 4s after it starts, down
from about 143s.
@botelastic botelastic Bot added the needs_team Indicates that the issue/PR needs a Team:* label label Oct 13, 2026
@botelastic

botelastic Bot commented Oct 13, 2026

Copy link
Copy Markdown

This pull request doesn't have a Team:<team> label.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)
  • /test : Run the Buildkite pipeline.

@mergify

mergify Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @shahzad31? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

@orestisfl orestisfl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thanks

Comment thread x-pack/libbeat/management/generate.go Resolved
@mergify

mergify Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@shahzad31
shahzad31 merged commit f73af48 into elastic:main Nov 9, 2026
135 checks passed
@shahzad31 shahzad31 added the backport-active-9 Automated backport with mergify to all the active 9.[0-9]+ branches label Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

@Mergifyio backport 9.6 9.5 9.4

@mergify

mergify Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

shahzad31 added a commit that referenced this pull request Nov 16, 2026
…53726) (#54587)

* management: stop converting the whole unit config for every stream

injectGlobalProcesssors called expected.GetSource().AsMap() for each stream.
The source of a unit holds all of its streams, so converting it for every
stream made building the inputs of a unit quadratic in its stream count. Elastic
Agent builds this config several times at startup, and with 10k Synthetics
streams in one component it spent about 140s doing so before it started the
collector.

Only the global processors are needed, so convert just that field. Injecting
processors into every stream of a unit with 8000 streams drops from 8.1s to 3ms.
With 10k streams the agent now starts the collector 4s after it starts, down
from about 143s.

* Address review: drop comment, use b.Loop in benchmark

(cherry picked from commit f73af48)

Co-authored-by: Shahzad <shahzad31comp@gmail.com>
shahzad31 added a commit that referenced this pull request Nov 16, 2026
…53726) (#54589)

* management: stop converting the whole unit config for every stream

injectGlobalProcesssors called expected.GetSource().AsMap() for each stream.
The source of a unit holds all of its streams, so converting it for every
stream made building the inputs of a unit quadratic in its stream count. Elastic
Agent builds this config several times at startup, and with 10k Synthetics
streams in one component it spent about 140s doing so before it started the
collector.

Only the global processors are needed, so convert just that field. Injecting
processors into every stream of a unit with 8000 streams drops from 8.1s to 3ms.
With 10k streams the agent now starts the collector 4s after it starts, down
from about 143s.

* Address review: drop comment, use b.Loop in benchmark

(cherry picked from commit f73af48)

Co-authored-by: Shahzad <shahzad31comp@gmail.com>
shahzad31 added a commit that referenced this pull request Nov 16, 2026
…53726) (#54588)

* management: stop converting the whole unit config for every stream

injectGlobalProcesssors called expected.GetSource().AsMap() for each stream.
The source of a unit holds all of its streams, so converting it for every
stream made building the inputs of a unit quadratic in its stream count. Elastic
Agent builds this config several times at startup, and with 10k Synthetics
streams in one component it spent about 140s doing so before it started the
collector.

Only the global processors are needed, so convert just that field. Injecting
processors into every stream of a unit with 8000 streams drops from 8.1s to 3ms.
With 10k streams the agent now starts the collector 4s after it starts, down
from about 143s.

* Address review: drop comment, use b.Loop in benchmark

(cherry picked from commit f73af48)

Co-authored-by: Shahzad <shahzad31comp@gmail.com>
@shahzad31
shahzad31 deleted the shahzad/management-global-processors-perf branch November 16, 2026 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-active-9 Automated backport with mergify to all the active 9.[0-9]+ branches Heartbeat needs_team Indicates that the issue/PR needs a Team:* label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[OTel] Building receiver inputs is quadratic in the number of streams of a unit

2 participants