# 消息积压解决策略

消息积压问题的直接原因一般有两种：生产者发送消息过快，或者消费者消费消息过慢。通常在设计系统的时候，会尽量保证消费者的消费性能高于生产者的发送性能，从而保证系统健康地持续运行。

在解决消息积压问题时候，对于不同原因需要采取不同的解决策略。大部分消息队列都内置监控功能，通过监控可以很容易地确定消息积压的具体原因。

## 生产者发送消息增多

在某段时间内生产者发送的消息突然增多，例如大促或者抢购，此时一般难以在短时间内优化消费者的性能，但是可以通过 **扩容消费者的实例数量** 来提升系统的总体消费能力，或者退而求其次，通过 **降级不重要的业务** 来减少生产者发送的消息总量。

## 消费者消费性能下降

在某段时间内消费者的消费性能突然下降，例如数据库不可用或者调用接口超时，此时需要 **解决消费者的线上故障**，等待消费者的消费性能恢复之后，被积压的消息便可以被逐渐消费掉。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitbook.fantasticmao.cn/tech/zhong-jian-jian/xiao-xi-dui-lie/xiao-xi-ji-ya-jie-jue-ce-le.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
