瞬間的なスループットを見積もるにはどうすればよいですか? たとえば、ブラウザがファイルをダウンロードするときと同様の方法で。これは単なる平均スループットではなく、おそらく「移動平均」を使用した瞬間的な推定です。アルゴリズムを探していますが、c++ で指定できます。理想的には、スレッドを使用せず (つまり、1 秒ごとに継続的に更新される)、値が要求されたときにのみ評価されるようにします。
2331 次
2 に答える
2
hereで説明されているように、指数移動平均を使用できますが、式を繰り返します。
accumulator = (alpha * new_value) + (1.0 - alpha) * accumulator
推定を達成するために、毎秒計算を照会するつもりであるが、最後の 1 分間の平均が必要であるとします。次に、その見積もりを取得する1つの方法を次に示します。
struct AvgBps {
double rate_; // The average rate
double last_; // Accumulates bytes added until average is computed
time_t prev_; // Time of previous update
AvgBps () : rate_(0), last_(0), prev_(time(0)) {}
void add (unsigned bytes) {
time_t now = time(0);
if (now - prev_ < 60) { // The update is within the last minute
last_ += bytes; // Accumulate bytes into last
if (now > prev_) { // More than a second elapsed from previous
// exponential moving average
// the more time that has elapsed between updates, the more
// weight is assigned for the accumulated bytes
double alpha = (now - prev_)/60.0;
rate_ = (1 -alpha) * last_ + alpha * rate_;
last_ = 0; // Reset last_ (it has been averaged in)
prev_ = now; // Update prev_ to current time
}
} else { // The update is longer than a minute ago
rate_ = bytes; // Current update is average rate
last_ = 0; // Reset last_
prev_ = now; // Update prev_
}
}
double rate () {
add(0); // Compute rate by doing an update of 0 bytes
return rate_; // Return computed rate
}
};
実際には、の代わりに単調クロックを使用する必要がありtime
ます。
于 2012-07-31T08:44:31.457 に答える
0
おそらく有蓋車の平均が必要です。
最後のn個の値を保持し、それらを平均してください。後続の各ブロックについて、最も古いものを減算し、最新のものを追加します。浮動小数点値の場合、集計エラーが発生する可能性があることに注意してください。その場合、m 値ごとに最初から合計を再計算する必要がある場合があります。もちろん、整数値の場合、そのようなものは必要ありません。
于 2012-07-31T16:48:23.613 に答える