Calculate Median Memory Allocation

Calculate the median (50th percentile) of memory allocations using the percentile() function

Query

flowchart LR; %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% repo{{Events}} 1{{Aggregate}} result{{Result Set}} repo --> 1 1 --> result
logscale
percentile(field=allocBytes, percentiles=[50], as=median)

Introduction

The percentile() can be used to calculate the median value of a numeric field by specifying the 50th percentile, providing a measure of central tendency that is less sensitive to outliers than the mean.

In this example, the percentile() function is used to calculate the median of memory allocations by setting the 50th percentile and specifying a custom output field name.

Example incoming data might look like this:

@timestampprocess_nameallocBytesthread_id
2023-06-15T10:00:00Zjava_app1024000thread-1
2023-06-15T10:00:01Zjava_app1548000thread-2
2023-06-15T10:00:02Zjava_app982000thread-1
2023-06-15T10:00:03Zjava_app2048000thread-3
2023-06-15T10:00:04Zjava_app1126000thread-2
2023-06-15T10:00:05Zjava_app1256000thread-1
2023-06-15T10:00:06Zjava_app1648000thread-3
2023-06-15T10:00:07Zjava_app3072000thread-2
2023-06-15T10:00:08Zjava_app1324000thread-1
2023-06-15T10:00:09Zjava_app1420000thread-3

Step-by-Step

  1. Starting with the source repository events.

  2. flowchart LR; %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% repo{{Events}} 1{{Aggregate}} result{{Result Set}} repo --> 1 1 --> result style 1 fill:#ff0000,stroke-width:4px,stroke:#000;
    logscale
    percentile(field=allocBytes, percentiles=[50], as=median)

    Calculates the median (50th percentile) of the allocBytes field and returns the result in a new field named median_50 (the _50 suffix is automatically added).

  3. Event Result set.

Summary and Results

The query is used to find the middle value (median) of memory allocations, providing a representative measure of typical allocation size.

This query is useful, for example, to monitor typical memory usage patterns, establish baseline memory requirements, or detect changes in memory allocation behavior.

Sample output from the incoming example data:

median_50
1420000

Note that the output field is automatically named median_50, combining the specified name with the percentile value.