# Java APM Agent causes CPU spikes

**URL:** <https://discuss.elastic.co/t/java-apm-agent-causes-cpu-spikes/261215>\
**Category:** APM\
**Tags:** java\
**Created:** [January 15, 2021, 7:40am UTC](https://discuss.elastic.co/t/java-apm-agent-causes-cpu-spikes/261215 "2021-01-15T07:40:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbking](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bbking/32/77563_2.png) [@bbking](https://discuss.elastic.co/u/bbking)\
**Post date:** [January 15, 2021, 7:40am UTC](https://discuss.elastic.co/t/java-apm-agent-causes-cpu-spikes/261215/1 "2021-01-15T07:40:41Z")

</div>

Hi, I set up a java APM agent with Tomcat in production, but the agent caused CPU spikes and during that time, memory usage was normal but GC almost dropped to zero. We didn't have a heap dump but the gc log shows that during the CPU spikes, there were lots of safepoints related to `ICBufferFull`. Does anyone have any ideas what might cause it?

**OS version** : CentOS Linux, Version 7(core)  
**Java Version** : openjdk version "11.0.9.1"  
**APM java agent version** : 1.19.0

**APM java agent configuration**  
The APM agent is setup with the Tomcat process with `-javaagent` flag

```auto
/java/1.8.0_275/bin/java -javaagent:elastic-apm-agent-1.19.0.jar -Delastic.apm

```

GC log:

```auto
log/gc.log.4:[2021-01-14T09:45:58.880-0800][1610646358880ms][info][safepoint] Application time: 0.0213354 seconds
log/gc.log.4:[2021-01-14T09:45:58.881-0800][1610646358881ms][info][safepoint] Entering safepoint region: RevokeBias
log/gc.log.4:[2021-01-14T09:45:58.882-0800][1610646358882ms][info][safepoint] Leaving safepoint region
log/gc.log.4:[2021-01-14T09:45:58.882-0800][1610646358882ms][info][safepoint] Total time for which application threads were stopped: 0.0025448 seconds, Stopping threads took: 0.0010856 seconds
log/gc.log.4:[2021-01-14T09:45:59.028-0800][1610646359028ms][info][safepoint] Application time: 0.1453296 seconds
log/gc.log.4:[2021-01-14T09:45:59.030-0800][1610646359030ms][info][safepoint] Entering safepoint region: ICBufferFull
log/gc.log.4:[2021-01-14T09:45:59.031-0800][1610646359031ms][info][safepoint] Leaving safepoint region
log/gc.log.4:[2021-01-14T09:45:59.031-0800][1610646359031ms][info][safepoint] Total time for which application threads were stopped: 0.0036981 seconds, Stopping threads took: 0.0021553 seconds

```

APM agent config:

```auto
recording=true
transaction_sample_rate=0.5
max_queue_size=512
use_path_as_transaction_name=true
ignore_exceptions=java.net.SocketException
transaction_ignore_urls=*.js,*.css,*.jpg,*.jpeg,*.png,*.gif,*.svg
capture_headers=false
capture_body=off
metrics_interval=15s
transaction_max_spans=800
span_min_duration=10ms
profiling_inferred_spans_min_duration=10ms
profiling_inferred_spans_sampling_interval=5ms
profiling_inferred_spans_enabled=true
disable_instrumentations=kafka
async_profiler_safe_mode=16
log_file_size=50mb

```

Server Metrics:

 ![Screen Shot 2021-01-14 at 11.31.59 PM](https://us1.discourse-cdn.com/elastic/original/3X/c/1/c1685c71cc2fdb84de20c37608820c655ef25bd8.png)

---

<div class="post-metadata">

**Author:** ![Sylvain\_Juge](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sylvain_juge/32/55521_2.png) [@Sylvain\_Juge](https://discuss.elastic.co/u/Sylvain_Juge)\
**Post date:** [January 15, 2021, 8:10am UTC](https://discuss.elastic.co/t/java-apm-agent-causes-cpu-spikes/261215/2 "2021-01-15T08:10:23Z")

</div>

Hi @bbking,

So far, we haven't had any reports about the safepoint behavior that you describe, did you checked that it does not happen when the agent is disabled ? For example, how many occurrences of `ICBufferFull` do you get in a day with and without the agent ?

We updated the profiler (async-profiler) in the last release, thus I would suggest to update to `1.20.0` version to see if that still appears with this version.

Also, do you have a particular reason to use `safe_mode=16` ? Unless you explicitly had issues in the past it should not be set unless debugging or work-around against known issues.

---

<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:** [February 5, 2021, 4:10am UTC](https://discuss.elastic.co/t/java-apm-agent-causes-cpu-spikes/261215/3 "2021-02-05T04:10:28Z")

</div>

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