Skip to content

Commit 8fba075

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

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

docs/performance.asciidoc

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
[float]
9+
[[performance-tuning]]
10+
== Performance Tuning
11+
12+
There are many options available to tune agent performance.
13+
Which option to adjust depends on whether you are optimizing for speed, memory usage, bandwidth or storage.
14+
15+
[float]
16+
[[performance-sampling]]
17+
=== Sampling
18+
19+
The first knob to reach for when tuning the performance of the agent is <<transaction-sample-rate,`transactionSampleRate`>>.
20+
Adjusting the sampling rate controls what percent of requests are traced.
21+
By default, the sample rate is set at `1.0`, meaning _all_ requests are traced.
22+
23+
The sample rate will impact all four performance categories, so simply turning down the sample rate is an easy way to improve performance.
24+
25+
[source,js]
26+
----
27+
var apm = require('elastic-apm-node').start({
28+
transactionSampleRate: 0.2
29+
})
30+
----
31+
32+
[float]
33+
[[performance-stack-traces]]
34+
=== Stack Traces
35+
36+
Stack traces can be a significant contributor to memory usage. There are several settings to adjust how they are used.
37+
38+
[float]
39+
[[performance-span-stack-traces]]
40+
==== Span Stack Traces
41+
42+
In a complex application, a request may produce many spans.
43+
Capturing a stack trace for every span can result in significant memory usage.
44+
To disable capturing stack traces for spans, set <<capture-span-stack-traces,`captureSpanStackTraces`>> to `false`.
45+
46+
This will mainly impact memory usage, but may also have a noticeable impact on speed too.
47+
The cpu time required to capture and convert a stack frame to something JavaScript can understand is not insignificant.
48+
49+
[float]
50+
[[performance-source-lines]]
51+
=== Source Lines
52+
53+
If you want to keep span stack traces enabled for context, the next thing to try is adjusting how many source lines are reported for each stack trace.
54+
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.
55+
56+
The are four different settings to control this behaviour:
57+
- <<source-context-error-app-frames,`sourceLinesErrorAppFrames`>>
58+
- <<source-context-error-library-frames,`sourceLinesErrorLibraryFrames`>>
59+
- <<source-context-span-app-frames,`sourceLinesSpanAppFrames`>>
60+
- <<source-context-span-library-frames,`sourceLinesSpanLibraryFrames`>>
61+
62+
Source line settings are divided into app frames representing your app code and library frames representing the code of your dependencies.
63+
App and library categories are both split into error and span groups.
64+
Spans, by default, do not capture source lines.
65+
Errors, by default, will capture five lines of code around each stack frame.
66+
67+
Source lines are cached in-process.
68+
In memory-constrained environments, the source line cache may use more memory than desired.
69+
Turning the limits down will help prevent excessive memory use
70+
71+
[float]
72+
[[performance-stack-frame-limit]]
73+
==== Stack Frame Limit
74+
75+
The <<stack-trace-limit,`stackTraceLimit`>> controls how many stack frames should be captured when producing an `Error` instance of any kind.
76+
77+
This will mainly impact memory usage, but may also have a noticeable impact on speed too.
78+
The cpu time required to capture and convert a stack frame to something JavaScript can understand is not insignificant.
79+
80+
[float]
81+
[[performance-error-log-stack-traces]]
82+
==== Error Log Stack Traces
83+
84+
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`>>.
85+
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.
86+
By default, it will only capture the stack trace to the reporting point when <<apm-capture-error,`captureError`>> is called with a string message.

0 commit comments

Comments
 (0)