# Induced CPU load by APM nodejs agent if elastic server saturates

**URL:** <https://discuss.elastic.co/t/induced-cpu-load-by-apm-nodejs-agent-if-elastic-server-saturates/272729>\
**Category:** APM\
**Tags:** nodejs\
**Created:** [May 11, 2021, 4:51pm UTC](https://discuss.elastic.co/t/induced-cpu-load-by-apm-nodejs-agent-if-elastic-server-saturates/272729 "2021-05-11T16:51:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Javier\_Aracil](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javier_aracil/32/87086_2.png) [@Javier\_Aracil](https://discuss.elastic.co/u/Javier_Aracil)\
**Post date:** [May 11, 2021, 4:51pm UTC](https://discuss.elastic.co/t/induced-cpu-load-by-apm-nodejs-agent-if-elastic-server-saturates/272729/1 "2021-05-11T16:51:02Z")

</div>

Hi All,

We are instrumenting a nodejs backend with Elastic APM agent. At some point, the elastic server cannot cope with the incoming messages from the agent. I wonder what happens in that case. I understand that such incoming messages will be dropped, and the backend CPU load will not be affected because of this.

Generally speaking, what CPU load can the agent induce in the backend?

Thanks very much,

Javier

---

<div class="post-metadata">

**Author:** ![trentm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/trentm/32/77647_2.png) [@trentm](https://discuss.elastic.co/u/trentm)\
**Post date:** [May 11, 2021, 5:47pm UTC](https://discuss.elastic.co/t/induced-cpu-load-by-apm-nodejs-agent-if-elastic-server-saturates/272729/2 "2021-05-11T17:47:06Z")

</div>

Hello Javier,

Thanks for the question. I'm assuming by "elastic server" here you mean the APM server (i.e. [Configuration options | APM Node.js Agent Reference [4.x] | Elastic](https://www.elastic.co/guide/en/apm/agent/nodejs/current/configuration.html#server-url)) to which the APM agent sends event data.

The first important thing to note is that how the Node.js APM agent copes with an overloaded or non-responding APM server was significantly changed in v3.14.0 of the agent ([Node.js Agent version 3.x | APM Node.js Agent Reference [4.x] | Elastic](https://www.elastic.co/guide/en/apm/agent/nodejs/current/release-notes-3.x.html#release-notes-3.14.0)).

> [@Javier\_Aracil](#):
>
> I understand that such incoming messages will be dropped, and the backend CPU load will not be affected because of this.

That is correct (at least with v3.14.0). The APM agent will buffer up to 1024 ([Configuration options | APM Node.js Agent Reference [4.x] | Elastic](https://www.elastic.co/guide/en/apm/agent/nodejs/current/configuration.html#max-queue-size)) events and start dropping events if the APM server won't receive them fast enough.

> [@Javier\_Aracil](#):
>
> Generally speaking, what CPU load can the agent induce in the backend?

That is a hard question to quantify in general. Often it depends a lot on the application being instrumented. Some disorganized thoughts:

- The `async_hooks` mechanism that the agent uses does definitely have some overhead on the application. From recent anecdotal observations, if the application is _very_ heavy on async operations (lots of timers, nextTick, setImmediate, and especially Promise usage), that overhead can be higher.
- If you are experiencing too-high CPU overhead from the agent, my first suggestions would be to consider setting `transactionSampleRate` ([Configuration options | APM Node.js Agent Reference [master] | Elastic](https://www.elastic.co/guide/en/apm/agent/nodejs/master/configuration.html#transaction-sample-rate)) to a value less than 1, and `captureSpanStackTraces=false` ([Configuration options | APM Node.js Agent Reference [master] | Elastic](https://www.elastic.co/guide/en/apm/agent/nodejs/master/configuration.html#capture-span-stack-traces)). If the application produces lots of spans, the latter can help a lot. Coming versions of the agent will have some improvements on stacktrace collection overhead and will probably change default settings to not capture stacktraces for all spans (likely just for slower ones).
- Otherwise working through [Performance Tuning | APM Node.js Agent Reference [master] | Elastic](https://www.elastic.co/guide/en/apm/agent/nodejs/master/performance-tuning.html) can help.

I hope that helps answer your question.

Cheers,  
Trent

---

<div class="post-metadata">

**Author:** ![Javier\_Aracil](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javier_aracil/32/87086_2.png) [@Javier\_Aracil](https://discuss.elastic.co/u/Javier_Aracil)\
**Post date:** [May 11, 2021, 5:53pm UTC](https://discuss.elastic.co/t/induced-cpu-load-by-apm-nodejs-agent-if-elastic-server-saturates/272729/3 "2021-05-11T17:53:23Z")

</div>

Thanks Trent, yes, APM server. We will proceed as suggested, best

Javier

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 1, 2021, 1:53pm UTC](https://discuss.elastic.co/t/induced-cpu-load-by-apm-nodejs-agent-if-elastic-server-saturates/272729/4 "2021-06-01T13:53:57Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
