1

版本:rocketmq-all-4.1.0-incubating

我们发送 msg 1000 QPS,同步发送,但抛出异常:-

[TIMEOUT_CLEAN_QUEUE] broker 忙,开始流控一段时间

有相关代码:

while (true) {
        try {
            if (!this.brokerController.getSendThreadPoolQueue().isEmpty()) {
                final Runnable runnable = this.brokerController.getSendThreadPoolQueue().peek();
                if (null == runnable) {
                    break;
                }
                final RequestTask rt = castRunnable(runnable);
                if (rt == null || rt.isStopRun()) {
                    break;
                }

                final long behind = System.currentTimeMillis() - rt.getCreateTimestamp();
                if (behind >= this.brokerController.getBrokerConfig().getWaitTimeMillsInSendQueue()) {
                    if (this.brokerController.getSendThreadPoolQueue().remove(runnable)) {
                        rt.setStopRun(true);
                        rt.returnResponse(RemotingSysResponseCode.SYSTEM_BUSY, String.format("[TIMEOUT_CLEAN_QUEUE]broker busy, start flow control for a while, period in queue: %sms, size of queue: %d", behind, this.brokerController.getSendThreadPoolQueue().size()));
                    }
                } else {
                    break;
                }
            } else {
                break;
            }
        } catch (Throwable ignored) {
        }
    }
}

我发现broker默认sendMessageThreadPoolNums的值为1,</p>

/**
 * thread numbers for send message thread pool, since spin lock will be used by default since 4.0.x, the default value is 1.
 */
private int sendMessageThreadPoolNums = 1; //16 + Runtime.getRuntime().availableProcessors() * 4;
private int pullMessageThreadPoolNums = 16 + Runtime.getRuntime().availableProcessors() * 2;

但是以前的版本不是1,如果我配置sendMessageThreadPoolNums = 100,可以解决这个问题吗?这将导致与默认值不同。谢谢

4

1 回答 1

1

简短的回答:

你有两个选择:

将 sendMessageThreadPoolNums 设置为一个小数字,比如 1,这是 4.1.x 版本之后的默认值。并且,保持默认值useReentrantLockWhenPutMessage=false,4.1.x之后引入

 sendMessageThreadPoolNums=1 
 useReentrantLockWhenPutMessage=false

如果需要使用大量线程处理发送消息,最好使用 useReentrantLockWhenPutMessage=true

 sendMessageThreadPoolNums=128//large thread numbers
 useReentrantLockWhenPutMessage=true  // indicating that do NOT use spin lock but use ReentrantLock when putting message
于 2018-03-28T09:04:28.867 回答