吞吐量网络估计
throughput networking estimation
如何估计瞬时吞吐量?例如,以类似于浏览器在下载文件时所做的操作。这不仅仅是一个平均吞吐量,而是一个瞬时估计,可能是一个"移动平均值"。我正在寻找算法,但您可以在c++中指定它。理想情况下,它不涉及线程(即,持续刷新,比如每秒刷新一次),而是只在询问值时进行评估。
您可以使用指数移动平均值,如下所述,但我将重复公式:
accumulator = (alpha * new_value) + (1.0 - alpha) * accumulator
为了实现估计,假设您打算每秒查询一次计算,但需要最后一分钟的平均值。那么,有一种方法可以得到这个估计:
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
。
您可能想要一个boxcar平均值。
只需保留最后n个值,并对其进行平均。对于后续的每个块,减去最旧的块,再加上最新的块。请注意,对于浮点值,您可能会得到一些聚合错误,在这种情况下,您可能希望每隔m个值从头开始重新计算总数。当然,对于整数值,您不需要这样的东西。
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- GetShortPathName在网络驱动器上使用中文文件夹时失败
- 通过网络、跨平台传递std::变体是否安全
- 如何在MNIST上提高网络运行的准确性
- Active Directory:从网络服务帐户下运行的Windows服务调用ADsOpenObject时失败
- OpenCV 4.1.2 - 从网络摄像头获取帧并将其拆分
- 使用OpenCV和覆盆子上的多个网络摄像头拍摄延时摄影,出现多个V4L错误
- 神经网络不学习.卡在50%
- 如何绑定 C++ gRPC 客户端的网络接口
- 在本地网络中通过OpenCV(C++)实时流式传输图像
- 在不知道套接字的情况下关闭网络连接
- 是否有 Windows 用户空间函数来枚举连接的网络共享?
- 在没有管理员权限的情况下连接到同一网络中的命名管道
- 无法为 X.radio 创建中等可视化,因为找不到网络节点可视化 - Omnet++
- 将传入的网络"char*"数据转换为"uint8_t"并返回的安全方法是什么?
- 像 POCO 这样的C++图书馆如何访问网络?
- 使用源读取器从网络摄像头源获取 H264 样本
- 吞吐量网络估计
- 使用 C++ 检测网络的最大吞吐量
- 在Windows上获得cpu使用率和网络吞吐量的最有效和最基本的方法