From aa094def926fcf8ad5b70d8cb174f8f09617c6b0 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 13 Sep 2024 17:28:24 +0800 Subject: [PATCH] opt parameter --- source/libs/transport/src/transCli.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index a7f3f2527c..0f06b8c0c2 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -3120,6 +3120,15 @@ static int32_t getOrCreateHeap(SHashObj* pConnHeapCache, char* key, SHeap** pHea return code; } +static FORCE_INLINE int8_t shouldSWitchToOtherConn(int32_t reqNum, int32_t sentNum, int32_t stateNum) { + int32_t total = reqNum + sentNum + stateNum; + if (total >= 16) { + return 1; + } + + return 0; +} + static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { int code = 0; SHeap* pHeap = NULL; @@ -3130,13 +3139,22 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { return NULL; } code = transHeapGet(pHeap, &pConn); + if (code != 0) { tDebug("failed to get conn from heap cache for key:%s", key); return NULL; } else { tDebug("get conn %p from heap cache for key:%s, status:%d, refCnt:%d", pConn, key, pConn->inHeap, pConn->reqRefCnt); - } + int32_t reqsNum = transQueueSize(&pConn->reqsToSend); + int32_t reqsSentOut = transQueueSize(&pConn->reqsSentOut); + int32_t stateNum = taosHashGetSize(pConn->pQTable); + if (shouldSWitchToOtherConn(reqsNum, reqsSentOut, stateNum)) { + tDebug("conn %p has %d reqs, %d sentout and %s status in process, switch to other conn", pConn, reqsNum, + reqsSentOut, stateNum); + return NULL; + } + } return pConn; } static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn) {