> For the complete documentation index, see [llms.txt](https://maxwell.gitbook.io/way-to-architect/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://maxwell.gitbook.io/way-to-architect/xi-tong-she-ji/xian-liu/xian-liu-shi-shen-me.md).

# 限流是什么

## 概念

限流是指通过对并发请求进行限速或者是对一个时间窗口内的请求进行限速。

一旦达到限制速率，则可以根据实际场景采取如下几种策略：

* 拒绝服务：定向到特定页面或告知资源不存在
* 排队等待：比如秒杀、评论、下单等
* 降级：返回兜底数据或默认数据

## 分类

常见的限流类型主要有以下几种：

* 限制总并发数：如数据库连接池、线程池
* 限制瞬时并发数：如Nginx的limit\_conn模块，用来限制瞬时并发数
* 限制时间窗口内的平均速率：如Guava的RateLimiter，Nginx的limit\_req模块，用来限制每秒的平均速率
* 限制远程端口调用速率
* 限制MQ的消费速率
* 根据网络连接数、网络流程、CPU或内存负载来限流

## 内容来源

《亿级流量网站架构核心技术》：限流详解
