lock optimization

This commit is contained in:
facetosea 2023-11-08 14:11:55 +08:00
parent ee00607209
commit c3d60989ef
1 changed files with 5 additions and 7 deletions

View File

@ -10,8 +10,7 @@ tmr_h tmrStartHandle;
SHashObj* clusterMonitorInfoTable; SHashObj* clusterMonitorInfoTable;
static const int interval = 1000; // ms static const int interval = 1000; // ms
static const int sendSize = 10; static const int sendBathchSize = 10;
static const int sleepTimeMS = 100;
int32_t sendReport(ClientMonitor* pMonitor, char* pCont); int32_t sendReport(ClientMonitor* pMonitor, char* pCont);
void generateClusterReport(ClientMonitor* pMonitor, bool send) { void generateClusterReport(ClientMonitor* pMonitor, bool send) {
@ -26,19 +25,19 @@ void generateClusterReport(ClientMonitor* pMonitor, bool send) {
} }
void reportSendProcess(void* param, void* tmrId) { void reportSendProcess(void* param, void* tmrId) {
taosRLockLatch(&monitorLock);
taosTmrReset(reportSendProcess, interval, NULL, tmrClientMonitor, &tmrStartHandle); taosTmrReset(reportSendProcess, interval, NULL, tmrClientMonitor, &tmrStartHandle);
taosRLockLatch(&monitorLock);
static int index = 0; static int index = 0;
index++; index++;
ClientMonitor** ppMonitor = (ClientMonitor**)taosHashIterate(clusterMonitorInfoTable, NULL); ClientMonitor** ppMonitor = (ClientMonitor**)taosHashIterate(clusterMonitorInfoTable, NULL);
while (ppMonitor != NULL && *ppMonitor != NULL) { while (ppMonitor != NULL && *ppMonitor != NULL) {
ClientMonitor* pMonitor = *ppMonitor; ClientMonitor* pMonitor = *ppMonitor;
generateClusterReport(*ppMonitor, index == sendSize); generateClusterReport(*ppMonitor, index == sendBathchSize);
ppMonitor = taosHashIterate(clusterMonitorInfoTable, ppMonitor); ppMonitor = taosHashIterate(clusterMonitorInfoTable, ppMonitor);
} }
if (index == sendSize) index = 0; if (index == sendBathchSize) index = 0;
taosRUnLockLatch(&monitorLock); taosRUnLockLatch(&monitorLock);
} }
@ -56,12 +55,11 @@ void monitorClientInitOnce() {
} }
void createMonitorClient(const char* clusterKey, SEpSet epSet, void* pTransporter) { void createMonitorClient(const char* clusterKey, SEpSet epSet, void* pTransporter) {
taosWLockLatch(&monitorLock);
if (clusterKey == NULL || strlen(clusterKey) == 0) { if (clusterKey == NULL || strlen(clusterKey) == 0) {
uError("createMonitorClient failed, clusterKey is NULL"); uError("createMonitorClient failed, clusterKey is NULL");
return; return;
} }
taosWLockLatch(&monitorLock);
if (taosHashGet(clusterMonitorInfoTable, clusterKey, strlen(clusterKey)) == NULL) { if (taosHashGet(clusterMonitorInfoTable, clusterKey, strlen(clusterKey)) == NULL) {
uInfo("createMonitorClient for %s.", clusterKey); uInfo("createMonitorClient for %s.", clusterKey);
ClientMonitor* pMonitor = taosMemoryCalloc(1, sizeof(ClientMonitor)); ClientMonitor* pMonitor = taosMemoryCalloc(1, sizeof(ClientMonitor));