Skip to content

Commit dbea0ef

Browse files
committed
docs: add api docs for apiRequestTime and apiRequestSize (#499)
1 parent fb0df7d commit dbea0ef

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
@@ -536,41 +536,46 @@ Specify the maximum number of spans to capture within a request transaction
536536
before dropping further spans.
537537
Setting to `-1` means that spans will never be dropped.
538538

539-
[[flush-interval]]
540-
===== `flushInterval`
539+
[[api-request-time]]
540+
===== `apiRequestTime`
541541

542542
* *Type:* Number
543543
* *Default:* `10`
544-
* *Env:* `ELASTIC_APM_FLUSH_INTERVAL`
544+
* *Env:* `ELASTIC_APM_API_REQUEST_TIME`
545545

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

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

553-
Lowering this interval can reduce memory usage on Node.js applications with a high number of transactions.
554-
555554
[NOTE]
556555
====
557-
The queue is flushed approximately 5 seconds after the first transaction has ended on a newly started Node process.
558-
559-
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.
560-
From there on the `flushInterval` option is used.
556+
The HTTP request is ended before the time threshold is reached if enough bytes are sent over it.
557+
Use the <<api-request-size,`apiRequestSize`>> config option to control the byte threshold.
561558
====
562559

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

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

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

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

576581
[[server-timeout]]
@@ -580,22 +585,11 @@ This all helps to ensure that multiple servers started at the same time will not
580585
* *Default:* `30`
581586
* *Env:* `ELASTIC_APM_SERVER_TIMEOUT`
582587

583-
Specify the timeout in seconds when reporting transactions to APM Server.
584-
585-
[[max-queue-size]]
586-
===== `maxQueueSize`
587-
588-
* *Type:* Number
589-
* *Default:* `100`
590-
* *Env:* `ELASTIC_APM_MAX_QUEUE_SIZE`
591-
592-
The agent maintains an in-memory queue to which recorded transactions are added when they end.
593-
The queue is flushed with regular intervals controlled by the <<flush-interval,`flushInterval`>> config option.
594-
595-
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.
588+
Specify the response timeout in seconds when reporting transactions to APM Server.
596589

597-
Set to `-1` to disable,
598-
in which case only `flushInterval` counts.
590+
The timeout is applied once the agent have sent the entire request body to the APM Server.
591+
If the response from the server takes longer than allowed by this timeout,
592+
the HTTP request is terminated and the TCP socket closed.
599593

600594
[[filter-http-headers]]
601595
===== `filterHttpHeaders`
@@ -1151,11 +1145,12 @@ apm.flush(function (err) {
11511145
})
11521146
----
11531147

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

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

11601155
[[apm-lambda]]
11611156
==== `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)