#14287·Redis

[BUG] 连接过多跟踪广播客户端的服务器性能严重下降

作者: warrick1016创建于 2025年8月19日更新于 2026年9月27日

3273:S 21 Jul 2025 10:51:32.507 * handleClientsWithPendingWrites cost: 7780us, processed_num_clis: 1183, buflen: 140137 3273:S 21 Jul 2025 10:51:32.516 * handleClientsWithPendingWrites cost: 7879us, processed_num_clis: 1150, buflen: 209930 3273:S 21 Jul 2025 10:51:32.525 * handleClientsWithPendingWrites cost: 7828us, processed_num_clis: 1166, buflen: 290028 3273:S 21 Jul 2025 10:51:32.534 * handleClientsWithPendingWrites cost: 7834us, processed_num_clis: 1178, buflen: 215100 3273:S 21 Jul 2025 10:51:32.542 * handleClientsWithPendingWrites cost: 7587us, processed_num_clis: 1155, buflen: 288464 `

出于某种原因,回复跟踪客户端 必须由主线程处理。并且处理的客户端数量是 无限的。

`int handleClientsWithPendingWrites(void) { listIter li; listNode *ln; int processed = listLength(server.clients_pending_write);

listRewind(server.clients_pending_write, &li);
while ((ln = listNext(&li))) {
    client *c = listNodeValue(ln);

     ... ...
    /* 如果可能,则将客户端分配给 IO 线程。 */
    if (server.io_threads_num > 1 &&
        !(c->flags & CLIENT_CLOSE_AFTER_REPLY) &&
        !isClientMustHandledByMainThread(c))
    {
        assignClientToIOThread(c);
        continue;
    }
    /* 尝试将缓冲区写入客户端套接字。 */
    if (writeToClient(c, 0) == C_ERR) continue;

    ... ...
}
return processed;

}`

` …