MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / chooseBestThreadForAccept

Function chooseBestThreadForAccept

src/networking.cpp:1154–1174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1152
1153static std::atomic<int> rgacceptsInFlight[MAX_EVENT_LOOPS];
1154int 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
1176void clientAcceptHandler(connection *conn) {
1177 client *c = (client*)connGetPrivateData(conn);

Callers 1

acceptOnThreadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected