Class PercentileCalculator
java.lang.Object
com.nmontytskyi.monitoring.detector.PercentileCalculator
Utility class for calculating response time percentiles.
Percentile P95 = 340ms means that 95% of requests completed faster than 340ms, while 5% were slower. This is a more accurate indicator than the average, which hides "tail" latencies that affect real user experience.
Implements the Nearest Rank Method:
index = ceil(p / 100 * n) - 1 result = sortedValues[index]
This is a utility class (static methods only) and cannot be instantiated.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classImmutable container holding three response time percentiles. -
Method Summary
Modifier and TypeMethodDescriptionstatic longCalculates the given percentile for a list of response time values.calculateAll(List<Long> values) Calculates P50, P95, and P99 in a single sorting pass.static longCalculates the median (P50) — 50% of requests completed faster than this value.static longCalculates P95 — 95% of requests completed faster than this value.static longCalculates P99 — 99% of requests completed faster than this value.
-
Method Details
-
calculate
Calculates the given percentile for a list of response time values.- Parameters:
values- list of measurements in milliseconds (does not need to be sorted)percentile- target percentile from 0 to 100 inclusive- Returns:
- the percentile value;
0if the list is empty - Throws:
IllegalArgumentException- ifpercentileis outside the range [0, 100]
-
p50
-
p95
-
p99
-
calculateAll
Calculates P50, P95, and P99 in a single sorting pass. Recommended method for populatingSlaReport.- Parameters:
values- list of measurements in milliseconds- Returns:
- object containing all three percentiles; all zeros if the list is empty
-