| 1152 | |
| 1153 | static std::atomic<int> rgacceptsInFlight[MAX_EVENT_LOOPS]; |
| 1154 | int chooseBestThreadForAccept() |
| 1155 | { |
| 1156 | int ielMinLoad = 0; |
| 1157 | int cclientsMin = INT_MAX; |
| 1158 | for (int iel = 0; iel < cserver.cthreads; ++iel) |
| 1159 | { |
| 1160 | int cclientsThread; |
| 1161 | atomicGet(g_pserver->rgthreadvar[iel].cclients, cclientsThread); |
| 1162 | cclientsThread += rgacceptsInFlight[iel].load(std::memory_order_relaxed); |
| 1163 | // Note: Its repl factor less one because cclients also includes replicas, so we don't want to double count |
| 1164 | cclientsThread += (g_pserver->rgthreadvar[iel].cclientsReplica) * (g_pserver->replicaIsolationFactor-1); |
| 1165 | if (cclientsThread < cserver.thread_min_client_threshold) |
| 1166 | return iel; |
| 1167 | if (cclientsThread < cclientsMin) |
| 1168 | { |
| 1169 | cclientsMin = cclientsThread; |
| 1170 | ielMinLoad = iel; |
| 1171 | } |
| 1172 | } |
| 1173 | return ielMinLoad; |
| 1174 | } |
| 1175 | |
| 1176 | void clientAcceptHandler(connection *conn) { |
| 1177 | client *c = (client*)connGetPrivateData(conn); |