dongyou6768 2011-08-31 15:26
浏览 69
已采纳

最近的平均值,没有完整记录所有数据

This is mainly a performance issue. It is to help get the current average of the past N (30?) values. The context here would be to monitor the average execution time for the past N data requests in a server. While the obvious solution, is to log the all past N requests, in which all N request is read, and tabulated. Creating a performance hit relative to the data request in question.

As this is mainly use as a means of measure and not a perfect running estimate, the question? To solve this problem in the most effective manner.

While the solution may be language neutral, I would be implementing in php :)

  • 写回答

1条回答 默认 最新

  • doushou8730 2011-08-31 15:32
    关注

    Instead of saving the last N values, organize your values in "buckets" with a predefined bucket-size, and for each bucket, only save the sum of all values in the bucket.

    Whenever a bucket is full, you can delete the oldest bucket. (The best way to do this would be a ring buffer)

    This allows you to cut your memory usage by a factor of BUCKET_SIZE, but obviously your average is not over the last N values anymore, but over the last N to N + BUCKET_SIZE.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊