Skip to content

Commit 3836ec4

Browse files
committed
docs: add api docs for apiRequestTime and apiRequestSize (elastic#499)
1 parent 5e164cb commit 3836ec4

File tree

5 files changed

+75
-75
lines changed

5 files changed

+75
-75
lines changed

docs/agent-api.asciidoc

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -539,41 +539,46 @@ Specify the maximum number of spans to capture within a request transaction
539539
before dropping further spans.
540540
Setting to `-1` means that spans will never be dropped.
541541

542-
[[flush-interval]]
543-
===== `flushInterval`
542+
[[api-request-time]]
543+
===== `apiRequestTime`
544544

545545
* *Type:* Number
546546
* *Default:* `10`
547-
* *Env:* `ELASTIC_APM_FLUSH_INTERVAL`
547+
* *Env:* `ELASTIC_APM_API_REQUEST_TIME`
548548

549-
The agent maintains an in-memory queue to which recorded transactions are added when they end.
550-
Unless empty,
551-
this queue is flushed and sent to the APM Server for processing approximately every 10 seconds.
549+
The agent maintains an open HTTP request to the APM Server that is used to transmit the collected transactions,
550+
spans,
551+
and errors to the server.
552552

553-
Use this option to change that interval.
553+
To avoid issues with intermittent proxies and load balancers,
554+
the HTTP request is ended and a new one created at regular intervals controlled by this config option.
554555
The value is expected to be in seconds.
555556

556-
Lowering this interval can reduce memory usage on Node.js applications with a high number of transactions.
557-
558557
[NOTE]
559558
====
560-
The queue is flushed approximately 5 seconds after the first transaction has ended on a newly started Node process.
561-
562-
This ensures that you don't have to wait for the entire `flushInterval` to pass for the first data to be sent to the APM Server.
563-
From there on the `flushInterval` option is used.
559+
The HTTP request is ended before the time threshold is reached if enough bytes are sent over it.
560+
Use the <<api-request-size,`apiRequestSize`>> config option to control the byte threshold.
564561
====
565562

566-
[NOTE]
567-
====
568-
After each flush of the queue,
569-
the next flush isn't scheduled until a transaction have ended.
563+
[[api-request-size]]
564+
===== `apiRequestSize`
570565

571-
This is done to introduce variance and also ensures that empty queues are not scheduled for flushing.
566+
* *Type:* Number
567+
* *Default:* `1048576` (1 MiB)
568+
* *Env:* `ELASTIC_APM_API_REQUEST_SIZE`
569+
570+
The agent maintains an open HTTP request to the APM Server that is used to transmit the collected transactions,
571+
spans,
572+
and errors to the server.
572573

573-
On top of that,
574-
the actual interval is adjusted by +/- 5% between each flush.
574+
To avoid issues with intermittent proxies and load balancers,
575+
the HTTP request is ended and a new one created if its body becomes too large.
576+
That limit is controlled by this config option.
577+
The value is expected to be in bytes.
575578

576-
This all helps to ensure that multiple servers started at the same time will not establish connections to the APM Server simultaneously.
579+
[NOTE]
580+
====
581+
The HTTP request is otherwise ended at regular intervals controlled by the <<api-request-time,`apiRequestTime`>> config option.
577582
====
578583

579584
[[server-timeout]]
@@ -583,22 +588,11 @@ This all helps to ensure that multiple servers started at the same time will not
583588
* *Default:* `30`
584589
* *Env:* `ELASTIC_APM_SERVER_TIMEOUT`
585590

586-
Specify the timeout in seconds when reporting transactions to APM Server.
587-
588-
[[max-queue-size]]
589-
===== `maxQueueSize`
590-
591-
* *Type:* Number
592-
* *Default:* `100`
593-
* *Env:* `ELASTIC_APM_MAX_QUEUE_SIZE`
594-
595-
The agent maintains an in-memory queue to which recorded transactions are added when they end.
596-
The queue is flushed with regular intervals controlled by the <<flush-interval,`flushInterval`>> config option.
597-
598-
Use the `maxQueueSize` option to force a flush of the queue when it reaches a certain size (number of ended transactions) - even if the `flushInterval` time isn't reached yet.
591+
Specify the response timeout in seconds when reporting transactions to APM Server.
599592

600-
Set to `-1` to disable,
601-
in which case only `flushInterval` counts.
593+
The timeout is applied once the agent have sent the entire request body to the APM Server.
594+
If the response from the server takes longer than allowed by this timeout,
595+
the HTTP request is terminated and the TCP socket closed.
602596

603597
[[filter-http-headers]]
604598
===== `filterHttpHeaders`
@@ -1156,11 +1150,12 @@ apm.flush(function (err) {
11561150
})
11571151
----
11581152

1159-
Manually flush the in-memory transaction queue and send all the transactions to the APM Server.
1160-
The queue is otherwise flushed automatically,
1161-
controlled by the <<flush-interval,`flushInterval`>> and/or <<max-queue-size,`maxQueueSize`>> config options.
1153+
Manually end the active outgoing HTTP request to the APM Server.
1154+
The HTTP request is otherwise ended automatically at regular intervals,
1155+
controlled by the <<api-request-time,`apiRequestTime`>> and <<api-request-size,`apiRequestSize`>> config options.
11621156

1163-
The callback is called *after* the event has been sent to the APM Server with a possible error argument.
1157+
The callback is called *after* the active HTTP request have ended.
1158+
The callback is called even if no HTTP request is currently active.
11641159

11651160
[[apm-lambda]]
11661161
==== `apm.lambda([type, ] handler)`

docs/performance-tuning.asciidoc

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,42 +36,58 @@ require('elastic-apm-node').start({
3636
----
3737

3838
[float]
39-
[[performance-transaction-queue]]
40-
=== Transaction Queue
39+
[[performance-apm-server-communication]]
40+
=== APM Server communication
4141

42-
The agent buffers the collected data using an in-memory queue before sending it to the APM Server.
43-
The queue is flushed either after a specific <<performance-flush-interval,amount of time>> or when it reaches <<performance-max-queue-size,a certain size>> -
44-
whichever comes first.
45-
Lowering these defaults can reduce memory usage,
46-
but will increase the number of requests to the APM Server.
42+
The agent uses a persistent outgoing HTTP request to stream data to the APM Server.
43+
To avoid issues with intermittent proxies and load balancers,
44+
the HTTP request is ended and a new one created at regular intervals or when the size of the request becomes too big.
45+
46+
There's an overhead involved in each HTTP request:
47+
Besides sending new HTTP headers,
48+
the agent needs to re-send certain metadata to the APM Server each time a new HTTP request is made.
49+
However,
50+
if allowed by the network,
51+
the TCP socket is reused between each HTTP request.
4752

4853
[float]
49-
[[performance-flush-interval]]
50-
==== Flush Interval
54+
[[performance-api-request-time]]
55+
==== Max HTTP request duration
5156

52-
To prevent items from staying in the queue for a long time during low activity,
53-
the <<flush-interval,`flushInterval`>> setting is used to ensure the queue empties if anything in it is too old.
57+
By default an HTTP request to the APM Server is ended after a maximum of 10 seconds.
58+
Using the <<api-request-time,`apiRequestTime`>> config option,
59+
this time limit can be modified.
5460

55-
Lowering the flush interval will ensure transactions are sent to the APM Server faster,
56-
but may also result in increased HTTP traffic and CPU usage.
61+
Lowering the time limit might be necessary if dealing with very agressive proxies,
62+
but increasing the time limit means that the combined overhead of these HTTP requests is reduced,
63+
as headers and metadata doesn't need to be re-sent that often.
5764

5865
[float]
59-
[[performance-max-queue-size]]
60-
==== Max Queue Size
66+
[[performance-api-request-size]]
67+
==== Max HTTP request size
6168

62-
The <<max-queue-size,`maxQueueSize`>> controls the maximum number of transactions that may remain in the queue before they must be sent.
69+
By default an HTTP request to the APM Server is ended after approximately 1 MiB of gzip compressed data have been written to the body.
70+
Using the <<api-request-size,`apiRequestSize`>> config option,
71+
this time limit can be modified.
6372

64-
Lowering this will reduce memory consumption,
65-
however it will increase the number of requests made to the APM Server.
73+
Lowering the size limit might be necessary if dealing with very agressive proxies,
74+
but increasing the size limit means that the combined overhead of these HTTP requests is reduced,
75+
as headers and metadata doesn't need to be re-sent that often.
6676

6777
[float]
6878
[[performance-server-timeout]]
69-
=== APM Server Timeout
79+
==== APM Server Timeout
80+
81+
In the event that the APM Server or the connection to the APM Server is slow or unstable,
82+
the <<server-timeout,`serverTimeout`>> setting can be set to ensure the agent doesn't wait too long for a response.
83+
84+
The agent only allows for a single TCP socket to be opened to the APM Server at any given time.
85+
This is to avoid the overhead of opening too many sockets.
86+
If the agent is stuck waiting for a response from the previous HTTP request,
87+
it might start dropping new data in order to keep its memory footprint low.
7088

71-
In the event that the connection to the APM Server is slow or unstable,
72-
the <<server-timeout,`serverTimeout`>> setting can be set to ensure connections don't stay open too long.
73-
If the server timeout is too high,
74-
it may result in too many socket descriptors being held open.
89+
Keeping this timeout low,
90+
helps alleviate that problem.
7591

7692
[float]
7793
[[performance-stack-traces]]

lib/config.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@ var DEFAULTS = {
5151
sourceLinesSpanAppFrames: 0,
5252
sourceLinesSpanLibraryFrames: 0,
5353
errorMessageMaxLength: 2048,
54-
flushInterval: 10, // TODO: Deprecate
5554
transactionMaxSpans: 500,
5655
transactionSampleRate: 1.0,
57-
maxQueueSize: 100, // TODO: Deprecate
5856
serverTimeout: 30,
5957
disableInstrumentations: []
6058
}
@@ -81,8 +79,6 @@ var ENV_TABLE = {
8179
errorOnAbortedRequests: 'ELASTIC_APM_ERROR_ON_ABORTED_REQUESTS',
8280
abortedErrorThreshold: 'ELASTIC_APM_ABORTED_ERROR_THRESHOLD',
8381
instrument: 'ELASTIC_APM_INSTRUMENT',
84-
flushInterval: 'ELASTIC_APM_FLUSH_INTERVAL',
85-
maxQueueSize: 'ELASTIC_APM_MAX_QUEUE_SIZE',
8682
asyncHooks: 'ELASTIC_APM_ASYNC_HOOKS',
8783
sourceLinesErrorAppFrames: 'ELASTIC_APM_SOURCE_LINES_ERROR_APP_FRAMES',
8884
sourceLinesErrorLibraryFrames: 'ELASTIC_APM_SOURCE_LINES_ERROR_LIBRARY_FRAMES',
@@ -111,8 +107,6 @@ var NUM_OPTS = [
111107
'apiRequestTime',
112108
'stackTraceLimit',
113109
'abortedErrorThreshold',
114-
'flushInterval',
115-
'maxQueueSize',
116110
'sourceLinesErrorAppFrames',
117111
'sourceLinesErrorLibraryFrames',
118112
'sourceLinesSpanAppFrames',
@@ -124,7 +118,6 @@ var NUM_OPTS = [
124118
]
125119

126120
var MINUS_ONE_EQUAL_INFINITY = [
127-
'maxQueueSize',
128121
'transactionMaxSpans'
129122
]
130123

test/config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ var optionFixtures = [
4141
['errorOnAbortedRequests', 'ERROR_ON_ABORTED_REQUESTS', false],
4242
['abortedErrorThreshold', 'ABORTED_ERROR_THRESHOLD', 25000],
4343
['instrument', 'INSTRUMENT', true],
44-
['flushInterval', 'FLUSH_INTERVAL', 10],
45-
['maxQueueSize', 'MAX_QUEUE_SIZE', 100],
4644
['asyncHooks', 'ASYNC_HOOKS', true],
4745
['sourceLinesErrorAppFrames', 'SOURCE_LINES_ERROR_APP_FRAMES', 5],
4846
['sourceLinesErrorLibraryFrames', 'SOURCE_LINES_ERROR_LIBRARY_FRAMES', 5],
@@ -160,7 +158,6 @@ truthyValues.forEach(function (val) {
160158
})
161159

162160
var MINUS_ONE_EQUAL_INFINITY = [
163-
'maxQueueSize',
164161
'transactionMaxSpans'
165162
]
166163

test/instrumentation/modules/http2.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
var agent = require('../../..').start({
44
serviceName: 'test',
5-
captureExceptions: false,
6-
maxQueueSize: 0
5+
captureExceptions: false
76
})
87
var ins = agent._instrumentation
98

0 commit comments

Comments
 (0)