开发者

Recent average, without full logging of all data

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开发者_JAVA百科 problem in the most effective manner.

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜