SlidingPercentileBandwidthStatistic


@UnstableApi
public class SlidingPercentileBandwidthStatistic implements BandwidthStatistic


A BandwidthStatistic that calculates estimates based on a sliding window weighted percentile.

Summary

Constants

static final int

The default maximum number of samples.

static final double

The default percentile to return.

Public constructors

Creates an instance with a maximum of DEFAULT_MAX_SAMPLES_COUNT samples, returning the DEFAULT_PERCENTILE.

SlidingPercentileBandwidthStatistic(
    int maxSampleCount,
    double percentile
)

Creates an instance.

Public methods

void
addSample(long bytes, long durationUs)

Adds a transfer sample to the statistic.

long

Returns the bandwidth estimate in bits per second, or ESTIMATE_NOT_AVAILABLE if there is no estimate available yet.

void

Resets the statistic.

Constants

DEFAULT_MAX_SAMPLES_COUNT

public static final int DEFAULT_MAX_SAMPLES_COUNT = 10

The default maximum number of samples.

DEFAULT_PERCENTILE

public static final double DEFAULT_PERCENTILE = 0.5

The default percentile to return.

Public constructors

SlidingPercentileBandwidthStatistic

public SlidingPercentileBandwidthStatistic()

Creates an instance with a maximum of DEFAULT_MAX_SAMPLES_COUNT samples, returning the DEFAULT_PERCENTILE.

SlidingPercentileBandwidthStatistic

public SlidingPercentileBandwidthStatistic(
    int maxSampleCount,
    double percentile
)

Creates an instance.

Parameters
int maxSampleCount

The maximum number of samples.

double percentile

The percentile to return. Must be in the range of [0-1].

Public methods

addSample

public void addSample(long bytes, long durationUs)

Adds a transfer sample to the statistic.

Parameters
long bytes

The number of bytes transferred.

long durationUs

The duration of the transfer, in microseconds.

getBandwidthEstimate

public long getBandwidthEstimate()

Returns the bandwidth estimate in bits per second, or ESTIMATE_NOT_AVAILABLE if there is no estimate available yet.

reset

public void reset()

Resets the statistic. The statistic should drop all samples and reset to its initial state, similar to right after construction.