有效的方式来计算命中件数到最后一分钟内的服务器,在实时 [英] Efficient way to compute number of hits to a server within the last minute, in real time

查看:104
本文介绍了有效的方式来计算命中件数到最后一分钟内的服务器,在实时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设你有一个不断得到HTTP请求的服务器。你的老板需要的一些统计数据,并要求您计算在最后一分钟内的点击次数在任何给定的时间。

Say you have a server that constantly gets HTTP requests. Your boss needs some stats, and asks you to compute the number of hits within the last minute at any given time.

什么算法和数据结构,你会用它来实现这一目标?

What algorithm and data-structure would you use to achieve this?

推荐答案

使用循环缓冲区

只要你必须保持目前的一些统计数据有一个内置的过时,环形缓冲区是一个很好的候选人。你的情况,你可以轻松地在最后一分钟的请求数通过在环形缓冲区的前面插入新的数据包,并保持一分钟,前-现在指针在缓冲区中,或执行上的请求时间二进制搜索

Whenever you have to keep some current statistics with a built-in obsolescence, a ring buffer is a good candidate. In your case, you can easily keep count of the requests in the last minute by inserting new packets at the front of the circular buffer and keeping a one-minute-before-now pointer in the buffer, or performing a binary search on request time.

这篇关于有效的方式来计算命中件数到最后一分钟内的服务器,在实时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆