> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 限流最佳实践

> 使用 Retry-After 标头、请求批处理和速率缓解策略来处理 PlayFab HTTP 429 限流响应,使 API 流量保持在限制之内。

在 PlayFab 中遇到限流时,会返回 HTTP 429 错误,表示 API 调用正在被限流。响应标头和正文包含用于理解错误的关键信息。

示例标头:

```http theme={null}
HTTP/1.1 429 Too Many Requests
Retry-After: 8
```

示例响应正文:

```json theme={null}
{ 
  "code": 429, 
  "status": "TooManyRequests", 
  "retryAfterSeconds": 8, 
  "error": "APIClientRequestRateLimitExceeded", 
  "errorCode": 1199, 
  "errorMessage": "The client has exceeded the maximum API request rate and is being throttled" 
} 
```

**`Retry-After`** 和 **`retryAfterSeconds`** 属性指示在尝试再次发送请求以避免限流之前,应等待的时间(以秒为单位)。如果使用最新的[跨平台 C/C++ SDK](/services/playfab/sdks/c),SDK 会尝试代表调用方处理重试。否则,请使用以下策略结合重试值来开发自定义处理逻辑。

## 缓解限流问题

如果限流错误持续存在,请考虑采用以下策略:

1. 审视请求速率
   * 分析你为何发送大量请求。
   * 评估降低针对 API 目标玩家或游戏实体的请求速率的方法。

2. 批处理 API 调用
   * 通过批处理 API 调用来降低频率。
   * 示例:每 10 秒批量更新一次个人资料,而不是每秒都更新。

## 关键要点

* 限流错误会触发 HTTP 429 响应,并附带描述错误性质的详细信息。
* 使用 **`Retry-After`** 和 **`retryAfterSeconds`** 属性来确定发起下一次请求之前的等待时间。
* 评估高频请求的必要性,并相应地进行优化。
* 实施批处理策略以缓解限流问题并提升整体系统效率。

## 另请参阅

* [Economy v2 限制](/services/playfab/economy-monetization/economy-v2/limits)


## Related topics

- [PlayFab 中的限流](/zh-CN/services/playfab/live-service-management/service-gateway/throttling/what-is-throttling.md)
- [调用 XBOX 服务的最佳实践](/zh-CN/services/xbox-services/develop/best-practices/live-best-practices-calling-xbl.md)
- [最佳实践](/zh-CN/services/xbox-services/develop/best-practices/index.md)
- [Insights 最佳实践](/zh-CN/services/playfab/data-analytics/legacy/insights/best-practices.md)
- [内容更新最佳实践](/zh-CN/build/core-features/common/packaging/packaging-updates.md)
