Home > Database > Mysql Tutorial > body text

使用 redis 做限流

WBOY
Release: 2016-06-07 16:39:26
Original
2303 people have browsed it

背景 事情是这样来的,最近2天 tool.lu 的 uv 并没有大幅的增长,但是 pv 的涨幅却很大,造成服务器的 load 一度超过了 20,想必是被攻击,做过php-fpm的优化,收效甚微。故想到了限流 限流的使用场景 API的调用次数限制 防止频繁刷新 etc... 想法和实现 其

背景

事情是这样来的,最近2天 tool.lu 的 uv 并没有大幅的增长,但是 pv 的涨幅却很大,造成服务器的 load 一度超过了 20,想必是被攻击,做过php-fpm的优化,收效甚微。故想到了限流

限流的使用场景

  1. API的调用次数限制
  2. 防止频繁刷新
  3. etc...

想法和实现

其实我是参考了下面这篇文章的实现,至于为什么要这么做,我的考虑跟他文章中提到的是一致的,可以查看原文

Rate limiting with Redis

原文中提供了大段的文字说明,于是我根据他的说明,做了一幅图,仅供参考:

design.jpg

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!