elastic / elastic-agent

Elastic Agent - single, unified way to add monitoring for logs, metrics, and other types of data to a host.
Other
113 stars 126 forks source link

Scale Preset should prevent Thundering Herd issue with many Agents #4469

Open StephanErb opened 3 months ago

StephanErb commented 3 months ago

Describe the enhancement:

The scale preset introduced in https://github.com/elastic/kibana/issues/166870 and https://github.com/elastic/elastic-agent/issues/3797 is a great start to make agent ingestion more scalable. However, assuming one wants to ingest using thousand of agents, there is a high risk of a thundering herd problem. If Elastic starts choking the the agents reconnect and retry logic further increases the load on the cluster. This might kick the entire system over the edge.

This should be addressed with further options being tuned by the preset.

Describe a specific use case for the enhancement or feature:

The scale preset should adjust the following additional options:

What is the definition of done?

Better defaults with no actions needed by users.

### Implementation tasks
- [ ] Add a random exponential backoff to `backoff.init` and `backoff.max` so that when agents reconnect en-mass (or wait to reconnect) the connection requests are somewhat spread out. This should be the default behavior regardless of the preset.
- [ ] For the **"optimized for Scale"** preset: change the default for `backoff.init` to 5s
- [ ] For the **"optimized for Scale"** preset: change the default for`backoff.max` default to 300s
cmacknz commented 3 months ago

backoff.init and backoff.max should use a higher default and leverage a jitter. There is currently no jitter in the backoff which leads to a synchronized retry across all agents.

+1 thanks for pointing this out, we should be using pseudo-random exponential backoff, not just exponential backoff.

max_retries should be reduced for metric data sets (but not logs).

Metricbeat should already default to 3 retries, while Filebeat defaults to infinite retries. Agent doesn't modify this part of the Metricbeat configuration. https://www.elastic.co/guide/en/beats/metricbeat/current/elasticsearch-output.html#_max_retries

elasticmachine commented 3 months ago

Pinging @elastic/elastic-agent (Team:Elastic-Agent)

cmacknz commented 3 months ago

https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/ has the modifications to the backoff algorithm we should make along with their relative performance.

elasticmachine commented 1 month ago

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)