fix:TD-31587:Repeated insert performance degradation
This commit is contained in:
parent
4b054e4ebd
commit
d3518fbc89
|
@ -99,4 +99,7 @@ int taos_counter_inc(taos_counter_t *self, const char **label_values);
|
|||
*/
|
||||
int taos_counter_add(taos_counter_t *self, double r_value, const char **label_values);
|
||||
|
||||
int taos_counter_get_vgroup_ids(taos_counter_t *self, char ***keys,int32_t **vgroup_ids);
|
||||
int taos_counter_get_keys_size(taos_counter_t *self);
|
||||
int taos_counter_delete(taos_counter_t *self, char *key);
|
||||
#endif // TAOS_COUNTER_H
|
||||
|
|
|
@ -37,6 +37,7 @@ typedef struct SDnodeMgmt {
|
|||
ProcessAlterNodeTypeFp processAlterNodeTypeFp;
|
||||
ProcessDropNodeFp processDropNodeFp;
|
||||
SendMonitorReportFp sendMonitorReportFp;
|
||||
MonitorCleanExpiredSamplesFp monitorCleanExpiredSamplesFp;
|
||||
SendAuditRecordsFp sendAuditRecordsFp;
|
||||
GetVnodeLoadsFp getVnodeLoadsFp;
|
||||
GetVnodeLoadsFp getVnodeLoadsLiteFp;
|
||||
|
|
|
@ -65,6 +65,7 @@ static int32_t dmOpenMgmt(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
|||
pMgmt->processAlterNodeTypeFp = pInput->processAlterNodeTypeFp;
|
||||
pMgmt->processDropNodeFp = pInput->processDropNodeFp;
|
||||
pMgmt->sendMonitorReportFp = pInput->sendMonitorReportFp;
|
||||
pMgmt->monitorCleanExpiredSamplesFp = pInput->monitorCleanExpiredSamplesFp;
|
||||
pMgmt->sendAuditRecordsFp = pInput->sendAuditRecordFp;
|
||||
pMgmt->getVnodeLoadsFp = pInput->getVnodeLoadsFp;
|
||||
pMgmt->getVnodeLoadsLiteFp = pInput->getVnodeLoadsLiteFp;
|
||||
|
|
|
@ -168,6 +168,7 @@ static void *dmMonitorThreadFp(void *param) {
|
|||
float interval = (curTime - lastTime) / 1000.0f;
|
||||
if (interval >= tsMonitorInterval) {
|
||||
(*pMgmt->sendMonitorReportFp)();
|
||||
(*pMgmt->monitorCleanExpiredSamplesFp)();
|
||||
lastTime = curTime;
|
||||
|
||||
trimCount = (trimCount + 1) % TRIM_FREQ;
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "vmInt.h"
|
||||
#include "taos_monitor.h"
|
||||
|
||||
extern taos_counter_t *tsInsertCounter;
|
||||
|
||||
void vmGetVnodeLoads(SVnodeMgmt *pMgmt, SMonVloadInfo *pInfo, bool isReset) {
|
||||
pInfo->pVloads = taosArrayInit(pMgmt->state.totalVnodes, sizeof(SVnodeLoad));
|
||||
|
@ -117,6 +120,27 @@ void vmGetMonitorInfo(SVnodeMgmt *pMgmt, SMonVmInfo *pInfo) {
|
|||
taosArrayDestroy(pVloads);
|
||||
}
|
||||
|
||||
int vmCleanExpriedSamples(SVnodeMgmt *pMgmt) {
|
||||
int list_size = taos_counter_get_keys_size(tsInsertCounter);
|
||||
if (list_size == 0) return 0;
|
||||
int32_t *vgroup_ids;
|
||||
char **keys;
|
||||
taos_counter_get_vgroup_ids(tsInsertCounter,&keys,&vgroup_ids);
|
||||
int r = 0;
|
||||
(void)taosThreadRwlockWrlock(&pMgmt->lock);
|
||||
for (int i = 0; i<list_size; i++) {
|
||||
int32_t vgroup_id = vgroup_ids[i];
|
||||
void *vnode = taosHashGet(pMgmt->hash, &vgroup_id, sizeof(int32_t));
|
||||
if (vnode == NULL) {
|
||||
r = taos_counter_delete(tsInsertCounter, keys[i]);
|
||||
}
|
||||
}
|
||||
(void)taosThreadRwlockUnlock(&pMgmt->lock);
|
||||
taosMemoryFree(vgroup_ids);
|
||||
taosMemoryFree(keys);
|
||||
return r;
|
||||
}
|
||||
|
||||
static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) {
|
||||
memcpy(pCfg, &vnodeCfgDefault, sizeof(SVnodeCfg));
|
||||
|
||||
|
|
|
@ -128,6 +128,7 @@ int32_t dmProcessNodeMsg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg);
|
|||
|
||||
// dmMonitor.c
|
||||
void dmSendMonitorReport();
|
||||
void dmMonitorCleanExpiredSamples();
|
||||
void dmSendAuditRecords();
|
||||
void dmGetVnodeLoads(SMonVloadInfo *pInfo);
|
||||
void dmGetVnodeLoadsLite(SMonVloadInfo *pInfo);
|
||||
|
|
|
@ -39,6 +39,8 @@ void vmGetVnodeLoadsLite(void *pMgmt, SMonVloadInfo *pInfo);
|
|||
void mmGetMnodeLoads(void *pMgmt, SMonMloadInfo *pInfo);
|
||||
void qmGetQnodeLoads(void *pMgmt, SQnodeLoad *pInfo);
|
||||
|
||||
int vmCleanExpriedSamples(void *pMgmt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -409,6 +409,7 @@ SMgmtInputOpt dmBuildMgmtInputOpt(SMgmtWrapper *pWrapper) {
|
|||
.processAlterNodeTypeFp = dmProcessAlterNodeTypeReq,
|
||||
.processDropNodeFp = dmProcessDropNodeReq,
|
||||
.sendMonitorReportFp = dmSendMonitorReport,
|
||||
.monitorCleanExpiredSamplesFp = dmMonitorCleanExpiredSamples,
|
||||
.sendAuditRecordFp = auditSendRecordsInBatch,
|
||||
.getVnodeLoadsFp = dmGetVnodeLoads,
|
||||
.getVnodeLoadsLiteFp = dmGetVnodeLoadsLite,
|
||||
|
|
|
@ -52,6 +52,16 @@ static void dmGetDmMonitorInfo(SDnode *pDnode) {
|
|||
monSetDmInfo(&dmInfo);
|
||||
}
|
||||
|
||||
int dmCleanExpriedSamples(SDnode *pDnode) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[VNODE];
|
||||
if (dmMarkWrapper(pWrapper) == 0) {
|
||||
if (pWrapper->pMgmt != NULL) {
|
||||
return vmCleanExpriedSamples(pWrapper->pMgmt);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dmGetDmMonitorInfoBasic(SDnode *pDnode) {
|
||||
SMonDmInfo dmInfo = {0};
|
||||
dmGetMonitorBasicInfoBasic(pDnode, &dmInfo.basic);
|
||||
|
@ -123,6 +133,14 @@ void dmSendMonitorReport() {
|
|||
monGenAndSendReport();
|
||||
}
|
||||
|
||||
void dmMonitorCleanExpiredSamples() {
|
||||
if (!tsEnableMonitor || tsMonitorFqdn[0] == 0 || tsMonitorPort == 0) return;
|
||||
dTrace("send monitor report to %s:%u", tsMonitorFqdn, tsMonitorPort);
|
||||
|
||||
SDnode *pDnode = dmInstance();
|
||||
(void)dmCleanExpriedSamples(pDnode);
|
||||
}
|
||||
|
||||
//Todo: put this in seperate file in the future
|
||||
void dmSendAuditRecords() {
|
||||
auditSendRecordsInBatch();
|
||||
|
|
|
@ -116,6 +116,7 @@ typedef enum {
|
|||
typedef int32_t (*ProcessCreateNodeFp)(EDndNodeType ntype, SRpcMsg *pMsg);
|
||||
typedef int32_t (*ProcessDropNodeFp)(EDndNodeType ntype, SRpcMsg *pMsg);
|
||||
typedef void (*SendMonitorReportFp)();
|
||||
typedef void (*MonitorCleanExpiredSamplesFp)();
|
||||
typedef void (*SendAuditRecordsFp)();
|
||||
typedef void (*GetVnodeLoadsFp)(SMonVloadInfo *pInfo);
|
||||
typedef void (*GetMnodeLoadsFp)(SMonMloadInfo *pInfo);
|
||||
|
@ -155,6 +156,7 @@ typedef struct {
|
|||
ProcessAlterNodeTypeFp processAlterNodeTypeFp;
|
||||
ProcessDropNodeFp processDropNodeFp;
|
||||
SendMonitorReportFp sendMonitorReportFp;
|
||||
MonitorCleanExpiredSamplesFp monitorCleanExpiredSamplesFp;
|
||||
SendAuditRecordsFp sendAuditRecordFp;
|
||||
GetVnodeLoadsFp getVnodeLoadsFp;
|
||||
GetVnodeLoadsFp getVnodeLoadsLiteFp;
|
||||
|
|
|
@ -80,4 +80,5 @@ int taos_metric_formatter_clear(taos_metric_formatter_t *self);
|
|||
*/
|
||||
char *taos_metric_formatter_dump(taos_metric_formatter_t *metric_formatter);
|
||||
|
||||
int32_t taos_metric_formatter_get_vgroup_id(char *key);
|
||||
#endif // TAOS_METRIC_FORMATTER_I_H
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "taos_metric_sample_i.h"
|
||||
#include "taos_metric_sample_t.h"
|
||||
#include "taos_metric_t.h"
|
||||
#include "taos_metric_formatter_i.h"
|
||||
|
||||
taos_counter_t *taos_counter_new(const char *name, const char *help, size_t label_key_count, const char **label_keys) {
|
||||
return (taos_counter_t *)taos_metric_new(TAOS_COUNTER, name, help, label_key_count, label_keys);
|
||||
|
@ -64,3 +65,40 @@ int taos_counter_add(taos_counter_t *self, double r_value, const char **label_va
|
|||
if (sample == NULL) return 1;
|
||||
return taos_metric_sample_add(sample, r_value);
|
||||
}
|
||||
|
||||
int taos_counter_get_keys_size(taos_counter_t *self) {
|
||||
return self->samples->keys->size;
|
||||
}
|
||||
|
||||
int taos_counter_get_vgroup_ids(taos_counter_t *self, char ***keys,int32_t **vgroup_ids) {
|
||||
TAOS_TEST_PARA(self != NULL);
|
||||
if (self == NULL) return 1;
|
||||
if (self->type != TAOS_COUNTER) {
|
||||
TAOS_LOG(TAOS_METRIC_INCORRECT_TYPE);
|
||||
return 1;
|
||||
}
|
||||
if (self->samples == NULL) return 1;
|
||||
taos_linked_list_t *key_list = self->samples->keys;
|
||||
int r = 0;
|
||||
*vgroup_ids = (int32_t *)taos_malloc(key_list->size*sizeof(int32_t));
|
||||
*keys = (char **)taos_malloc(key_list->size*sizeof(char *));
|
||||
int index = 0;
|
||||
for (taos_linked_list_node_t *current_key = key_list->head; current_key != NULL;current_key = current_key->next) {
|
||||
char *key = (char *)current_key->item;
|
||||
int32_t vgroup_id = taos_metric_formatter_get_vgroup_id(key);
|
||||
(*vgroup_ids)[index] = vgroup_id;
|
||||
(*keys)[index] = key;
|
||||
index++;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
int taos_counter_delete(taos_counter_t *self, char *key) {
|
||||
TAOS_TEST_PARA(self != NULL);
|
||||
if (self == NULL) return 1;
|
||||
if (self->type != TAOS_COUNTER) {
|
||||
TAOS_LOG(TAOS_METRIC_INCORRECT_TYPE);
|
||||
return 1;
|
||||
}
|
||||
return taos_map_delete(self->samples, key);
|
||||
}
|
|
@ -156,6 +156,21 @@ int taos_metric_formatter_load_l_value(taos_metric_formatter_t *self, const char
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
int32_t taos_metric_formatter_get_vgroup_id(char *key) {
|
||||
char *start,*end;
|
||||
char vgroupid[10];
|
||||
start = strstr(key, "vgroup_id=\"");
|
||||
if (start) {
|
||||
start += strlen("vgroup_id=\"");
|
||||
end = strchr(start, '\"');
|
||||
if (end) {
|
||||
strncpy(vgroupid, start, end - start);
|
||||
vgroupid[end - start] = '\0';
|
||||
}
|
||||
return strtol(vgroupid, NULL, 10);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
int taos_metric_formatter_load_sample(taos_metric_formatter_t *self, taos_metric_sample_t *sample,
|
||||
char *ts, char *format) {
|
||||
|
|
Loading…
Reference in New Issue