Skip to content

Commit 9cd73d3

Browse files
author
Stephen Belanger
committed
doc: add performance tuning doc
1 parent 12cceb5 commit 9cd73d3

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

docs/performance.asciidoc

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
[[performance]]
2+
3+
ifdef::env-github[]
4+
NOTE: For the best reading experience,
5+
please view this documentation at https://www.elastic.co/guide/en/apm/agent/nodejs/current/performance.html[elastic.co]
6+
endif::[]
7+
8+
== Performance Tuning
9+
10+
There are four major categories to consider when tuning agent performance: cpu time, memory, storage, and bandwidth. Each setting will impact one or many of these categories.
11+
12+
[float]
13+
[[performance-sampling]]
14+
=== Sampling
15+
16+
The first knob to reach for when tuning the performance of the agent is `transactionSampleRate`.
17+
Adjusting the sampling rate controls what percent of requests are traced.
18+
By default, the sample rate is set at `1.0`, meaning _all_ requests are traced.
19+
20+
The sample rate will impact all four performance categories, so simply turning down the sample rate is an easy way to improve performance.
21+
22+
[source,js]
23+
----
24+
var apm = require('elastic-apm-node').start({
25+
transactionSampleRate: 0.2
26+
})
27+
----
28+
29+
[float]
30+
[[performance-stack-traces]]
31+
=== Stack Traces
32+
33+
Stack traces can be a significant contributor to memory usage, so there are several settings to adjust how they are used.
34+
35+
==== Span Stack Traces
36+
37+
In a complex application, a request may produce many spans, so capturing a stack trace for every span can result in significant memory usage.
38+
To disable capturing stack traces for spans, set `captureSpanStackTraces` to `false`.
39+
40+
This will mainly impact memory usage, but may also have a noticeable impact on speed too.
41+
The cpu time required to capture and convert a stack frame to something JavaScript can understand is not insignificant.
42+
43+
==== Stack Frame Limit
44+
45+
The `stackTraceLimit` controls how many stack frames should be captured when producing an `Error` instance of any kind.
46+
47+
This will mainly impact memory usage, but may also have a noticeable impact on speed too.
48+
The cpu time required to capture and convert a stack frame to something JavaScript can understand is not insignificant.
49+
50+
==== Error Log Stack Traces
51+
52+
Most stack traces recorded by the agent will point to where the error was instantiated, not where it was identified and reported to the agent with <<apm-capture-error,`captureError`>>.
53+
For this reason, the agent also has a feature to enable capturing an additional stack trace pointing to the place an error was reported to the agent.
54+
By default, it will only capture the stack trace to the reporting point when <<apm-capture-error,`captureError`>> is called with a string message.
55+
56+
==== Unhandled Exceptions
57+
58+
By default, the agent will record any unhandled exceptions that occur within the application.
59+
60+
[float]
61+
[[performance-source-lines]]
62+
=== Source Lines
63+
64+
The most important settings to look at are the source line settings.
65+
When a stack trace is captured, the agent will also capture several lines of source code around each stack frame location in the stack trace.
66+
The are four different settings to control this behaviour: `sourceLinesErrorAppFrames`, `sourceLinesErrorLibraryFrames`, `sourceLinesSpanAppFrames`, and `sourceLinesSpanLibraryFrames`.
67+
68+
Source line settings are divided into app frames representing your app code and library frames representing the code of your dependencies.
69+
App and library categories are both split into error and span groups.
70+
Spans, by default, do not capture source lines.
71+
Errors will, by default, capture five lines of code around each stack frame.
72+
73+
Source lines are cached in-process.
74+
If your app produces many errors from many different places the source line cache may be larger than desired, in memory-constrained environments.
75+
You can try turning down the number of error source lines, if your memory usage is higher than you think it should be.

0 commit comments

Comments
 (0)