|
| 1 | +[[tuning-and-overhead]] |
| 2 | +== Tuning and Overhead considerations |
| 3 | + |
| 4 | +Using an APM solution comes with certain trade-offs, and the Python agent for Elastic APM is no different. |
| 5 | +Instrumenting your code, measuring timings, recording context data etc. all need resources: |
| 6 | + |
| 7 | + * CPU time |
| 8 | + * memory |
| 9 | + * bandwidth use |
| 10 | + * Elasticsearch storage |
| 11 | + |
| 12 | +We invested and continue to invest a lot of effort to keep the overhead of using Elastic APM as low as possible. |
| 13 | +But because every deployment is different, there are some knobs you can turn to adapt it to your specific needs. |
| 14 | + |
| 15 | +[float] |
| 16 | +[[tuning-sample-rate]] |
| 17 | +=== Transaction Sample Rate |
| 18 | + |
| 19 | +The most straight forward way to reduce the overhead of the agent is to tell the agent to do less. |
| 20 | +If you set the <<config-transaction-sample-rate,`transaction_sample_rate`>> to a value below `1.0`, |
| 21 | +the agent will randomly sample only a subset of transactions. |
| 22 | +If a transaction is not sampled, the agent has to do a lot less work, |
| 23 | +as we only record the the name of the transaction, the overall transaction time and the result for unsampled transactions. |
| 24 | + |
| 25 | +[options="header"] |
| 26 | +|============ |
| 27 | +| Field | Sampled | Unsampled |
| 28 | +| Transaction name | yes | yes |
| 29 | +| Duration | yes | yes |
| 30 | +| Result | yes | yes |
| 31 | +| Context | yes | no |
| 32 | +| Tags | yes | no |
| 33 | +| Spans | yes | no |
| 34 | +|============ |
| 35 | + |
| 36 | +Reducing the sample rate to a fraction of all transactions can make a huge difference in all four of the mentioned resource types. |
| 37 | + |
| 38 | +[float] |
| 39 | +[[tuning-queue]] |
| 40 | +=== Transaction Queue |
| 41 | + |
| 42 | +To reduce the load on the APM Server, the agent does not send every transaction up as it happens. |
| 43 | +Instead, it queues them up, and flushes the queue periodically, or when it reaches a maximum size, using a background thread. |
| 44 | + |
| 45 | +While this reduces the load on the APM Server (and to a certain extent on the agent), |
| 46 | +holding on to the transaction data in a queue uses memory. |
| 47 | +If you notice that using the Python agent results in a large increase of memory use, |
| 48 | +you can use these settings: |
| 49 | + |
| 50 | + * <<config-flush-interval,`flush_interval`>> to reduce the time between queue flushes |
| 51 | + * <<config-max-queue-size,`max_queue_size`>> to reduce the maximum size of the queue |
| 52 | + |
| 53 | +The first setting, `flush_interval`, is helpful if you have a sustained high number of transactions. |
| 54 | +The second setting, `max_queue_size`, can help if you experience peaks of transactions |
| 55 | +(a large amount of transactions in a short period of time). |
| 56 | + |
| 57 | +Keep in mind that reducing the value of either setting will cause the agent to send more HTTP requests to the APM Server, |
| 58 | +potentially causing a higher load. |
| 59 | + |
| 60 | + |
| 61 | +[float] |
| 62 | +[[tuning-max-spans]] |
| 63 | +=== Spans per transaction |
| 64 | + |
| 65 | +The average amount of spans per transaction can influence how much time the agent spends in each transaction collecting contextual data for each span, |
| 66 | +and the the storage space needed in Elasticsearch. |
| 67 | +In our experience, most usual transactions should have well below 100 spans. |
| 68 | +In some cases however, the number of spans can explode: |
| 69 | + |
| 70 | + * long-running transactions |
| 71 | + * unoptimized code, e.g. doing hundreds of SQL queries in a loop |
| 72 | + |
| 73 | +To avoid that such edge cases overload both the agent and the APM Server, |
| 74 | +the agent stops recording spans when a limit is reached. |
| 75 | +You can configure this limit by changing the <<config-transaction-max-spans,`transaction_max_spans`>> setting. |
0 commit comments