PercentileTimeToFirstByteEstimator


@UnstableApi
public final class PercentileTimeToFirstByteEstimator implements TimeToFirstByteEstimator


Implementation of TimeToFirstByteEstimator that returns a configured percentile of a sliding window of collected response times.

Summary

Constants

static final int

The default maximum number of samples.

static final float

The default percentile to return.

Public constructors

Creates an instance that keeps up to DEFAULT_MAX_SAMPLES_COUNT samples and returns the DEFAULT_PERCENTILE percentile.

PercentileTimeToFirstByteEstimator(
    int numberOfSamples,
    float percentile
)

Creates an instance.

Public methods

long

Returns the estimated time to first byte of the response body, in microseconds, or TIME_UNSET if no estimate is available.

void

Called when a transfer is being initialized.

void

Called when a transfer starts.

void

Resets the estimator.

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 float DEFAULT_PERCENTILE = 0.5f

The default percentile to return.

Public constructors

PercentileTimeToFirstByteEstimator

public PercentileTimeToFirstByteEstimator()

Creates an instance that keeps up to DEFAULT_MAX_SAMPLES_COUNT samples and returns the DEFAULT_PERCENTILE percentile.

PercentileTimeToFirstByteEstimator

public PercentileTimeToFirstByteEstimator(
    int numberOfSamples,
    float percentile
)

Creates an instance.

Parameters
int numberOfSamples

The maximum number of samples to be kept in the sliding window.

float percentile

The percentile for estimating the time to the first byte.

Public methods

getTimeToFirstByteEstimateUs

public long getTimeToFirstByteEstimateUs()

Returns the estimated time to first byte of the response body, in microseconds, or TIME_UNSET if no estimate is available.

onTransferInitializing

public void onTransferInitializing(DataSpec dataSpec)

Called when a transfer is being initialized.

Parameters
DataSpec dataSpec

Describes the data for which the transfer is initialized.

onTransferStart

public void onTransferStart(DataSpec dataSpec)

Called when a transfer starts.

Parameters
DataSpec dataSpec

Describes the data being transferred.

reset

public void reset()

Resets the estimator.