pping: Truncate aggregation histograms

In many scenarios, the upper range of an aggregation histogram may be
empty (ex. max histogram bins is for 1000ms but highest observed RTT
was 100 ms, leaving 900 trailing empty bins). As trailing empty bins
contain no useful information, simply truncate the histograms to the
highest non-empty bin.

The truncation of histograms has two benefits.

1. It avoids unnecessary processing of empty bins when internally
calculating statics from the histograms. This should not have any
impact on the output.

2. It reduces the size of the histogram in the JSON output
format. This can potentially save a lot of space in instances where
most maximum observed RTT for a prefix during an aggregation interval
is significantly lower than the highest histogram bin. Removing
trailing empty bins (unlike non-trailing ones) does not require
encoding any additional information (like the number of removed bins
or the index of the remaining ones). It can also never make the
histogram take up more space. Thus there are no obvious drawbacks with
"compressing" the histograms in this manner.

In the future it may be relevant to implement other ways to compress
the histograms, which may be more efficient for certain
distributions (ex. very sparse histograms). However as this method of
removing trailing empty bins is both simple and without drawbacks, so
it makes sense to make the default behavior for now.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
This commit is contained in:
Simon Sundberg
2023-06-01 18:48:47 +02:00
parent e9db312ad5
commit 46f5913e6f

View File

@ -1095,6 +1095,13 @@ static bool aggregated_rtt_stats_nortts(struct aggregated_rtt_stats *stats)
return stats->max == 0;
}
static __u64 aggregated_rtt_stats_maxbins(struct aggregated_rtt_stats *stats,
__u64 bin_width, __u64 n_bins)
{
return stats->max / bin_width < n_bins ? stats->max / bin_width + 1 :
n_bins;
}
static void
merge_percpu_aggreated_rtts(struct aggregated_rtt_stats *percpu_stats,
struct aggregated_rtt_stats *merged_stats,
@ -1141,7 +1148,8 @@ static void print_aggrtts_standard(FILE *stream, __u64 t, const char *prefixstr,
struct aggregated_rtt_stats *rtt_stats,
struct aggregation_config *agg_conf)
{
__u64 nb = agg_conf->n_bins, bw = agg_conf->bin_width;
__u64 bw = agg_conf->bin_width;
__u64 nb = aggregated_rtt_stats_maxbins(rtt_stats, bw, agg_conf->n_bins);
print_ns_datetime(stream, t);
fprintf(stream,
@ -1170,7 +1178,8 @@ static void print_aggrtts_json(json_writer_t *ctx, __u64 t,
struct aggregated_rtt_stats *rtt_stats,
struct aggregation_config *agg_conf)
{
__u64 nb = agg_conf->n_bins, bw = agg_conf->bin_width;
__u64 bw = agg_conf->bin_width;
__u64 nb = aggregated_rtt_stats_maxbins(rtt_stats, bw, agg_conf->n_bins);
int i;
jsonw_start_object(ctx);