新增:添加域名级 QPS(每秒请求数)请求限制功能 #303
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
功能概述
为 feapder 框架添加域名级 QPS(每秒请求数)限制功能,支持为不同域名设置独立的请求速率限制;
主要用于使用feapder时,针对部分额外的服务的域名(非主要爬取)进行限制,避免QPS超出。
核心特性
技术实现
令牌桶算法
核心组件
LocalTokenBucket: 本地内存令牌桶RedisTokenBucket: Redis 分布式令牌桶DomainRateLimiter: 统一管理器,自动选择令牌桶类型使用示例
修改文件
新增文件
feapder/utils/rate_limiter.py: 令牌桶算法实现(~300行)docs/usage/域名级QPS限制.md: 完整使用文档test_qps_limit.py: 功能测试脚本修改文件
feapder/setting.py: 新增 QPS 相关配置项feapder/network/request.py: 在 get_response() 中添加 QPS 检查逻辑feapder/core/scheduler.py: 传递 redis_key 给 Request 类feapder/core/parser_control.py: 注入 request_buffer 到请求对象feapder/templates/*.tmpl: 在 4 个模板中添加 QPS 配置示例docs/_sidebar.md: 添加文档导航