iterate clients fairly in clientsCron() (#12025)
Every time when accept a connection, we add the client to `server.clients` list's tail, but in `clientsCron` we rotate the tail to head at first, and then process the head. It means that the "new" client would be processed before "old" client, moreover if connections established and then freed frequently, the "old" client may have no chance to be processed. To fix it, we need take a fair way to iterate the list, that is take the current head and process, and then rotate the head to tail, thus we can make sure all clients could be processed step by step. p.s. client has `client_list_node` pointer, we don't need put the current client to head to avoid O(N) when remove it.
This commit is contained in:
parent
78202f843f
commit
bedecec786
@ -1015,12 +1015,11 @@ void clientsCron(void) {
|
||||
client *c;
|
||||
listNode *head;
|
||||
|
||||
/* Rotate the list, take the current head, process.
|
||||
* This way if the client must be removed from the list it's the
|
||||
* first element and we don't incur into O(N) computation. */
|
||||
listRotateTailToHead(server.clients);
|
||||
/* Take the current head, process, and then rotate the head to tail.
|
||||
* This way we can fairly iterate all clients step by step. */
|
||||
head = listFirst(server.clients);
|
||||
c = listNodeValue(head);
|
||||
listRotateHeadToTail(server.clients);
|
||||
/* The following functions do different service checks on the client.
|
||||
* The protocol is that they return non-zero if the client was
|
||||
* terminated. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user