gpt4 book ai didi

algorithm - 如何检测请求/秒速率的增加?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:25:39 26 4
gpt4 key购买 nike

我正在尝试实时处理不同链接的点击流。每次点击都会记录到数据库中。对于大多数链接,每分钟的点击次数或多或少是恒定的(例如 < 50)。然而,他们中的少数人可以达到 1000-2000/分钟,但时间很短。

我想检测何时开始看到如此高流量的点击流,因为我想为这些流延迟和批处理数据库更新,而不是实时执行它们。

我一直在尝试多种方法,但都没有很好的结果。对我来说,这看起来像是一个标准的数学问题或队列管理问题。

有什么建议吗?

最佳答案

在插入每次点击时,还要计算过去一分钟内的点击次数并将其插入。然后您可以只查询速率足够高的事件。

例如(伪代码):

proc record_click
insert into click_log (current_time, event_info)
insert into click_rates (current_time,
(select count(*) from click_log where time > current_time - 1 minute))

如果您不想在插入点击时执行此操作,您可以稍后计算该值,但这将是一个潜在的巨大数据集,而不是每次点击时的大约 50 条记录时间。

create view click_rates as
select event_time, count(*) as rate
from click_events e1, click_events e2
where e2.event_time between e1.event_time - interval '1 minute' and e1.event_time
group by e1.event_time

关于algorithm - 如何检测请求/秒速率的增加?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15304117/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com